The purpose of this assignment is to get experience with an

The purpose of this assignment is to get experience with an array, do while loop and read and write file operations.

Your goal is to create a program that reads the exam.txt file with 10 scores. After that, the user can select from a 4 choice menu that handles the user’s choices as described in the details below. The program should display the menu until the user selects the menu option quit.

The project requirements:

It is an important part of your grade that you design your application according to the following requirements.

Step 1) Create a flowchart and pseudo code to list the actions and how they should occur.

Step 2) Add the exam.txt file inside your project.

exam.txt file is a file with 10 scores (see below image...)

Step 3) Write the source code according to your pseudo code and the following project requirements:

1. Declare the number of scores as a const. This const is to be used as size of your array.

2. Create the first for loop to read the data from the data file into an array. If the file is not found, the program needs to terminate with this error, “Data file not found.”.

3. Once the score data has been read into the array, display a menu with 4 choices to the user as follows below. This needs to be setup as a do while and repeat the program until the user selects the menu choice 4 (Quit).

Please select 1, 2, 3, or 4:

Search score, Enter 1

Generate stats file, Enter 2

Print scores, Enter 3

Quit, Enter 4

Then set up a switch statement with these cases to handle the user’s selection.

4. If the user selects the menu choice 1, ask the user for a score, then use a loop to search for the exact match inside your array and display a message if the match was found : “Matching score found” and if the match is not found display: “The score you entered is not found”.

5. If the user selects the menu choice 2, use another loop to find the highest and lowest score figures. Then generate a new text file called stats.txt, record the average, highest and lowest score figures and save 3 numbers in that file. Then display a message to the user: “The stats.txt file has been generated. The average, highest and the smallest scores are:…(display numbers here)”

6. If the user selects the menu choice 3, use another for loop to display all scores to the user.

7. If the user selects the menu choice 4, exit the program. Otherwise, display the menu again.

Step 4) Test run your program and include your printouts of your console output screenshots that cover the following test cases:

Test case1: User enters for menu selection 1 and for score 10

Test case1a: User enters for menu selection 1 and for score 35

Test case2: User enters 2

Test case3: User enters 3

Test case4: User enters 4

Test case5: User enters 5

Solution

#include <iostream>
#include <fstream>
using namespace std;

const int SIZE=10;

//function to read data frm file
int readData(int scores[SIZE])
{
    int tmp,cnt=-1;
    ifstream myfile(\"exam.txt\");
    if (myfile.is_open())
    {
         while(myfile>>tmp)
         {
             cnt++;
             scores[cnt]=tmp;
        }
    myfile.close();
    }
  
    return cnt;
}

//function to search score in array based on search item provided
void searchScore(int scores[],int size,int search)
{
    int found=false;
    for(int i=0;i<=size;i++)
    {
        if(scores[i]==search)
        {
            found=true;
            cout<<\"\ Matching score found\";
            break;
        }
      
    }
    if(found==false)
    cout<<\"\ The score you entered is not found\";
}

//display scores in array
void displayScores(int scores[],int size)
{
    for(int i=0;i<=size;i++)
    {
        cout<<scores[i]<<\"\\t\";
    }
}

//find max,mn,avergae scores in array and wriye to stats./txt
void findMaxMinScores(int scores[],int size)
{
    int max=-999,min=9999;
    float avg=0;
    for(int i=0;i<=size;i++)
    {
        if(scores[i]>max)
        max=scores[i];
        if(scores[i]<min)
        min=scores[i];
        avg+=scores[i];
    }
    avg/=size;
     ofstream myfile;
myfile.open (\"stats.txt\");
myfile << max <<min<<avg;
myfile.close();
    cout<<\"The stats.txt file has been generated. The average, highest and the smallest scores are below: \";
    cout<<\"\ Avg score: \"<<avg;
    cout<<\"\ Max score: \"<< max;
    cout<<\"\ Min score: \"<<min;
}

int main()
{
    //declare variables
    int scores[SIZE];
    //read datae frm file and retirve size
    int size=readData(scores);
    if(size>0)
    {
    bool flag=true;
  
    //loop until user quits
    do
    {
      
        //display menu options
        int choice;
    cout<<\"\ Please select 1, 2, 3, or 4: \";
    cout<<\"\ Search score, Enter 1\";
    cout<<\"\ Generate stats file, Enter 2\";
    cout<<\"\ Print scores, Enter 3\";
    cout<<\"\ Quit, Enter 4:\\t\\t\\t\";
    cin>>choice;
  
    //switch case to handle user request
    switch(choice)
    {
        case 1:int search;
               cout<<\"\ Enter score to search for: \";
               cin>>search;
               searchScore(scores,size,search);
               break;
        case 2:findMaxMinScores(scores,size);
               break;
        case 3:displayScores(scores,size);
            break;
        case 4:flag=false;break;
        default:cout<<\"\ Invalid choice!!Try again!!\";break;
    }
  
    }while(flag);
    }
    else
    cout << \"\ Data file not found\";

   return 0;
}


Please post different questions for pseudo code and flowchart

The purpose of this assignment is to get experience with an array, do while loop and read and write file operations. Your goal is to create a program that reads
The purpose of this assignment is to get experience with an array, do while loop and read and write file operations. Your goal is to create a program that reads
The purpose of this assignment is to get experience with an array, do while loop and read and write file operations. Your goal is to create a program that reads
The purpose of this assignment is to get experience with an array, do while loop and read and write file operations. Your goal is to create a program that reads

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site