📄 http:^^www.cs.wisc.edu^~milo^cs302^quiz4.html
字号:
Date: Mon, 11 Nov 1996 17:12:10 GMTServer: NCSA/1.5Content-type: text/htmlLast-modified: Wed, 06 Nov 1996 18:32:19 GMTContent-length: 3671<HTML><HEAD><TITLE>Quiz 4 - CS 302 Fall 1996 - Section 4</TITLE></HEAD><BODY><H4 ALIGN=CENTER> <!WA0><!WA0><!WA0><!WA0><!WA0><!WA0><A HREF="http://www.cs.wisc.edu/~cs302">CS 302</A> Fall 1996 - <!WA1><!WA1><!WA1><!WA1><!WA1><!WA1><A HREF="http://www.cs.wisc.edu/~milo/cs302.html">Section 4</A></H4> <H4 ALIGN=CENTER>Quiz 4 (Take Home)</H4><H5 ALIGN=CENTER>Due Monday, November 11, 1996</H5> <hr><br>This quiz is a ``take home'' assignment that counts the same as anin-class quiz. Like an in-class quiz, this should be all of your ownwork, though you are welcome to use your text and/or a computer toassist you in this assignment. Your answers may be written out byhand, or preferably, typed.<OL> <LI> (5 points) Write a function called <TT>display</TT> that takestwo parameters: an array of characters and an integer for size of thearray. The function should write the first N characters of the arrayto <TT>cout</TT>, where N is the size parameter that was passed intothe function. (Precondition: The size passed in will not be longerthan the actual size of the array.) <p> <LI> (5 points) Write a function called <TT>num_equal</TT> thattakes three parameters: two arrays of integers and an integer variablefor the number of valid entries in the array (in most cases just thesize of the array). The function should return the number of pairs ofintegers that are the same. For example, if the function was passedtwo arrays {1, 2, 3, 4} and {2, 2, 3, 5}, and size 4, the functionwould return 2. (Precondition: The size passed in will not be longerthan the actual size of either array.) <p> <LI> (8 points) Design and implement a QuizScores class. Thisclass will be used to read in and average quiz scores. All quizscores are integers from the range 0-20. You will need the followingprivate variables: <UL> <LI> an array of integers to hold the scores. Declare this tocontain at least 100 elements. <LI> an integer to keep track of how many quiz scores you readin. </UL>You will need the following public methods: <UL> <LI> a constructor which takes a single <TT>ifstream</TT> as aparameter and reads the data from that file. The first integer in thedata file is the number of quiz scores. The rest of the file containsN integer quiz scores, where N is the first integer in the file. Thedata should be read from the file and stored in the private arrayvariable, and also set the integer that keeps track of the number ofscores entered. If the number of scores in the file is greater thanthe size of the array to hold the scores, give an error message and<TT>exit(1)</TT> the program. <LI> an <tt>average</tt> method which takes no parameters andreturns the average quiz score, a double. <LI> a <tt>getNumber</tt> method which returns the number of quizscores read in. </UL> <p> <LI> (2 points) Modify your QuizScores class by adding anotherpublic method that will produce a histogram of the results. Themethod should take a single <tt>ofstream</tt> as a parameter and writeto that stream a histogram of the quiz results. To do this you willneed a local array variable with 21 elements (0-20 is 21 possiblescores). Use this array to count how many time each score occurs inthe file. For example, if the quiz scores were 10, 15, 15, 15, 15, 18, 18, 20, the following should be displayed:<PRE> 0: 1: 2: 3: 4: 5: 6: 7: 8: 9:10:*11:12:13:14:15:****16:17:18:**19:20:*</PRE>(Note: This question is only two points due to the extra time it willtake to complete, if you can not finish this or can't figure it out,the most you can lose on this problem is only two points.)</OL></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -