Server IP : 172.16.15.8 / Your IP : 18.223.125.236 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0705) : /home/vnlaughlin/../drsparks/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// CS 112 Computer Programming 1 // Assignment 9 // File: assignment9.cpp // Author: Heather Phelps // Instructor: Dr. Wang // Due: Mon. Nov 9, 2009 // Compile: g++ assignment9.cpp // Run: ./a.out < data9.txt > in9.txt // Goal: This program will read a file with unknown # of int, // calculate the avg for each line, and the total amount, and output // the results to a file. // #include <iostream> #include<iomanip> using namespace std; int main() { int data; int num; int sum; int line_num = 0; int total_sum; int total_num; float total_avg; cout << fixed << showpoint; cin >> data; while(cin) { // process each line line_num ++; num = 0; sum = 0; while( data != -1) { num ++; sum += data; cin >> data; } cout << setprecision(1); cout << "Line #: " << line_num << endl; cout << "# of int: " << num << endl; cout << "Sum of int: " << sum << endl; cout << "Average of the line: " << 1.0*sum/num << "\n"; total_num += num; total_sum += sum; cin >> data; } total_avg = 1.0*total_sum/total_num; cout << "The avg of all is: " << total_avg << endl; return 0; }