Write a mal program that prompts the user

Assignment Help C/C++ Programming
Reference no: EM131472638

Programming at the Hardware-Software Interface

You must follow the programming and documentation guidelines available in the Blackboard module Projects.

Important Notes:
(i) This is nota team project.
(ii) This project has two parts and both parts must be done in MAL. You must submit two MAL source files named p5a.mal and p5b.mal.
(iii) There is no two-day grace period for this assignment.

Description of Part (a)

In MAL an integer is represented using 32 bits. Assume that the bits are numbered right to left from 0 to 31. Thus, the rightmost bit is numbered 0 and the leftmost bit is numbered 31. We say that the bits 0 through 15 form the right halfand the bits 16 through 31 form the left halfof the integer.

You are required to write a MAL program that prompts a user for a positive decimal integer, reads the integer typed by the user and outputs the following values:
1. The total number of 1's in the right half of the binary representation of the integer.
2. The total number of 0's in the left half of the binary representation of the integer.
3. The highest power of 2 that evenly divides the integer .
4. The value of the largest digit in the decimal representation of the integer.

Example:Suppose the user types the decimal integer 1536. The 32-bit binary representation of 1536 is as follows:

0000 0000 0000 0000 0000 0110 0000 0000

For this example, the required answers are as follows:
1. The number of 1's in the right half of the binary representation of the given integer = 2.
2. The number of 0's in the left half of the binary representation of the given integer = 16.
3. The largest power of 2 that evenly divides the given integer = 93.
4. The value of the largest digit in the decimal representation of the given integer = 6.

Program outline:
The outline for your program for Part (a) must be the following.
1. Prompt the user for a positive integer.
2. Read the integer.
3. Compute the four quantities mentioned above and print the answers.
4. Stop.

Programming Suggestions:
1) MAL program must be in a file named p5a.mal.
2) Each time your program for Part (a) is executed, it should handle just one integer.
3) You may assume that the value typed by the user is a positive decimal integer. Thus, there is no need to do any error checking in this part.
4) There is no need to convert the integer to binary; when the integer is read in (using syscall), it is already in binary form.
5) Use bitwise operations to count the number of 1's (0's) in the right (left) half.
6) To find the highest power of 2 that divides the integer, count the number of 0's at the end of the binary representation or use successive divisions by 2.
7) To extract the decimal digits and compute the largest digit, use successive divisions by 10.

Description of Part (b)
In this part, you are required to write a MAL program that prompts the user for a line of textand reads the line typed by the user. If the line contains just white space characters your programshould simply output the message "Line contains only white space characters." and stop.Otherwise, your program should compute and output the following:

1. The number of non-whitespace characters in the line.

2. The number of words in the line.

3. The maximum length of a word in the line.

4. The minimum length of a word in the line.

5. The word of maximum length in the line. (If there are two or more words of maximum lengthin the line, then the program should print the word of maximum length that appears first inthe line.)

6. The word of minimum length in the line. (If there are two or more words of minimum lengthin the line, then the program should print the word of minimum length that appears first inthe line.)

Example: Suppose the line typed by the user is the following:
It was the best of times and it was the worst of times.
The answers for the above line are:
No. of non-whitespace characters: 43
No. of words: 13
Maximum length of a word: 6
Minimum length of a word: 2
Word of maximum length: times.
Word of minimum length: It

Note that the word of maximum length (6) is "times." (without the quotes), which includesthe punctuation mark at the end. (Recall that a word is any sequence of characters that does notinclude a whitespace character.) There are several words of minimum length (2) in the above text. The first such word is "It" (again, without the quotes).

Program outline:

The outline for your program for Part (b) must be the following.

1. Prompt the user for a line of text.

2. Read the line of text typed by the user.

1. If the line has only whitespace charactersprint the message "Line contains only white space characters" and stop.

2. Otherwise compute the quantities mentioned above and print the answers.

3. Stop.

Programming Suggestions:

1) MAL program must be in a file named p5b.mal.

2) It must have at least one function in addition to the main program.

3) Study Lecture 15 (arrays of character in MAL) before working on Part (b).

4) You may find it useful to write a function that returns information (e.g. starting and ending indices) about the next word.

5) A word is any sequence of characters that does not contain a whitespace character.

6) A whitespace character refers to a space, a tab or the newline character.

7) Any line of text typed by a user has at most 80 characters including the newline character.

8) End of any line is determined by the null character.

9) It is excepted to check whether the input line consists of just whitespacecharacters, no other error checks are needed.

10) Each time your program is executed, it should handle just oneline of text.
Some sample data to test your program:
Important Note: Some sample inputs that can be used to test your programsare given below. However, you should remember that when we compileand run your source files, we will use other data. Just because your programs work for the sample inputs given below,you shouldn't assume that they will work for all inputs.Therefore, you should test your programs thoroughly with otherinput values.

Example of program execution:
Part (a). Example 1.
unix2> /usr/local/bin/spim
.
. <--- Initial lines printed by spim.
.
(spim) read "p5a.mal"
(spim) run
Positive integer? 1536
No. of 1's in the right half = 2
No. of 0's in the left half = 16
Largest power of 2 = 9
Largest decimal digit = 6
(spim) quit
unix2>

Part (a). Example 2.
unix2> /usr/local/bin/spim
.
. <--- Initial lines printed by spim.
.
(spim) read "p5a.mal"
(spim) run
Positive integer? 123
No. of 1's in the right half = 6
No. of 0's in the left half = 16
Largest power of 2 = 0
Largest decimal digit = 3
(spim) quit
unix2>

Part (b). Example 1.
unix2> /usr/local/bin/spim
.
. <--- Initial lines printed by spim.
.
(spim) read "p5b.mal"
(spim) run
Text? A short line.
No. of non-whitespace characters: 11
No. of words: 3
Maximum length of a word: 5
Minimum length of a word: 1
Word of maximum length: short
Word of minimum length: A
(spim) quit
unix2>

Part (b). Example 2.
unix2> /usr/local/bin/spim
.
. <--- Initial lines printed by spim.
.
(spim) read "p5b.mal"
(spim) run
Text? This example contains five words.
No. of non-whitespace characters: 29
No. of words: 5
Maximum length of a word: 8
Minimum length of a word: 4
Word of maximum length: contains
Word of minimum length: This
(spim) quit
unix2>

Reference no: EM131472638

Questions Cloud

Improvement capability for organizational performance : In at least 200 words, please explain how to develop improvement capability for organizational performance.
Review the case study of the b and l food company : The B&L Food Company prepared, packed, and sold quality food products to wholesalers and retailers. Marvin, while grocery shopping at Gregg's Red & White.
What experiences does turkle claim : What experiences does Turkle claim that people avoid when they say "texting will do"? What do you think about this?
Banquet event ordering : Now that you have your services checklist (from Unit 6), it is time to create the banquet event order (BEO) for all the food functions for your group.
Write a mal program that prompts the user : CSI 333 - Programming at the Hardware-Software Interface - write a MAL program that prompts a user for a positive decimal integer, reads the integer typed by the user and outputs the values.
Hr article analysis-crisis management : Students will demonstrate their knowledge of HRâs role in and influence on legal and environmental risk mitigation, as well as the integration of ethical practi
Could ayrault sue the car manufacturer : Ayrault was driving her car to the family doctor for an appointment. When she stopped for a red light, the car behind her "rear-ended" her car.
Develop an annotated bibliography : Develop an annotated bibliography including 8 to 10 peer-reviewed sources on concepts related to perception of motion, depth, and size.
What could be done to improve the product quality : You will also determine human factors that could be helpful or harmful to company and expand upon what could be done to improve the product or service quality.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Program calculates and displays salesperson''s commission

The sales manager at Tompkins Company wants a program that calculates and displays each salesperson's commission, which is 10% of his or her sales. It also should display the total commission. Use a value-returning function to get the amount sold by ..

  Feature of object-oriented programming

Describe at least one (1) feature of object-oriented programming that Visual Logic lacks and Identify at least one (1) advantage to using event-driven programming, as compared to using purely procedural programming

  Write a program that asks the user to enter the monthly cost

Write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should then display the total monthly cost ..

  You have to develop a basic temperature classnbsp base

you have to develop a basic temperature class.nbsp base skeleton code and a simple driver have been provided for

  Implement a version of the zombiedash

For this assignment you must implement a version of the 'ZombieDash' video game on the Teensy LCD board. The game is to be written in the C programming language. The implementation will make use of the LCD screen, buttons, LEDs, potentiometer, and..

  Display an error message and prompt the user again

Write an application that creates a quiz, which contains at least 5 questions about a hobby, popular music, astronomy, or any other personal interest.

  Find the total number of lines in a collection

Write two functions, so that we can find the total number of lines in a collection of text files.

  Create an output array using input

create an output array using input x values 1 through 10.

  Write a program that stores the number

Write a program that stores the following numbers in the array named miles : 15, 22, 16, 18, 27, 23, 20. Use a pointer to copy the data stored in miles to another array named dist and then display the values in the dist array.

  Build a basic cipher base class

Build a randomly generated simple substitution cipher and use it to encode messages. Again the encoded messages will be in all upper case letters only.

  Write application to calculate price of carpeting for room

The Westfield Carpet Company has asked you to write an application that calculates the price of carpeting for rectangular rooms.

  Details of the stock of a shop

David needs to create a program to maintain the details of the stock of a shop. He needs to ensure that item category is Women, Men, Girls, Boys, and Babies. He needs to accept item category from the user.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd