Question: The following description using the example output on screen to describe the behavior of the expected Lab 8. Italicized text are displayed on the console

The following description using the example output on screen to describe the behavior of the expected Lab 8.

Italicized text are displayed on the console screen; the Bold faced text are echoed user input; and the red colored text are comments not shown on screen.

At the start up time:

The course are configured at the start up time. Once the course is set up, the size of the class and number of tests can not be modified during run time.

____configure the course information____ Name of this course:COMSC-165 Section-1252 Total number of students?:3 Total number of tests?:6 === Lab8 Test Commands === CLASS: (COMSC-165 Section-1252), size: (3), number of tests: (6) create - to create/change a student record block - to enter a block of delimited score list batch - 1 by 1 to enter each block of score list show - to show a student scores and grade all - display all student grades modify - to modify a particular test score help - this menu quit - this program

At the run time:

The menu is hidden, and is displayed when help command is entered.

---- Enter a command ->create ------------------- Enter Student # 1/3

student name:Wu Shu Wang student id:1234567 ------------------- Enter Student # 2/3 student name:Kongfu King student id:0123456 ------------------- Enter Student # 3/3 student name:Martial Arts student id:0012345 ---- Enter a command ->batch command "batch" - to enter entire records using batch mode: enter record # 1 block of test scores:99,98,97,96,95,94 6 test scores created! enter record # 2 block of test scores:89,90,91,92,93,100 6 test scores created! enter record # 3 block of test scores:69,70,79,80,89,90 6 test scores created! ---- Enter a command ->all command "all" - dispay everyone's record: Name: Wu Shu Wang ID: 1234567 Average: 96 Grade: A Test: 99, 98, 97, 96, 95, 94 Name: Kongfu King ID: 0123456 Average: 92 Grade: A Test: 89, 90, 91, 92, 93, 100 Name: Martial Arts ID: 0012345 Average: 79 Grade: C Test: 69, 70, 79, 80, 89, 90 ---- Enter a command ->modify command "modify" - modify one record: which record # (1 - 3): 3 which test # (1 - 6) :1 to change test # 2 from 69 to:150 Please enter an integer between "1" and "100": 100 ---- Enter a command ->show command "show" - show one student's record: Enter Student record # 1 - 3 :1 Name: Wu Shu Wang ID: 1234567 Average: 96 Grade: A Test: 99, 98, 97, 96, 95, 94 ---- Enter a command ->show command "show" - show one student's record: Enter Student record # 1 - 3 :3 Name: Martial Arts ID: 0012345 Average: 84 Grade: B Test: 100, 70, 79, 80, 89, 90 ---- Enter a command ->block command "block" - to enter one record using block mode: Enter Student # between 1 to 3:2 Enter a (comma delimited) list of exactly 6 test scores:100,100,100,100,100(only 5 scores are entered) The list did not have exactly 6 test scores! ---- Enter a command ->block command "block" - to enter one record using block mode: Enter Student # between 1 to 3:3 Enter a (comma delimited) list of exactly 6 test scores:100,100,100,100,100,100 6 test scores created! ---- Enter a command ->show command "show" - show one student's record: Enter Student record # 1 - 3 :3 Name: Martial Arts ID: 0012345 Average: 100 Grade: A Test: 100, 100, 100, 100, 100, 100

There is an "enter" hidden helper command to batch enter a student record's test scores is available. Here are some of the example run of that command:

---- Enter a command ->enter command "enter" - enter one set of test scores: which record # (1 - 3):1 enter test # 1/6 score:99 enter test # 2/6 score:88 enter test # 3/6 score:77 enter test # 4/6 score:90 enter test # 5/6 score:80 enter test # 6/6 score:70 ---- Enter a command ->show command "show" - show one student's record: Enter Student record # 1 - 3 :1 Name: ID: Average: 0 Grade: Test: 99, 88, 77, 90, 80, 70

BLOCK ENTRY STARTER!

#include #include #include #include //#include

using namespace std;

void parse(string input, vector &tokens, string del) { tokens.clear(); int countDel =0; for(int i = 0; i if(input[i] == del[0]) countDel++; } int tokenSize = countDel +1; for(int i=0; i int x= input.find(del[0]); tokens.push_back(input.substr(0,x)); input = input.substr(x+1); } }

int tokenSize(string input, string del) { int size; int countDel =0; for(int i = 0; i if(input[i] == del[0]) countDel++; } return size = countDel + 1; }

int str2Int(string s) { int i; stringstream ss(s); //turn the string into a stream ss >> i; //convert return i; }

main() { string del = ","; vector tokens; string input; int sum = 0; cout getline(cin, input); parse(input, tokens, del);

int tSize = tokenSize(input,del); int *scores = new int[tSize]; for(int i =0; i;> scores[i] = str2Int(tokens[i]); cout cout for(int i =0; i;> cout ?",> cout for(int i =0; i;> sum += scores[i]; cout ?",> } cout return 0; }

LAB STARTER!

#include #include #include // std::locale, std::toupper #include #include

using namespace std;

struct Course { string name; int size; int testAmount; };

struct Student { string name; // Name of student. string id; // ID int* pScores; // Pointer to scores. bool ready; // flag to prevent manipulation on empty record. int average; // Average test scores. char grade; // His/her grade. };

// Function Prototypes void strLower(string &); void displayStudentRecord(Student *, int, int); void calculateGrade(Student *, int, int); int positiveInput(); int withinSizeInput(int); bool enterScoreList(Student *, int, int); void parse(string , vector &, string); int tokenSize(string, string); int str2Int(string);

void menu(string name, int size, int testAmount) { cout int main() { // start with uninitialized (empty) the structures string del = ","; Course sp14; Student *pStudent; // set up the class cout getline(cin, sp14.name); cout sp14.size = positiveInput();

cout sp14.testAmount = positiveInput();

pStudent = new Student[sp14.size]; for(int record_id = 0; record_id pStudent[record_id].ready = false; pStudent[record_id].average = 0; pStudent[record_id].grade = ' '; pStudent[record_id].pScores = new int[sp14.testAmount]; for( int test_num=0; test_num pStudent[record_id].pScores[test_num] = 0; } } menu(sp14.name, sp14.size, sp14.testAmount); // main loop while(true){ string option; // user command cout "; getline(cin, option); strLower(option); if(option == "help") { menu(sp14.name, sp14.size, sp14.testAmount); } else if(option == "create") { // command option to create/edit a student record // Get information about the students and create the record. for( int record_id = 0; record_id cout getline(cin, pStudent[record_id].name); cout getline(cin, pStudent[record_id].id); } } else if(option == "block") { cout // Part-1: block entry command // To be completed by you.

// end of part-1 } else if(option == "batch") { // command option 4. batch entry block grade cout // Part-2: batch of block entry commands // To be completed by you

// end of part-2 } else if(option == "show") { // command option 5. show student record cout int record_id=0; cout record_id = withinSizeInput(sp14.size) - 1; displayStudentRecord(pStudent, record_id, sp14.testAmount); }

else if(option == "all") { cout int record_id=0; for(int record_id=0; record_id displayStudentRecord(pStudent, record_id, sp14.testAmount); } else if(option == "modify") { cout int record_id=0; int test_num=0; int test_score; cout record_id = withinSizeInput(sp14.size); cout

if(pStudent[record_id-1].ready) { test_num = withinSizeInput(sp14.testAmount); cout int new_score = withinSizeInput(100); pStudent[record_id-1].pScores[test_num-1] = new_score; // update grade and average when test score changed calculateGrade(pStudent, record_id-1, sp14.testAmount); } else { cout } } else if(option == "enter") { // hidden helper command for development cout int input; int record_id=0;

cout cin >> record_id; cin.ignore(); record_id -= 1; // 1 -> 0 based for(int test_num=0; test_num cout > input; cin.ignore(); while ((!cin) || (input=0)> cout cin >> input; cin.ignore(); } pStudent[record_id].pScores[test_num] = input; } calculateGrade(pStudent, record_id, sp14.testAmount); pStudent[record_id].ready = true; } else if(option == "quit") { break; } else { cout } } // end main menu while // Release dynamically allocated memory used for structures. for(int record_id = 0; record_id ;> delete [] pStudent[record_id].pScores; pStudent[record_id].pScores = 0; } delete [] pStudent; pStudent = 0;

return 0; }

// block of list entry method bool enterScoreList(Student * pStudent, int record_id, int size) { vector tokens; string input, del=","; int sum=0; getline(cin, input); parse(input, tokens, del); int tSize = tokenSize(input,del); if(tSize == size) { for(int i =0; i;> pStudent[record_id].pScores[i] = str2Int(tokens[i]); } cout } else { cout } return true; } // String lower case conversion helper void strLower(string &str) { locale loc; string result; for (int i=0; i();> result.push_back(tolower(str[i],loc)); } str = result; }

// Function to display a student information void displayStudentRecord(Student *pStudent, int record_id, int size) { cout for(int test_num=0; test_num;> cout ?",> } }

void calculateGrade( Student * pStudent, int record_id, int size) { int sum = 0, average; // Part 3. generating Grade and Average // To be completed by you

// end of part-3 }

// Input and validate as a positive int value. int positiveInput() { int input; cin >> input; cin.ignore(); // Part-4 the checking and preventing user input error cin.fail() // or out of range data: (input=0),> // To be completed by you

// end of part-4 return input; }

int withinSizeInput(int size) { int input; cin >> input; cin.ignore(); // Fill the blank to perform the checking and preventing // user input error cin.fail() // or out of range data: (input=0)>

// end of the to be filled section return input; }

void parse(string input, vector &tokens, string del) { tokens.clear(); int countDel =0; for(int i = 0; i if(input[i] == del[0]) countDel++; } int tokenSize = countDel +1; for(int i=0; i int x= input.find(del[0]); tokens.push_back(input.substr(0,x)); input = input.substr(x+1); } }

int tokenSize(string input, string del) { int size; int countDel =0; for(int i = 0; i if(input[i] == del[0]) countDel++; } return size = countDel + 1; }

int str2Int(string s) { int i; stringstream ss(s); //turn the string into a stream ss >> i; //convert return i;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!