联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp2

您当前位置:首页 >> CS作业CS作业

日期:2018-05-26 05:23


CSI 333 – Programming at the Hardware-Software Interface

SQUPT, Spring 2018

Project IV


The total grade for the assignment is 100 points.

You must follow the programming and documentation guidelines (see file Programming Assignments Requirements and Recommendations.docx).

Due date: EOD May 25th, Thursday.


Important Notes:

(i)This is not a team project.

(ii)This project has two parts and both parts must be done in MAL.  You must submit two MAL source files.

(iii)There is one-week grace period for this assignment.


Description of Part (a) – 40 points

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 half and the bits 16 through 31 form the left half of 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 is 9.

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)Each time your program for Part (a) is executed, it should handle just one integer.

2)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.

3)There is no need to convert the integer to binary; when the integer is read in (using syscall), it is already in binary form.

4)Use bitwise operations to count the number of 1’s (0’s) in the right (left) half.

5)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.

6)To extract the decimal digits and compute the largest digit, use successive divisions by 10.

Description of Part (b) – 60 points

In this part, you are required to write a MAL program that prompts the user for a line of text and reads the line typed by the user. If the line contains just white space characters your program should 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 length in the line, then the program should print the word of maximum length that appears first in the line.)

6.The word of minimum length in the line. (If there are two or more words of minimum length in the line, then the program should print the word of minimum length that appears first in the 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 includes the punctuation mark at the end. (Recall that a word is any sequence of characters that does not include 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.

3.

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

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

4.Stop.

Programming Suggestions:

1)Each time your program for Part (b) is executed, it should handle just one line of text.

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

3)Study lecture materials about arrays of character in MAL (“Class 12-Data structures 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 whitespace characters, no other error checks are needed.

Submission:

You must perform submissions as directed by your instructor. Submission should include:

?source code for the evaluation – the procedure will be explained in your lab classes,

?screenshots with program output.

Important Notes: ignoring any of the following rules will result in penalty or even ZERO grade for the project.

1.For Project 4 you must turn in two files with source codes named as directed by your instructor.

2.At the top of each of your source file the following information must appear in the form of comments (note that comments in a MAL program start with the '#' character. You CANNOT use C style of comments in a MAL program):

(a)course code and title,

(b)semester,

(c)your class ID (e.g., ZR160102),

(d)your name,

(e)your student ID,

(f)the name of your lab classes supervisor.

3.Make sure that your programs compile and produce correct results using MARS. Programs that cause errors will NOT receive any credit.

Some sample data to test your program:

Important Note: Some sample inputs that can be used to test your programs are given below. However, you should remember that when we compile and 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 other input values.

Program Grading:

The total grade for the assignment is 100 points, with 40 points for Part (a) and 60 points for Part (b). As in the case of the other projects, your program must be well documented. Please consult the handouts on MAL to understand how MAL programs are documented.

Example of program execution:

Part (a). Example 1.

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


Part (a). Example 2.

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


Part (b). Example 1.

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


Part (b). Example 2.

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


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp