Question

I need #5 done i cant seem to understand it. it must be written in c++

4. Numeric Processing Write a program that opens the file random.txt, reads all the numbers from the file, and calculates and displays the following: a. The number of numbers in the file. b. The sum of all the numbers in the file (a running total) c. The average of all the numbers in the file numFile.cpp Notes: Display the average of the numbers showing 3decimal places 5. Download the file gradeBook.txt available through D21. The file contains an unknown number of students. Information for each student is displayed in two lines: The first line indicates the name of the student whitespaces are allowed. The second line shows the students grade in a class. Write a program that prompts the user for the name of the file and displays a nicely formatted report showing: a. Student with the highest grade in the class Name and grade b. Student with the lowest grade in the class Name and grade c. Average grade in the class gradeBook.cpp

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

4)

random.txt (Save the file under D Drive.Then the path of the file pointing to it is D:\\random.txt )

23
45
32
99
89
33
77
99
11
39
92
56

_______________

#include <iostream>
#include <fstream>
using namespace std;
int main()
{
//Declaring variables
int number,option,count=0,i=0;
double sum=0.0,average;
  
//fileInput reference
ifstream dataIn;

//Opening input file
dataIn.open("D:\\random.txt");
  
//this loop conitinues to counts the number of elements in the file
while(dataIn>>number)
{
count++;
}
//cout<<"Total No of Numbers in the file :"<<count<<endl;
dataIn.close();
  
//Creating an integer array
int filearr[count];
  
//Opening input file
dataIn.open("D:\\random.txt");
/* This loop continues to executes until it
* iterates over every number in the file
*/
while(dataIn>>number)
{
//Getting the number from the file and populates into an array
filearr[i]=number;
sum+=filearr[i];
//Incrementing the 'i' value by 1 every time
i++;
}
  
//calculating the average of all the numbers
average=sum/count;

//Displaying the results
cout<<"The number of numbers in the file :"<<count<<endl;
cout<<"The sum of all numbers in the file :"<<sum<<endl;
cout<<"The average of all the numbers in the file :"<<average<<endl;

return 0;
}
__________________   

Output:

C:Program Files (x86)\Dev-Cpp\MinGW64 bin\ReadFileUnknownNosSumAverage.exe The number of numbers in the file :12 The sum of a

_________________

5)

Add a comment
Know the answer?
Add Answer to:
I need #5 done i cant seem to understand it. it must be written in c++...
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
  • I am in C++ programming, I need help with this assignments. The answer in this assignments...

    I am in C++ programming, I need help with this assignments. The answer in this assignments when I look for it it doesn't work in my visual studios. Can you please help me? I hardly have C in the class, if I fail I will fail the whole class and repeat this class again.   The file named Random.txt contains a long list of random numbers. Download the file to your system, then write a program that opens the file, reads...

  • USE C++ FOR THE CODE THAT CAN RUN IN VISUAL STUDIO 2019 (or a complier) Ignore...

    USE C++ FOR THE CODE THAT CAN RUN IN VISUAL STUDIO 2019 (or a complier) Ignore the last paragraph on the bottom of the page! \ Write a program YourName-Assignments (replace Your Name with your actual name, no spaces) that reads from students' records (one student per line) in the following format: Last Name Tests Grade Assignments Grade and computes and outputs (to the console) the STUDENT STATISTICS in a table format one line per student: Student Name Total Points...

  • Write a Java program that reads a file until the end of the file is encountered....

    Write a Java program that reads a file until the end of the file is encountered. The file consists of an unknown number of students' last names and their corresponding test scores. The scores should be integer values and be within the range of 0 to 100. The first line of the file is the number of tests taken by each student. You may assume the data on the file is valid. The program should display the student's name, average...

  • using C# Write a program which calculates student grades for multiple assignments as well as the...

    using C# Write a program which calculates student grades for multiple assignments as well as the per-assignment average. The user should first input the total number of assignments. Then, the user should enter the name of a student as well as a grade for each assignment. After entering the student the user should be asked to enter "Y" if there are more students to enter or "N" if there is not ("N" by default). The user should be able to...

  • programming language is C++. Please also provide an explanation of how to create a file with...

    programming language is C++. Please also provide an explanation of how to create a file with the given information and how to use that file in the program Let's consider a file with the following student information: John Smith 99.0 Sarah Johnson 85.0 Jim Robinson 70.0 Mary Anderson 100.0 Michael Jackson 92.0 Each line in the file contains the first name, last name, and test score of a student. Write a program that prompts the user for the file name...

  • Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a...

    Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a student's name (on one line). Then, for each course the student took last semester, the file has 2 data lines. The course name is on the first line. The second line has the student's grade average (0 to 100) and the number of credits for the course Sample data: Jon P. Washington, Jr. Computer Science I 81 4 PreCalculus 75 3 Biology I 88...

  • This is a C++ Program, I need the program broken up into Student.h, Student.cpp, GradeBook.h, GradeBook.cpp,...

    This is a C++ Program, I need the program broken up into Student.h, Student.cpp, GradeBook.h, GradeBook.cpp, and Main.cpp 1. The system must be able to manage multiple students (max of 5) and their grades for assignments from three different assignment groups: homework (total of 5), quizzes (total (total of 2) of 4), and exams 2. For each student record, the user should be able to change the grade for any assignment These grades should be accessible to the gradebook for...

  • Using C++. Please Provide 4 Test Cases. Test # Valid / Invalid Data Description of test...

    Using C++. Please Provide 4 Test Cases. Test # Valid / Invalid Data Description of test Input Value Actual Output Test Pass / Fail 1 Valid Pass 2 Valid Pass 3 Valid Pass 4 Valid Pass Question 2 Consider a file with the following student information: John Smith 99 Sarah Johnson 85 Jim Robinson 70 Mary Anderson 100 Michael Jackson 92 Each line in the file contains the first name, last name, and test score of a student. Write a...

  • Please answer all the questions and I don't want work for another person. do it in...

    Please answer all the questions and I don't want work for another person. do it in jaf project. 5.6 (Conversion from m to kilometers) Write a program that displays the following two tables side by side: Miles Miles Kilometers Kilometers 1.609 20 12.430 15.538 3.218 25 37.290 14.481 60 I 65 40.398 10 16.090 5.8 (Find the highest score) Write a program that prompts the user to enter the number of students and each student's name and score, and finally...

  • ****THIS IS A 2 PART QUESTION! I ONLY NEED THE ANSWER TO PART 2 ON HOW...

    ****THIS IS A 2 PART QUESTION! I ONLY NEED THE ANSWER TO PART 2 ON HOW TO SEND THE DATA SERIALIZED**** Write a c# program that stores student grades in a text file and read grades from a text file.  The program has the following GUI: There are four buttons: Create File, Save Case, Close File and Load File.  Initially, only the Create File and Load File buttons are enabled.  If the user clicks the Create File button, a Save File Dialog window...

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