Question

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

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...)

The purpose of this assignment is to get experienc

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#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<<"\nMatching score found";
            break;
        }
      
    }
    if(found==false)
    cout<<"\nThe 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<<"\nAvg score: "<<avg;
    cout<<"\nMax score: "<< max;
    cout<<"\nMin 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<<"\nPlease select 1, 2, 3, or 4: ";
    cout<<"\nSearch score, Enter 1";
    cout<<"\nGenerate stats file, Enter 2";
    cout<<"\nPrint scores, Enter 3";
    cout<<"\nQuit, Enter 4:\t\t\t";
    cin>>choice;
  
    //switch case to handle user request
    switch(choice)
    {
        case 1:int search;
               cout<<"\nEnter 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<<"\nInvalid choice!!Try again!!";break;
    }
  
    }while(flag);
    }
    else
    cout << "\nData file not found";

   return 0;
}


Please post different questions for pseudo code and flowchart

Add a comment
Know the answer?
Add Answer to:
The purpose of this assignment is to get experience with an array, do while loop and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Programming

    PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...

  • (C++) Hey guys we just went over loops and it got me confused, it has me...

    (C++) Hey guys we just went over loops and it got me confused, it has me scrathcing my head for the past two days. I would appreciate any help you guys have to offer. Few places I have a hard time is get input and determine winner(cummulative part). Write a program that lets the user play the Rock, Paper, Scissors game against the computer. The computer first chooses randomly between rock, paper and scissors, but does not display its choice....

  • CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes...

    CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes the user and displays the purpose of the program. It then prompts the user to enter the name of an input file (such as scores.txt). Assume the file contains the scores of the final exams; each score is preceded by a 5 characters student id. Create the input file: copy and paste the following data into a new text file named scores.txt DH232 89...

  • Write a C program Design a program that uses an array to store 10 randomly generated...

    Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...

  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

  • java/javafx assignment: Island Paradise just started running their city lotto. You've been tasked with writing a...

    java/javafx assignment: Island Paradise just started running their city lotto. You've been tasked with writing a program for them. The program is going to allow to user to first select their lotto numbers. The program will then randomly generate the winning lotto numbers for the week and then check the winning numbers against the random ticket the user played in the Lotto to see how many numbers the user guessed correctly. The rules for lotto work as follows: Select 7...

  • Program 7 Arrays: building and sorting (100 points) Due: Friday, October 30 by 11:59 PM Overview...

    Program 7 Arrays: building and sorting (100 points) Due: Friday, October 30 by 11:59 PM Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be...

  • Plz give me correct code and screen shots for this question by using SASM !!!!!!!! Implement...

    Plz give me correct code and screen shots for this question by using SASM !!!!!!!! Implement the following working C++ program in assembler. Submit assembler code and screen shot. #include <iostream> #include <iomanip> using namespace std; // This menu-driven Health Club membership program carries out the // appropriate actions based on the menu choice entered. A do-while loop // allows the program to repeat until the user selects menu choice 4. int main() { // Constants for membership rates const...

  • java program QUESTION 2: 1. Write a do-while loop that asks the user to select a...

    java program QUESTION 2: 1. Write a do-while loop that asks the user to select a task from the following menu to continue: 1. Option 1 2. Option 2 3. Option 3 4. Option 4 5. Exit Read the selection from the keyboard then write the switch statement: For option 1, display the message "Do the option 1" For option 2, display the message "Do the option 2" For option 3, display the message "Do the option 3" For option...

  • using java Program: Please read the complete prompt before going into coding. Write a program that...

    using java Program: Please read the complete prompt before going into coding. Write a program that handles the gradebook for the instructor. You must use a 2D array when storing the gradebook. The student ID as well as all grades should be of type int. To make the test process easy, generate the grade with random numbers. For this purpose, create a method that asks the user to enter how many students there are in the classroom. Then, in each...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT