讲解:lecture slides、C/C++、Program Structure、C/C++Python|R

Exercise 1 (55%) The ex1.zip file contains the Time class from part 4 of the lecture slides. Some extra operator functions have been declared in the header file. You are required to implement these in the .cpp file. Note that some of these operators have been declared as member functions whereas others have been declared as friends of the class; this has been done arbitrarily to require you to implement both kinds of function. You must not make any changes to the header file. The six comparison operators should return boolean results (i.e. either true or false). A time t1 should be regarded as being smaller than another time t2 if it occurs earlier in the day. It is recommended that you implement the == operator and one of the operators directly and use those two in the implementation of the other operators. The -, -= and -- operators should behave in a similar way to the +, += and ++ operators (but t-n should be the time n seconds before t instead of n seconds after t). If you choose to implement operator- directly and call it in the other operators the code for the other three will be similar to those in the lecture slides. In the addition function it was necessary to check for seconds and minutes values greater than or equal to 60 and hours values greater than or equal to 24. In the subtraction you will need to check for values that have become less than 0. Note that when the first operand of the / operator is negative and the second is positive the result is rounded towards 0, and when the first operand of the % operator is negative and the second is positive the result is either 0 or negative; for example (-97)/60 gives -1 and (-97)%60 gives -37.The operator% function with return the elapsed time in seconds between its 2 arguments, i.e. the length of the period from a start time to an end time. The first operand denotes the start time and the second operand the end time, so if the second argument is earlier in the day than the first you should assume that it refers to the following day (e.g. the elapsed time from 11.30pm to 1am is 90 (5400 seconds)). Your submitted class will be tested using a main function that I will write so you should not submit a main function to test your code but it is strongly recommended that you write one to test your code. In order to allow my test program to load successfully, if you fail to complete any of the required functions you must instead provide dummy versions that return default values (e.g. false for the comparison operators and 0 for the friend % operator). Note that the six comparison operators have lower precedence than Exercise 2 (45%) This exercise involves write a program to analyse the text of a large file. The program will read the file, generate some information about it, and provide output both to the screen and to a file (whose name should be provided by the user). The information to be provided by the program is a bar-graph displaying the number of occurrences in the file of each word from a list of words that will be provided in a second text file. The program should ask the user for the names of the text file to be analysed, the file containing the search words and the代写lecture slides作业、代做C/C++程序、代写Program Structure作业、代做C/C++课程 output file. The program should terminate cleanly with an appropriate error message if any of the files cannot be opened. For the purpose of this assignment a “word” should be regarded as being a sequence of non-whitespace characters containing at least one letter. Any punctuation marks at the beginning or end of a word should be removed; punctuation marks in the middle of a word are to be regarded as part of the word. You must use the function ispunct, defined in the header file cctype, to check if a character is punctuation. All input should be converted to lower case, so ”IT”, ”It”, and ”it.” should all be converted to ”it”. If your program uses the exit function to terminate the program if a file cannot be opened you should include the header file cstdlib; some compilers recognise exit without the inclusion of this file, but some do not.Bar Graphs Bar graphs show visually the frequencies of certain items, the widths or heights of the bars being proportional to the frequencies. Here is a bar graph of the count of some words from the next paragraph above, converted to lower case. the ********** 10 if ** 2 chart ******* 2 If there are many occurrences of one or more word, the chart will need scaling, using one star for every n occurrences. If you do this, your output must indicate the scaling and the actual numbers should be shown alongside the bars, as seen above. To gain maximum marks the scaling factor should be based on the word with the largest number of occurrences. The word file may contain words that do not occur in the text; these should be distinguishable from words that do not, so a word that appears in the text must have at least one asterisk in the chart – hence a simple integer division by the scaling factor will not be sufficient. Program Structure Your program must contain a class called ReadWords and a class for generation of the bar graph (which should send its output to both cout and the output file), each with a .cpp and a .h file, and a main function in a separate file called ex2.cpp. You may, if you wish, use more classes. The header file for the ReadWords class and a partial implementation are provided in the ex2.zip folder in the zip file; you must use these and must not make any changes to the header file. Changes to the provided code in the the cpp file are permitted. A sample text file and word list will be provided to allow you to test your program; these will be uploaded to Moodle early in week 6. A separate (unseen) word list will be used to test your submitted work; this list will not contain more than 10 words and it will have a newline character at the end like the word list file provided. Deliverables You should submit a single zip file containing two folders, ex1 and ex2. The only file formats acceptable are .zip , .7z or a linux gzipped tar file. If you submit a file in any other format you will lose 20% of the marks for this assignment. The folder ex1 should contain the Time.h file and your Time.cpp file. The folder ex2 should contain all of the .h and .cpp files for the exercise 1, along with a .txt file that was produced as output by your program using the word list provided. Files generated by the compiler, such as .o and .exe files, should not be submitted.转自:http://ass.3daixie.com/2018110830818194.html

你可能感兴趣的:(讲解:lecture slides、C/C++、Program Structure、C/C++Python|R)