Question

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 all the numbers from the file, and calculates the following:

  1. The number of numbers in the file
  2. The sum of all the numbers in the file (a running total)
  3. The average of all the numbers in the file

The program should display the number of numbers found in the file, the sum of the numbers, and the average of the numbers.

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

Source code:

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

int main()
{
   ifstream fs("Random.txt");
   int num,count=0;
   double sum=0.0,avg=0.0;
   while(fs>>num)
   {
       ++count;
       sum=sum+num;
   }
   avg=sum/count;
   cout<<"Number of numbers in the file:"<<count<<endl;
   cout<<"The sum of all numbers in the file:"<<sum<<endl;
   cout<<"The average of all numbers in the file:"<<avg<<endl;
}

Random.txt:

1 10 9 8 7 6 5 4 3 2 1

1 #include <iostream> 2 #include <fstream> 3 using namespace std; 4 5 int main() 6 { 7 ifstream fs(Random. txt); 8 int num,Sample input and output:

(base) rgukti@rgukt-TravelMate-P243-M:-/Desktop$ ./a.out Number of numbers in the file: 10 The sum of all numbers in the file

Add a comment
Know the answer?
Add Answer to:
I am in C++ programming, I need help with this assignments. The answer in this assignments...
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
  • 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,...

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

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

  • Programming Visual Basic 2010 Please post correct answer. Some of the questions I asked answered wrong...

    Programming Visual Basic 2010 Please post correct answer. Some of the questions I asked answered wrong before. Number Analysis: Create an application that reads the numbers from the file named NumberSet.txt .Your application should perform the following: 1) Display the total of the numbers 2) Display the average of the numbers 3) Display the highest number in the file. 4) Display the lowest number in the file. Attachment: NumberSet.txt http://s000.tinyupload.com/?file_id=00184765431250246674 I need full programming code with all the comments and...

  • C++ 3. Write a program that reads integers from a file, sums the values and calculates...

    C++ 3. Write a program that reads integers from a file, sums the values and calculates the average. a. Write a value-returning function that opens an input file named in File txt. You may "hard-code" the file name, i.e., you do not need to ask the user for the file name. The function should check the file state of the input file and return a value indicating success or failure. Main should check the returned value and if the file...

  • these numbers are from Random.txt file since i couldn't upload the file 42 468 335 501...

    these numbers are from Random.txt file since i couldn't upload the file 42 468 335 501 170 725 479 359 963 465 706 146 282 828 962 492 996 943 828 437 392 605 903 154 293 383 422 717 719 896 448 727 772 539 870 913 668 300 36 895 704 812 323 334 674 665 142 712 254 869 548 645 663 758 38 860 724 742 530 779 317 36 191 843 289 107 41 943...

  • C++ Programming Help Please! NOTE: Please READ All Steps very carefully. DO #10! (10 is based...

    C++ Programming Help Please! NOTE: Please READ All Steps very carefully. DO #10! (10 is based off of 9). Program Info:   #9. Write a program that reads in ten whole numbers and that outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the ten numbers just once...

  • C# Visual Studios HelloWorld For this program, you will need to sum the values of an...

    C# Visual Studios HelloWorld For this program, you will need to sum the values of an array and print the sum. A numbers array of integers will be provided for you in the program file. Since the array will already be populated with values, all your program needs to do is calculate the sum of all the values and print the output. Sample output Sum: 215

  • For this assignment you are to create two programming projects. The first should have a project...

    For this assignment you are to create two programming projects. The first should have a project directory with Lab02-2WriteNumbers and the second should have a project directory with Lab02-2ReadNumbers. Lab02-03WriteNumbers – Write a program that asks the user to enter five numbers. Use a double data type to hold the numbers. The program should create a file and save all five numbers to the file. Enter a number (1 of 5): 45 Enter a number (2 0f 5): 23 Enter...

  • import java.util.Scanner; // TASK #1 Add the file I/O import statement here /** This class reads...

    import java.util.Scanner; // TASK #1 Add the file I/O import statement here /** This class reads numbers from a file, calculates the mean and standard deviation, and writes the results to a file. */ public class StatsDemo { // TASK #1 Add the throws clause public static void main(String[] args) { double sum = 0; // The sum of the numbers int count = 0; // The number of numbers added double mean = 0; // The average of the...

  • the code is in visual basic 376 Chapter 6 Loop Structures Case Programming Assignments con Most...

    the code is in visual basic 376 Chapter 6 Loop Structures Case Programming Assignments con Most Rainfall in the USA USE CASE DEFINITION e Windows application opens with the heading "Most Rainfall in US - Kauai," a ListBox object that displays the monthly rainfall amounts, an i amounts in inches mage, and a Button object that allows the user to begin entering their rainfall 2. A menu bar displays the File menu, which has two menu items: Clear and Exit....

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