read the program; it looks a lot like warm up 2, right? instead of reading data from a text file to your program, you'll be inputting numbers into an array, then copying those numbers to a file created by your .cpp program after running the program, look for (and hopefully find) the text file (should be in the same folder as your.cpp file) then, add the following to the program: o input validation, so that only valid quiz scores are entered (not less than zero nor greater than 100) • statements that will compute the average quiz score and write the average, in a sentence that says "Your average score is save and run the program; confirm that input validation works, and the average sentence appears at the end of your myData.txt file

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

answer in c++

V/input values into an array
//copying that data to a text file, which is created by the
- CPP
program
//text file should be in same folder as
cpp file
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
const int QUIZZES = 5;
int scores [QUIZZES];
//array size
//declaring array with 5 elements
//loop counter variable
//output file stream object
int count = 0;
ofstream outputFile;
//store values in the array
for (count = 0; count < QUIZZES; count++)
{
cout << "Enter a quiz score: ";
cin >> scores [count];
}
//creates and opens file for output
outputFile.open ("myData.txt");
//write array contents to ouput fil
for (count = 0; count < QUIZZES; count++)
outputFile <« scores [count] <<endl;
//close the file
outputFile.close ();
//confirm data written to output file:
cout << "The data was saved to the file.\n";
return 0;
}
Transcribed Image Text:V/input values into an array //copying that data to a text file, which is created by the - CPP program //text file should be in same folder as cpp file #include <iostream> #include <fstream> using namespace std; int main () { const int QUIZZES = 5; int scores [QUIZZES]; //array size //declaring array with 5 elements //loop counter variable //output file stream object int count = 0; ofstream outputFile; //store values in the array for (count = 0; count < QUIZZES; count++) { cout << "Enter a quiz score: "; cin >> scores [count]; } //creates and opens file for output outputFile.open ("myData.txt"); //write array contents to ouput fil for (count = 0; count < QUIZZES; count++) outputFile <« scores [count] <<endl; //close the file outputFile.close (); //confirm data written to output file: cout << "The data was saved to the file.\n"; return 0; }
read the program; it looks a lot like warm up 2, right?
instead of reading data from a text file to your program, you'll be inputting numbers into an array, then copying those numbers to a
file created by your .cpp program
after running the program, look for (and hopefully find) the text file (should be in the same folder as your .cpp file)
• then, add the following to the program:
o input validation, so that only valid quiz scores are entered (not less than zero nor greater than 100)
o statements that will compute the average quiz score and write the average, in a sentence that says "Your average score is"
save and run the program; confirm that input validation works, and the average sentence appears at the end of your myData.txt file
Transcribed Image Text:read the program; it looks a lot like warm up 2, right? instead of reading data from a text file to your program, you'll be inputting numbers into an array, then copying those numbers to a file created by your .cpp program after running the program, look for (and hopefully find) the text file (should be in the same folder as your .cpp file) • then, add the following to the program: o input validation, so that only valid quiz scores are entered (not less than zero nor greater than 100) o statements that will compute the average quiz score and write the average, in a sentence that says "Your average score is" save and run the program; confirm that input validation works, and the average sentence appears at the end of your myData.txt file
Expert Solution
Step 1

Solution:

In the code that is given  in the question :

  • input validation can be performed as follows :

// performing input validation to check if the score <=0 and score>100
    while (scores[count] <= 0 || scores[count] > 100)
    {
        cout << "value not accepted.\n";
        cin >> scores[count];
    }

  • The average of quiz scores can be done as follows:

                 sum= sum + scores[count];
                 avg = sum /quizzes;

 

Step 2

// code:

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

int main()
{   const int quizzes =5;
    int scores[quizzes];
    int count =0;
    int sum=0;
    double avg = 0.0;
    ofstream outputfile;
    if (scores == NULL)
    return 0;
//Get the quizz score for each test
   cout << "Enter the quizz scores below.\n";
   for (int count = 0; count <quizzes ; count++)
   {
    cin >> scores[count];

  // performing input validation to check if the score <=0 and score>100
    while (scores[count] <= 0 || scores[count] > 100)
    {
        cout << "value not accepted.\n";
        cin >> scores[count];
    }

// calculating the average of quiz scores
    sum= sum + scores[count];
    avg = sum /quizzes;
   }
     outputfile.open("myData.txt");
     for(count=0;count<quizzes;count++)
        outputfile <<scores[count] << endl;
        outputfile <<"your average score is " <<avg <<endl;
     
     outputfile.close();
     cout<<" The data was saved to file";
     cout<< "\n your average score is"<<avg<<endl;

    return 0;
}

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Structured English
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education