C/C++ 编程代写
当前位置:以往案例 > >CS案例之C++ Write a C++ program to grade multiple-c
2017-12-16


Problem Description

Write a C++ program to grade multiple-choice, including True/False, questions for an  given in a class. A class may have one or more sections. The answer keys are the same for all sections of a class for one , but the number of students is normally different for different sections. Your program will be used for different classes and/or different s, and the number of questions will be different. But any  should have at least 1 and at most 40 questions. The answer key and a student's answer to a question could be a digit, between 1 and 5 (inclusive), or a character among A, B, C, D, E, F and T, or lower case equivalent.

Input Data

· The first value in the input file is the number of questions of the .

· The second line is the answer keys without spaces between any two answers.

· The next line is the number of sections, followed by data for all sections.

· The data for a section begins with the number of students, followed by students' data.

· The data for each student is on a separate line, beginning with the answers from the student followed by the student's last name.

· As the key answers, there is no space between any two answers.

· The student's last name comes after his/her last answer without any spaces between.

· Any student's last name has at most 15 characters.

Sample input is given later.

You can assume the input data are correct and do not check for invalid values.

Output Data

· For each student, last name, number of correct answers, and Pass or Fail. A student passes an  if the number of correct answers is 70% or better of total number of questions, and fails otherwise.

· For each section, the total number of students and the number of students who passed the .

· For the entire class, the number of sections, the total number of students and the number of students who passed the .

See sample output later for the exact output format.

The following requirements must be followed:

1. You must NOT use structs, 2D array or classes. You will lose 2 points if you do NOT adhere to this.

2. You must use the following two functions in your program. You will lose 2 points for each of the functions that is not used in your program.

3.

4. // The function reads in numQuestions answers into array answers.

5. // Parameters: (out, in)

6. void  ReadAnswers(char answers[], int numQuestions);

7.

8. // The function compares a student's answers against the answer

9. //     keys and passes back the number of correct answers and

10.   //     whether the student passed the .

11.   // Parameters: (in, in, in, out, out)

12.   void  ProcessAnswer(const char keys[], const char answers[],

13.                       int numQuestion, int& correct, bool& pass);

14.

15. You must also use the following two functions in your program. You should also provide the comment blocks for the function documentation. You will lose 2 points for each of the functions that is not used. You will lose 1 points for each missing documentation comment block.

16.

17.void  UpdateTotal(int& totalStudents, int& totalPassed,

18.                  int numStudents, int Passed);

19.void  ProcessOneSection(int& numStudents, int& Passed,

20.                        int numQuestion, char Keys[]);

21. You must use the same function ReadAnswers() to read the answer keys and the answers for each student. You will lose two points if different functions are used.

22. You must use for loops to process all sections of the class, all students of a section, and all answers of a student. No while loops are allowed on this project. You will lose two points for each while loop used in your program.

23. You must follow the programming ground rules.

o All functions, including the main function, should be no more than 30 lines long, from the left brace to the right brace, inclusive.

o Each function should have a comment block before the function header, and each function parameter should be identified as in, out, or in/out parameter.

o Each line, including comments, should be at most 74 columns long.

o No magic numbers! Some constant definitions are given below:

o

o const int MAX_QUESTIONS  = 40;

o const float PASS_PERCENT = 0.7;

24. To get credit for the project, your solution must minimally work on test set 1 of your submission log. The input file of test1 is given to you.

Notes

Your main() function could be like the following:


Read number of questions

Read and store the answer keys

Read number of sections

For each section

Process all students' answers

Update class results

Display results for the section

Display results for the entire class

You can also use function toupper(x) to convert a character to upper case. You need to include header fileto use the function.

Sample Input (Test set 1)


10

t2ft5Ttfft

2

4

T2Ft4ttftTHockney

t1fF5ffttfHill

f3ft5fTTftLongwood

t4Tf5TFTFTSharp

5

T2Ft5ttffTHockney

t2ft4ttfFtHill

f2ft4tTTftLongwood

t2Tf5FFTFTSharp

t2fT5FFTtTQuick

Sample Output (Test set 1)

The following output is generated in batch mode.


Name          Correct Answers      PASS/FAIL

—————    —————      ———

Hockney           8                PASS

Hill           3                FAIL

Longwood           6                FAIL

Sharp           5                FAIL


1 out of 4 students of section 1 passed the .



Name          Correct Answers      PASS/FAIL

—————    —————      ———

Hockney          10                PASS

Hill           9                PASS

Longwood           7                PASS

Sharp           5                FAIL

Quick           6                FAIL


3 out of 5 students of section 2 passed the .



There are 10 questions in the .

There are 2 sections, and 4 out of 9 students passed the .

Since the HiC grader runs in interactive mode, the output will look different:


10

t2ft5Ttfft

2

Name          Correct Answers      PASS/FAIL

—————    —————      ———

4

T2Ft4ttftTHockney

Hockney           8                PASS

t1fF5ffttfHill

Hill           3                FAIL

f3ft5fTTftLongwood

Longwood           6                FAIL

t4Tf5TFTFTSharp

Sharp           5                FAIL


1 out of 4 students of section 1 passed the .



Name          Correct Answers      PASS/FAIL

—————    —————      ———

5

T2Ft5ttffTHockney

Hockney          10                PASS

t2ft4ttfFtHill

Hill           9                PASS

f2ft4tTTftLongwood

Longwood           7                PASS

t2Tf5FFTFTSharp

Sharp           5                FAIL

t2fT5FFTtTQuick

Quick           6                FAIL


3 out of 5 students of section 2 passed the .



There are 10 questions in the .

There are 2 sections, and 4 out of 9 students passed the .

When you test your program, please make sure your output matches the interacive mode output if you are using HiC.







CS303 Program 5
Program Description
You are going to write a computer program/prototype to process mail packages that are sent to different cities. For each destination city, a destination object is set up with the name of the city, the count of packages to the city and the total weight of all the packages. The destination object is updated periodically when new packages are collected. You will maintain a list of destination objects and use commands to process data in the list.

Commands Description
You will read and process commands from the standard input, stopping when the Quit command is entered. Commands can have parameters. The commands you are to implement are of the form:


Add city

Output city

Update city package_count package_weight

Clear city

Quit

1. Add command: Add a destination object for the given city to the end of the list if a destination object for that city doesn't already exist and the list isn't full. If the list is full or a destination object for that city already exists, still read in the data; however, don't do anything with the data read in (toss it!), and print an error message (check the full condition first). Be sure to initialize the new destination object before adding it to the list.

2. Output command: Output the average package weight of the destination object for the specified city. If the destination object for the given city doesn't exist, print an appropriate message. See the sample outputs below for the exact message.

3. Update command: Update the destination object for the specified city by adding the given package_count and package_weight to the count and weight respectively. If the destination object doesn't exist, print an appropriate message.

4. Clear command: Reset the count and weight of the destination object for the specified city to zero, but do not change the city name. If the destination object doesn't exist, print an appropriate message.

5. Quit command: Terminate the program.

You can assume all inputs are formatted correctly. In particular, you do not need to check for invalid commands.

Requirements
1. You must use the following declarations:


const int MAX_CITIES = 5;

const int NOT_FOUND = -1;


// Write a comment block here that describes this class.

class Destination

{

string city;        // the name of the city where packages are to be sent

int package_count;  // count of packages

float total_weight; // total weight of all packages



. . . // remove this comment and add properly-commented methods which are described below.

};


// Write a comment block here that describes this class.

class DestinationList

{

int num;                       // number of objects in the list

Destination list[MAX_CITIES];  // array of destinations



. . . // remove this comment and add properly-commented methods which are described below.


};

2. You cannot add other data members to this Destination class. Failure to comply will result in a zero (0). We suggest you copy/paste these into your program!


3. You are only allowed to manipulate a Destination's data member via the following four methods and one constructor.  These methods MUST be placed in the class Destination; 2 points off for each one not in the Destination class and 2 points off if NOT used.   Do NOT forget to complete the “TODO” portions indicated below.  You will lose points if you forget to finish these TODOs!


// This constructor initializes the city to name and

// both the package count and total weight to 0.

// params: TODO

Destination( string name )


// Adds numPackages and packageWeight to the package count and total weight, respectively.

// params: TODO

void RecordShipment( int numPackages, float packageWeight )


// Returns true if the object's city is the same as name; false otherwise

// params: TODO

bool DestinationHasName( string name )


// Zeroes the package count and total weight.

void ClearShipment( )


// returns average weight of the packages in a shipment, or 0.0 if there

// are no packages

float AverageWeight( )


4. You must properly complete and comment these methods. None of these methods are allowed to print or read any data; if they do, you will lose 3 points for each violation.


5. For the DestinationList class, you must write a search function. The function must have one parameter: a string containing a city name. The function is to determine whether or not an object with the specified city name is in the list, returning the index of the city if it is found or a -1 if it is not. Failing to write and use this function will result in a 3-point penalty. Furthermore, the function cannot read or print data with a 2-point penalty if it does.  For this DestinationList class, you should have a default constructor and public methods, to add, update and output information maintained by this class.


6. Lastly, the main program should ONLY have 2 variables. One of those variables will be of type DestinationList and the other of type string to hold the command.  -2 points for using more than 2 variables in main.


7. Display all float values with 2 decimal digits. Use


cout << fixed << showpoint << setprecision(2);


8. See the sample output for the exact wording of all messages.


9. To get minimal credit for the project, your solution must work on both Test 1 and Test 2.


10. Don't forget to follow the programming ground rules.


11. You may work in teams for this project. If you choose to work in a team, you must sign up by Wednesday, Nov. 9th at 3 pm. If you choose this option, you must follow the other requirements given here: team-requirements. Note you will be required to work in teams for project 6.

Sample Input (Test 1)

Add Madison

Add Chicago

Update Madison    2 60.75

Update Chicago    4 180

Update Chicago    3 46.1

Output Chicago

Output Madison

Add Dubuque

Update Dubuque    4 400

Clear Chicago

Output Chicago

Update Dubuque    2 106.44

Output Dubuque

Quit

Sample Output (Test 1)

Add Madison

Madison added to the list.

Add Chicago

Chicago added to the list.

Update Madison    2 60.75

Destination Madison updated with 2 packages weighing 60.75 lbs.

Update Chicago    4 180

Destination Chicago updated with 4 packages weighing 180.00 lbs.

Update Chicago    3 46.1

Destination Chicago updated with 3 packages weighing 46.10 lbs.

Output Chicago

Average weight of all packages to Chicago: 32.30

Output Madison

Average weight of all packages to Madison: 30.38

Add Dubuque

Dubuque added to the list.

Update Dubuque    4 400

Destination Dubuque updated with 4 packages weighing 400.00 lbs.

Clear Chicago

Output Chicago

Average weight of all packages to Chicago: 0.00

Update Dubuque    2 106.44

Destination Dubuque updated with 2 packages weighing 106.44 lbs.

Output Dubuque

Average weight of all packages to Dubuque: 84.41

Quit

Normal termination.

Sample Input (Test 2)

Add Madison

Add Chicago

Add Dubuque

Add Orlando

Add Madison

Add Miami

Add Denver

Update Chicago  3 40.5

Update Madison  2 50.79

Output Chicago

Output Denver

Update Orlando 38  482.12

Update Denver  10  100.33

Clear  Chicago

Output Chicago

Clear  Denver

Quit

Sample Output (Test 2)

Add Madison

Madison added to the list.

Add Chicago

Chicago added to the list.

Add Dubuque

Dubuque added to the list.

Add Orlando

Orlando added to the list.

Add Madison

Madison is already in the list.

Add Miami

Miami added to the list.

Add Denver

Denver not added. List is full.

Update Chicago  3 40.5

Destination Chicago updated with 3 packages weighing 40.50 lbs.

Update Madison  2 50.79

Destination Madison updated with 2 packages weighing 50.79 lbs.

Output Chicago

Average weight of all packages to Chicago: 13.50

Output Denver

Cannot output. Denver is not in the list.

Update Orlando 38  482.12

Destination Orlando updated with 38 packages weighing 482.12 lbs.

Update Denver  10  100.33

Cannot update. Denver is not in the list.

Clear  Chicago

Output Chicago

Average weight of all packages to Chicago: 0.00

Clear  Denver

Cannot clear. Denver is not in the list.

Quit

Normal termination.


在线提交订单