I can't run this code, it gives an error. Can you fix the error and rewrite the code for me and can you also correct the average part? #include #include #include #include #include #include #define SIZE 50 using namespace std; int main() { int sum1 = 0, counter = 0; int num[SIZE]; string word; ifstream infileFirst; ifstream infileSecond; ofstream outfile; infileFirst.open("group1.txt"); infileSecond.open("group2.txt"); outfile.open("groupBar.out"); outfile << fixed << showpoint << setprecision(2); outfile << "\t\t\t\t Bar Graph " << endl; outfile << "Course \t Course"; int i; for (i = 0; i <= 100; i = i + 10) { outfile << setfill(' ') << right << setw(5) << i; } outfile << endl; outfile << "ID \t\t Average "; outfile << setfill('.') << "|" << right << setw(5) << "|" << right << setw(5) << "|" << right << setw(5) << "|" << right << setw(5) << "|" << right << setw(5) << "|" << right << setw(5) << "|" << right << setw(5) << "|" << right << setw(5) << "|" << right << setw(5) << "|" << right << setw(5) << "|" << right << endl; infileFirst >> word; int number; double avg; string txt1[50]; string txt2[50]; string star =""; double avg1[50]; double avg2[50]; int sum = 0, k = 0, numberCounter = 0; while (!infileFirst.eof()) { infileFirst >> number; if (number == -999) { avg = double(sum) / numberCounter; avg1[k] = avg; for (int i = 0; i < avg/2; i++) { star += "*"; } txt1[k++] = word + " \t" + to_string(avg)+ "\t" + star + "\n"; infileFirst >> word; star = ""; sum = 0, numberCounter = 0; continue; } numberCounter++; sum += number; } sum = 0, numberCounter = 0, k=0; infileSecond >> word; outfile << fixed << showpoint << setprecision(2); while (!infileSecond.eof()) { infileSecond >> number; if (number == -999) { avg = (double(sum) / numberCounter); avg2[k] = avg; for (int i = 0; i < avg / 2; i++) { star += "#"; } txt2[k++] =" \t\t" + to_string(avg) + "\t" + star + "\n"; infileSecond >> word; star = ""; sum = 0, numberCounter = 0; continue; } numberCounter++; sum += number; } for ( i = 0; i < 5; i++) { outfile << txt1[i] << txt2[i]; } outfile << endl; outfile << "Group 1 -- ****" << endl; outfile << "Group 2 -- ****" << endl; double result1 = 0.0; for (i = 0; i < 10; i++) { result1 = (avg1[i] = +avg)/ i; } outfile << "Avg for group 1: " << result1 << endl;; double result2 = 0.0; for (i = 0; i < 10; i++) { result2 = (avg1[i] = +avg); } outfile << "Avg for group 1: " << result2; system("pause"); return 0; }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I can't run this code, it gives an error. Can you fix the error and rewrite the code for me and can you also correct the average part?

#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<iomanip>
#include<string>
#include<cctype>

#define SIZE 50

using namespace std;

int main()
{
int sum1 = 0, counter = 0;

int num[SIZE];

string word;
ifstream infileFirst;
ifstream infileSecond;
ofstream outfile;

infileFirst.open("group1.txt");
infileSecond.open("group2.txt");

outfile.open("groupBar.out");

outfile << fixed << showpoint << setprecision(2);

outfile << "\t\t\t\t Bar Graph " << endl;

outfile << "Course \t Course";

int i;
for (i = 0; i <= 100; i = i + 10)
{
outfile << setfill(' ') << right << setw(5) << i;
}
outfile << endl;

outfile << "ID \t\t Average ";

outfile << setfill('.') << "|" << right << setw(5) << "|" << right << setw(5) << "|" << right << setw(5) << "|" << right << setw(5) << "|" << right << setw(5) << "|" << right << setw(5) << "|" << right << setw(5) << "|" << right << setw(5) << "|" << right << setw(5) << "|" << right << setw(5) << "|" << right << endl;

infileFirst >> word;

int number;

double avg;
string txt1[50];
string txt2[50];
string star ="";
double avg1[50];
double avg2[50];
int sum = 0, k = 0, numberCounter = 0;

while (!infileFirst.eof())
{
infileFirst >> number;
if (number == -999)
{
avg = double(sum) / numberCounter;
avg1[k] = avg;
for (int i = 0; i < avg/2; i++)
{
star += "*";
}
txt1[k++] = word + " \t" + to_string(avg)+ "\t" + star + "\n";
infileFirst >> word;
star = "";
sum = 0, numberCounter = 0;
continue;
}

numberCounter++;
sum += number;
}

sum = 0, numberCounter = 0, k=0;
infileSecond >> word;
outfile << fixed << showpoint << setprecision(2);
while (!infileSecond.eof())
{
infileSecond >> number;
if (number == -999)
{
avg = (double(sum) / numberCounter);
avg2[k] = avg;
for (int i = 0; i < avg / 2; i++)
{
star += "#";
}
txt2[k++] =" \t\t" + to_string(avg) + "\t" + star + "\n";
infileSecond >> word;
star = "";
sum = 0, numberCounter = 0;
continue;
}
numberCounter++;
sum += number;
}

for ( i = 0; i < 5; i++)
{
outfile << txt1[i] << txt2[i];
}

outfile << endl;
outfile << "Group 1 -- ****" << endl;
outfile << "Group 2 -- ****" << endl;

double result1 = 0.0;
for (i = 0; i < 10; i++)
{
result1 = (avg1[i] = +avg)/ i;
}
outfile << "Avg for group 1: " << result1 << endl;;

double result2 = 0.0;
for (i = 0; i < 10; i++)
{
result2 = (avg1[i] = +avg);
}
outfile << "Avg for group 1: " << result2;


system("pause");
return 0;
}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY