Question

In: Computer Science

C++ program that will ask the user for how many test scores will be entered. Setup...

  1. C++ program that will ask the user for how many test scores will be entered.
  2. Setup a while loop with this loop iteration parameter. The data will include the student’s first name and midterm score
  3. Print out the completed test scores to a file (midTermScores.txt) .
  4. Print out list of students names and grades
  5. in the print out, a letter grade should replace numeric score using standard grading (a = 90 – 100, b=80-90, c=70-80, d=60-70, f=below 60)

Solutions

Expert Solution

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

int main(){
        
        int nscores;
        
        cout << "Number of Test scores : ";
        cin >> nscores;
        
        string fnames[nscores];
        float scores[nscores];
        
        int i=0;
        
        // Reading first names and test scores
        while( i < nscores ) {
                cout << "Enter First Name : ";
                cin >> fnames[i];
                cout << "Enter Score : ";
                cin >> scores[i];
                i++;
        }
        
        i = 0;
        
        // printing names and test scores
        cout << "--------------------------------"<<endl;
        
        cout << "Name"<<"\t"<<"Score" << endl;
        
        while( i < nscores ) {
                cout << fnames[i] <<"\t"<< scores[i] <<endl;
                i++;
        }
        
        cout << "--------------------------------"<<endl;
        
        
        int j = 0;
        
        ofstream fs;
        
        //clearing file with empty text
        fs.open("midTermScores.txt");
        fs << "";
        fs.close();
        
        fs.open("midTermScores.txt", ios::app);
        
        // writing first name and scores on file
        while( j < nscores ) {
                fs << fnames[j] <<"\t"<< scores[j] <<endl;
                j++;
        }
        
        // closing file
        fs.close();
        
        
        int k = 0;
        
        // printing firstnames and grades
        cout << "Name"<<"\t"<<"Grade" << endl;
        while( k < nscores ) {
                
                int n = scores[k];
                char grade;
                if( n >= 90 && n <= 100 ){
                        grade = 'A';
                }else if(n >= 80 && n < 90){
                        grade = 'B';
                }else if(n >= 70 && n < 80){
                        grade = 'C';
                }else if(n >= 60 && n < 70){
                        grade = 'D';
                }else{
                        grade = 'F';
                }
                cout << fnames[k] << "\t" << grade <<endl;
                k++;
        }
        
        return 1;
}

Output:


Related Solutions

Create a C++ program that will ask the user for how many test scores will be...
Create a C++ program that will ask the user for how many test scores will be entered. Setup a while loop with this loop iteration parameter. (no fstream) The data needs to include the student’s first name, student number test score the fields should be displayed with a total width of 15. The prompt should be printed with a header in the file explaining what each is: ex. First Name student number Test Score 1) mike 6456464   98 2) phill...
Q1) Please create a C++ program that will ask the user for how many test scores...
Q1) Please create a C++ program that will ask the user for how many test scores will be entered. Setup a while loop with this loop iteration parameter. The data will include the student’s first name, Wayne State Access ID, midterm score and their favorite team (i.e. – Doug, hg1702, 92, Wolverines * - John, hv2201, 99, Warriors). Print out the completed test scores to a file (midTermScores.txt) . Adjust the output as follows: (15 points) a. Scores with the...
C LANGUAGE Ask user how many scores there are, then ask for each score. Then calculate...
C LANGUAGE Ask user how many scores there are, then ask for each score. Then calculate the average score and scores below 60. Then display the average score and number of scores below 60
Write a program in Java to: Ask the user how many scores they want to enter...
Write a program in Java to: Ask the user how many scores they want to enter (=> Create an array based the entered size) Ask the user to enter their scores in the quarter (Fill the array with the entered scores(assigned to elements)) ==>> Use a "for" loop Find the greatest score Calculate and show the average Show the final grade based on the average (For example A,B,C ... ) Print the scores (the elements of the array) => Use...
Write a program using C++ that ask the user for the flowing: How many shares to...
Write a program using C++ that ask the user for the flowing: How many shares to be bought: The price per share: Percent commission for the broker for each transaction: Average annual return as of percentage: The program should calculate and display the following: The amount paid for the stock alone (without the commission) The amount of the commissionThe total amount of paid (the payment for stock plus the commission) After TEN years, your shares will worth:
Ask the user to enter test scores. Once they have entered -1, print out the highest...
Ask the user to enter test scores. Once they have entered -1, print out the highest grade. Ensure that the grade entered is an integer.(Using Java Language) Enter integers between 0 and 100, -1 when finished. Enter a test score: [asdf] Enter an integer. Enter a test score: [32.5] Enter an integer. Enter a test score: [42] Enter a test score: [99] Enter a test score: [87] Enter a test score: [x] Enter an integer. Enter a test score: [-1]...
write a program in c++ that asks the user to enter their 5 test scores and...
write a program in c++ that asks the user to enter their 5 test scores and calculates the most appropriate mean. Have the results print to a text file and expected results to print to screen.
Python Program Write a program that will ask a user on how many input colored balls...
Python Program Write a program that will ask a user on how many input colored balls of the following codes: R-red, B-blue, W-white, G-green and O-orange -will he or she would like to enter in the program and print the total number of Red balls were encountered. Assume an uppercase and lower case letter will be accepted.
write a c++ program . Ask the user to enter a number less than 100. Test...
write a c++ program . Ask the user to enter a number less than 100. Test the input to make sure it is correct, and use a while loop to continuously ask the user for correct input value if they don't follow the input rule. After receiving the correct input, test the number to see if it is even or odd. If it is odd, use a while loop to do the following: Output to the monitor all odd numbers...
Write a Java program that will first ask the user how many grades they want to...
Write a Java program that will first ask the user how many grades they want to enter. Then use a do…while loop to populate an array of that size with grades entered by the user. Then sort the array. In a for loop read through that array, display the grades and total the grades. After the loop, calculate the average of those grades and display that average. Specifications Prompt the user for the number of grades they would like to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT