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

  • 4246833550117072547935996346570614628282896249299694382843739260590315429338342271771989644872777253987091366830036895704812323334674665142712254869548645663758 388607247425307793173619184328910741943265649447806891730371351710239454963062485955757841967

    4246833550117072547935996346570614628282896249299694382843739260590315429338342271771989644872777253987091366830036895704812323334674665142712254869548645663758 38860724742530779317361918432891074194326564944780689173037135171023945496306248595575784196737793230994544062732453853911983930542834116640659705931978307 6743872274692573271830778574985139872911626373567686565753253351151942725967431108192833845828875438494691021075922258942394750731414169901592763656411360 625538549484596426033512928373752159722349200669485282735541000419939901789128468729894649484808422311618814515 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 all the numbers from the file, and calculates the following: The number of numbers in the file The sum of all the numbers in the file (a running total) The average of all the numbers in the file The program should display the number of numbers found in the file,...

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

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

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

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

  • PLEASE USE BASIC C++ CODE PLEASE USE BASIC C++ CODE PLEASE HAVE DONE AS SOON AS...

    PLEASE USE BASIC C++ CODE PLEASE USE BASIC C++ CODE PLEASE HAVE DONE AS SOON AS POSSIBLE THANK YOU I REALLY APPRECIATE IT FILE TEXT: Mary 80 90 75 90 85 Joe 80 65 80 80 80 Same program as Quiz #4, but this time it must be done with arrays: Write a program that calculates the average of 5 test scores for each student on the file. Function 1--write a function to read the student's name 5 test scores...

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

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

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