Reference no: EM13938177
Can you find a bug in this program and then fix it so that it won't have an infinite loop?
#include <iostream>
#include <fstream>
using namespace std;
void CalculateAvgScore(ifstream &fIn,ofstream &fOut);
int main(int argc, char *argv[])
{
ifstream fin;
ofstream fout;
char inFileName[20],outFileName[20];
cout << "Enter the name of an existing text file: ";
cin>>inFileName;
cout << "Enter a name for output text file: ";
cin>>outFileName;
fin.open(inFileName,fstream::in);//open the input file
fout.open(outFileName,fstream::out);//open the ouuput file
CalculateAvgScore(fin,fout);//add one more field avgscore to the output file
fin.close();//close the input file
fout.close();//close the output file
system ("PAUSE");
return 0;
}
void CalculateAvgScore(ifstream &fIn,ofstream &fOut)
{
while (!fIn.eof())
{
char firstName[30],lastName[30];
int Scores[10]={0};
int totalScore=0;
double avgScore=0;
fIn>>lastName;//read lasttname
fIn>>firstName;//read firstname
if (lastName[0]=='') continue;//skip empty lines
for (int i=0;i<10;i++)
{
fIn >> Scores[i];//read score one by one
totalScore += Scores[i];
}
avgScore = (double)totalScore / 10;//calculate avg score
fOut << lastName;//write lastname
fOut << " ";//write one space
fOut << firstName;//write firstname
fOut << " ";
for (int j=0;j<10;j++)
{
fOut << Scores[j];//write score one by one
fOut << " ";
}
fOut << avgScore;//write avg score
fOut << "n";//write one change line character
}
}
Attachment:- consuelo_charlton_assignment5.09.zip
Analyse the threat or opportunity
: Describe any biases that are relevant and need to be avoidedEvaluate the financial impacts of the decision (or of not making the decision) in terms of costs, revenue and/or service levels
|
Elements of a potential wbs
: Q1: Level 1 WBS Elements With reference to the referenced example job drawings list at least 5 Level 1 Elements of a potential WBS. Q2: Level 2 WBS Headings Select 5 of the Level 1 Elements from Q1 and list potential Level 2 Headings under each. ..
|
Prepare the journal entry to record the purchase
: Prepare the journal entry to record the purchase. By how much did this purchase increase or decrease the excess of current assets over current liabilities?
|
Investment where you receive a cashflow
: Consider an investment where you receive a cashflow of +$400,000 per year for the first 5 years (times 1,2,3,4,5) and then $300,000 per year for the next 5 years (times 6-10), then $200,000 per year for the next 5 years (times 11-15) and then $100..
|
Can you find a bug in this program
: Can you find a bug in this program and then fix it so that it won't have an infinite loop?
|
Understanding or analysing the knowledge situation
: What are the possible models for understanding or analysing the knowledge situation. What is the knowledge or intellectual capital that needs to be managed or process
|
Why are vegetarians more efficient at saving energy
: Why are vegetarians more efficient at saving energy and food resources? Would our food problems be solved if everyone chose a vegetarian diet? Why or why not?
|
What is each years working capital movement
: Working capital values for accounts payable and inventory at the beginning of each year are to be calculated by applying the target working capital days to the appropriate forecast revenue and/or cost figures for the coming year.
|
Explain the network fundamental characteristics
: Write a 1-2 page paper that includes the following based on your chosen Local Organization: Explain the network's fundamental characteristics and components. Click the Assignment Files tab to submit your assignment
|