Question

In: Computer Science

Create a c++ program with this requirements: Create an input file using notepad ( .txt )...

Create a c++ program with this requirements:

  1. Create an input file using notepad ( .txt ) . When testing your program using different input files, you must change the filename inside your program otherwise there will be syntax errors.
  2. There are a finite number of lines to be read from the data file. But we can’t assume to know how many before the program executes; so, the standard tactic is to keep reading until you find the “End of File” marker.
  3. Input date file consists of scores (one per line), might contain no score at all (an empty file) and program does not know how many scores before execution.
  4. If file not empty, determine how many valid scores (0 to 100), and how many invalid scores (less than 0 or greater than 100).
  5. Take only the valid scores and determine what letter grade and keep track of how many As, Bs, Cs, Ds, and Fs.  

(90 to 100 is an A, 80 to 89 is a B, 70 to 79 is a C, 60 to 69 is a D, 0 to 60 is a F)

  1. Output to the screen (not file output) with the followings: the number of valid scores, the number of invalid scores, the highest valid score, the lowest valid score, and the average of the valid scores. Also print out the histogram of the grades (sideway). Look at my output examples
  2. If the file is empty, don’t print any statistics at all. If the input file only has invalid scores, just print how many invalid scores and no valid scores, don’t include any statistics.
  3. Test your program with difference cases/scenarios.

It would just be based on this template:

#include<iostream>

#include<iomanip>

#include<fstream>

using namespace std;

int main ( )

{

int ValidScores=0, InvalidScores=0, numA=0, numB=0, numC=0, numD=0, numF=0;

double score, averageScore, highScore, lowScore;

ifstream In;

In.open( );

if ( )

{

cout << "Input file not found. Program ends" << endl;

return -1;

}

In >> score;

while ( )

{

}

if (ValidScores + InvalidScores) == 0)cout << "No data in the input file" << endl;

else if (ValidScores == 0) cout << InvalidScore << " invalid scores entered. No statistics" << endl;

else

{

}

return 0;

}

Solutions

Expert Solution

Here is the complete C++ code, I could not finish the histogram as the question does not show the output of the program and I could not figure out as how it needs to be displayed, could you please add that part, so that i can complete it. Rest all done.!

Thank you.

=======================================================================

#include<iostream>
#include<iomanip>
#include<fstream>

using namespace std;

int main ( )
  
   {
  
   int ValidScores=0, InvalidScores=0, numA=0, numB=0, numC=0, numD=0, numF=0;
  
   double score, averageScore, highScore, lowScore;
  
   ifstream In;
  
   In.open("scores.txt"); // update the input file name here
  
   if (In.bad() || !In.is_open() )
  
   {
  
   cout << "Input file not found. Program ends" << endl;
  
   return -1;
  
   }
  
   In >> score;
  
   while ( In)
   {
       if(score<0 || score>100) InvalidScores+=1;
       else if(score>=90) numA+=1;
       else if(score>=80) numB+=1;
       else if(score>=70) numC+=1;
       else if(score>=60) numD+=1;
       else numF+=1;
       if(score<=100 && score>=0){
           ValidScores+=1;
           averageScore += score;
           if(ValidScores==1) highScore=lowScore=score;
           if(highScore<score) highScore = score;
           if(lowScore>score) lowScore = score;      
       }
       In >> score;
  
   }
  
   In.close();
  
   if ((ValidScores + InvalidScores) == 0)cout << "No data in the input file" << endl;
   else if (ValidScores == 0) cout << InvalidScores << " invalid scores entered. No statistics" << endl;
   else   {
       cout<<"Total Invalid Scores: "<<InvalidScores<<endl;
       cout<<"Total valid Scores: "<<ValidScores<<endl;
      
       cout<<"Total A Scores: "<<numA<<endl;
       cout<<"Total B Scores: "<<numB<<endl;
       cout<<"Total C Scores: "<<numC<<endl;
       cout<<"Total D Scores: "<<numD<<endl;
       cout<<"Total F Scores: "<<numF<<endl;
      
       cout<<"Max Score: "<<highScore<<endl;
       cout<<"Low Score: "<<lowScore<<endl;
      
       cout<<setprecision(2)<<showpoint<<fixed;
       cout<<"Average Score: "<<averageScore/ValidScores<<endl;
  
   }
  
   return 0;

}

-====================================================================


Related Solutions

Create a c++ program that: Create an input file using notepad ( .txt ). When testing...
Create a c++ program that: Create an input file using notepad ( .txt ). When testing your program using different input files, you must change the filename inside your program otherwise there will be syntax errors. There are a finite number of lines to be read from the data file. But we can’t assume to know how many before the program executes; so, the standard tactic is to keep reading until you find the “End of File” marker. Input date...
[In Python] Write a program that takes a .txt file as input. This .txt file contains...
[In Python] Write a program that takes a .txt file as input. This .txt file contains 10,000 points (i.e 10,000 lines) with three co-ordinates (x,y,z) each. From this input, use relevant libraries and compute the convex hull. Now, using all the points of the newly constructed convex hull, find the 50 points that are furthest away from each other, hence giving us an evenly distributed set of points.
JAVA - Quick Sort .txt and Return ----------------------------------------------------------------------------- The program should input a .txt file like...
JAVA - Quick Sort .txt and Return ----------------------------------------------------------------------------- The program should input a .txt file like below and must use a Quick sort Algorithm ================ 6 10 4 19 10 12 8 6 0 1 2 3 ================ The first number "6" represents the index of the element to return after sort the second number on the top "10" represents the number of elements or size of array. The following numbers and lines are the elements that need to go...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
Create this C++ program using classes 1. Create a file text file with a string on...
Create this C++ program using classes 1. Create a file text file with a string on it 2. Check the frecuency of every letter, number and symbol (including caps) 3. Use heapsort to sort the frecuencys found 4. Use huffman code on the letters, symbols or numbers that have frecuencys I created the file, and the frecuency part but i'm having trouble with the huffman and heapsort implementation.
C++ Language Create Login Register program without open .txt file simple program also if you can...
C++ Language Create Login Register program without open .txt file simple program also if you can hide password input option menu 1) Login 2) Register 3) exit
1. Create a local file on your hard drive by using the NotePad editor that comes...
1. Create a local file on your hard drive by using the NotePad editor that comes with Windows or TextEdit on the MAC. Type into this file some remarks stating that you understand the FTP process. 2. Save it with the name "assign3.txt" 3. Start the FTP program. (SSH for Windows OR FileZilla for MAC) 4. Log on to electron.cs.uwindsor.ca server how do i do this on a mac computer It is intro to internet class
C Language NO ARRAY UTILIZATION OR SORTING Create a .txt file with 20 integers in the...
C Language NO ARRAY UTILIZATION OR SORTING Create a .txt file with 20 integers in the range of 0 to 100. There may be repeats. The numbers must not be ordered/sorted. The task is to find and print the two smallest numbers. You must accomplish this task without sorting the file and without using arrays for any purpose. It is possible that the smallest numbers are repeated – you should print the number of occurrences of the two smallest numbers....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT