ENG 101: Introduction to Computers and Programming Homework 2

Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due

Engineering 101 Homework 2 

You are to turn in these pages as part of your assignment in addition to any other sheets you need. All pages must be stapled and all answers must be typed or neatly printed. This is an individual assignment; though you are welcome to work with others. Assignments that are unstapled or are difficult to read will lose at least 50% of the possible points and we may not grade them at all. 

This assignment is worth about 1% of your grade in the class and is graded out of 50 points. Remember you may drop one homework assignment. Note that there are two pages to this assignment. 

The code associated with this assignment is available for download, both as an “enscripted” pdf file as well as plaintext. 

The program computes a student’s grade in this class. The program allows the user to change the number of each type of assignment, the weight of each type of assignment, and the number of points each assignment is graded out of. Those are changed by modifying the constants found at the start of the file. These values are all pretty much the same as our course. This includes that 1 homework assignment and 2 inlabs will be dropped. If you don’t understand how the class is graded, now would be a good time to look at the overview section of the course webpage. 

Also, ignore the getScores() function. Just assume it populates the courseGrades structure with scores. All constants are kept the same as in the code unless otherwise noted. 

Questions: 

1) The sort() function is declared as having a “void” return value. Use your text (or some other source) and explain what that means. What is the sort function actually doing that would impact the code which calls it? [3] 

2) Consider the sumList() function. 

a) Explain what the function does in terms of its three parameters. [3] 

b) Why does it call sort? [3] 

c) If the function were called as 

x=sumList(a,4,2) 

where x is a double and a is an array of ints with values a={1, 30, 2, 40, 5}, what would the value of x be after the call? [4] 

3) If courseGrades.quiz[]={30,25}, what value would quizContrib have? [4] 

4) If courseGrades.exam[]={90,20,100}, what value would examContrib have? [5] 

5) If courseGrades.hw[]={50,20,40,10,50}, what value would hwContrib have? [5] 

6) There is a comment that sorting project scores would be bad (in the main, just before the projectContrib is computed). 

a) Why would it be bad? [3] 

b) Of sort(), sumList(), contrib(), and projectContribution() which ones would sort the array? [2] 

7) There are a few formatting or code design “errors” in the code. Things which are either inconsistent or not standard with what we have done so far. Name two. [2] 

Harder questions 

8) At various points in the code the “assert()” function is used. It is included via “cassert” at the top of the code. 

a) Explain what assert is doing and why it is useful. Again, the text or a web search will prove useful here. [3] 

b) One thing that isn’t tested for is that the sum of all the weights comes to 100. Write a line of code that uses assert to test for that. Where would you place that line? [4] 

9) Calling sumList twice to get the examContrib score is pretty ugly. How we avoid calling any function to get the “best” score? Provide the replacement code which computes “best”. [5] 

10) In getScores() there is a line “if (!scoreFile)”. Using the text or other resource figure out what that line is doing. [4]

发表评论

电子邮件地址不会被公开。 必填项已用*标注