Question

In: Computer Science

Answer in C++ language please** I got stuck. How do I find the Overall Average,Overall Highest...

Answer in C++ language please**

I got stuck. How do I find the Overall Average,Overall Highest number, and the Overall Lowest Number after all of this??

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

const int ALIASFILE_LINE_COUNT =16;
const float USERBONUSLEVEL = 75.09;
const float USERAWARDLEVEL = 80.72;
const int USERBONUS = 5;
const int USERAWARD = 8;
void selectionSortAsc( double list[], int length);


int main()
{cout <<"\n\nproject 3 template,.. \n ,...includes global constants for project.\n"<<endl;
//1. declare and initialize your variables.
//2. configure and test the file I/O
fstream fileName;
string inputFile;
ofstream outFile;
cout<<"Enter File Name ";
cin>>inputFile;
fileName.open(inputFile.c_str());
if(!fileName)
{
cout <<"\n\n\tINPUT FILE ERROR! Exiting.\n\n";
return 1;
}

// 3. GET RATE - read & display alias.txt file to verify.
string info1,info2,info3,info4,info5,info6,info8,info9,info10,info11,info12,info13,info14,info15,info16,info17,info18;
double rate;
string a;
string b;
const int size = 50;
while ( fileName )
{
if (fileName == false)
cout<<"Could not open the input file"<<endl;

// read another record
getline(fileName,info1);
getline(fileName,info2);
getline(fileName,info3);
getline(fileName,info4);
getline(fileName,info5);
getline(fileName,info6);
fileName>>a>>b>>rate;
getline(fileName,info8);
getline(fileName,info9);
getline(fileName,info10);
getline(fileName,info11);
getline(fileName,info12);
getline(fileName,info13);
getline(fileName,info14);
getline(fileName,info15);
getline(fileName,info16);
getline(fileName,info17);
getline(fileName,info18);
}
// display
outFile<<info1<<endl;
outFile<<info2<<endl;
outFile<<info3<<endl;
outFile<<info4<<endl;
outFile<<info5<<endl;
outFile<<info6<<endl;
outFile<<a<<b<<rate<<endl;
outFile<<info8<<endl;
outFile<<info9<<endl;
outFile<<info10<<endl;
outFile<<info11<<endl;
outFile<<info12<<endl;
outFile<<info13<<endl;
outFile<<info14<<endl;
outFile<<info15<<endl;
outFile<<info16<<endl;
outFile<<info17<<endl;
outFile<<info18<<endl;

// 4. load the arrays with the values
// declaring 2-D array of 4 rows and 7 columns

double A[4][7];

// opening files
// opening files
cout<<"_____________________________________________________"<<endl;
{
ifstream inFile;
inFile.open("update_fullOfGrace.txt");
if(inFile.fail() ){
cerr << "\n\nERROR!! Could NOT open input file!!\n\n";
return 1;
}
int row = 0;
while(row < 4){
int col = 0;
while(col < 7){
inFile>>A[row][col];
col++;
}
row++;
}
double values[7];

for(int i=0; i<4; i++){

for(int j=0; j<7; j++){
values[j]=A[i][j];

}

selectionSortAsc(values,7);
for(int k=0; k<7; k++){
A[i][k]=values[k];

}
}
for(int i=0; i<4; i++){
for(int j=0; j<7; j++)
cout<<A[i][j]<<" ";
cout<<endl;

}
cout<<"_____________________________________________________"<<endl;
for(int i=0; i<4; i++){
double sum = 0;
for(int j=0; j<7; j++)
sum = sum + A[i][j];

cout<<"Average for Week "<<(i+1)<<" is: "<<(sum/7.0)<<endl;
cout<<endl;
}


cout<<"_____________________________________________________"<<endl;

// 5. calculate averages for each week, and all weeks

// 6. calculate total average of all four weeks
// 7. find high values for each week.
double high1;
double high2;
double high3;
double high4;
double low1;
double low2;
double low3;
double low4;
high1=100;
high2=100;
high3=95;
high4=99;
low1=9.8;
low2=6.9;
low3=6.9;
low4=5.61;

cout<<" High Values "<<endl;
cout<<"Week 1: "<<high1<<endl;
cout<<"Week 2: "<<high2<<endl;
cout<<"Week 3: "<<high3<<endl;
cout<<"Week 4: "<<high4<<endl;

// 8. find low values for each week.
cout<<" Low Values "<<endl;
cout<<"Week 1: "<<low1<<endl;
cout<<"Week 2: "<<low2<<endl;
cout<<"Week 3: "<<low3<<endl;
cout<<"Week 4: "<<low4<<endl;

}


// 10. update the current rate
rate+=USERBONUS
if(overall_avg> USERBONUSLEVEL)
{
rate+= USERBONUS;
}
if(rate>USERBONUSLEVEL&&low!=0)
{
rate+=USERAWARD;
}
// 11. update the alias file with the new rate.
//12. out to screen
cout <<"\n___________________________________________________________\n";
cout<<setw(14);
cout<<"OVERALL HIGH = 100"
cout <<"\n___________________________________________________________\n";

/// 13. close out and exit gracefully,....

cout<<"\n\n\n";
return 0;
}
// 9. sort it all out.
void selectionSortAsc( double list[], int length){
int index=0, smallestIndex=0, minIndex=0;
double temp;
for (index = 0; index < length ; index++){
/// Step a
//smallestIndex = index;
for (minIndex = 0; minIndex < length-1; minIndex++)
{
if (list[minIndex] > list[minIndex + 1])
// smallestIndex = minIndex;
/// Step b
{
temp = list[minIndex];
list[minIndex] = list[minIndex + 1];
list[minIndex + 1] = temp;
}
}
}
}

Solutions

Expert Solution

Updated your code as required: please check below:


#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
const int ALIASFILE_LINE_COUNT = 16;
const float USERBONUSLEVEL = 75.09;
const float USERAWARDLEVEL = 80.72;
const int USERBONUS = 5;
const int USERAWARD = 8;
void selectionSortAsc(double list[], int length);

int main()
{
cout << "\n\nproject 3 template,.. \n ,...includes global constants for project.\n" << endl;
//1. declare and initialize your variables.
//2. configure and test the file I/O
fstream fileName;
string inputFile;
ofstream outFile;
cout << "Enter File Name ";
cin >> inputFile;
fileName.open(inputFile.c_str());
if (!fileName) {
cout << "\n\n\tINPUT FILE ERROR! Exiting.\n\n";
return 1;
}
// 3. GET RATE - read & display alias.txt file to verify.
string info1, info2, info3, info4, info5, info6, info8, info9, info10, info11, info12, info13, info14, info15, info16, info17, info18;
double rate;
string a;
string b;
const int size = 50;
while (fileName) {
if (fileName == false)
cout << "Could not open the input file" << endl;
// read another record
getline(fileName, info1);
getline(fileName, info2);
getline(fileName, info3);
getline(fileName, info4);
getline(fileName, info5);
getline(fileName, info6);
fileName >> a >> b >> rate;
getline(fileName, info8);
getline(fileName, info9);
getline(fileName, info10);
getline(fileName, info11);
getline(fileName, info12);
getline(fileName, info13);
getline(fileName, info14);
getline(fileName, info15);
getline(fileName, info16);
getline(fileName, info17);
getline(fileName, info18);
}
// display
outFile << info1 << endl;
outFile << info2 << endl;
outFile << info3 << endl;
outFile << info4 << endl;
outFile << info5 << endl;
outFile << info6 << endl;
outFile << a << b << rate << endl;
outFile << info8 << endl;
outFile << info9 << endl;
outFile << info10 << endl;
outFile << info11 << endl;
outFile << info12 << endl;
outFile << info13 << endl;
outFile << info14 << endl;
outFile << info15 << endl;
outFile << info16 << endl;
outFile << info17 << endl;
outFile << info18 << endl;
// 4. load the arrays with the values
// declaring 2-D array of 4 rows and 7 columns
double A[4][7];
// opening files
// opening files
cout << "_____________________________________________________" << endl;
{
ifstream inFile;
inFile.open("update_fullOfGrace.txt");
if (inFile.fail()) {
cerr << "\n\nERROR!! Could NOT open input file!!\n\n";
return 1;
}
int row = 0;
while (row < 4) {
int col = 0;
while (col < 7) {
inFile >> A[row][col];
col++;
}
row++;
}
double values[7];
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 7; j++) {
values[j] = A[i][j];
}
selectionSortAsc(values, 7);
for (int k = 0; k < 7; k++) {
A[i][k] = values[k];
}
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 7; j++)
cout << A[i][j] << " ";
cout << endl;
}
cout << "_____________________________________________________" << endl;
      
      
       double high[4], low[4], avg[4];
      
for (int i = 0; i < 4; i++) {
double sum = 0;
           high[i] = A[i][0]; // make high to first element
           low[i] = A[i][0]; // make low to first element
for (int j = 0; j < 7; j++) {
sum = sum + A[i][j];
               // if new high is found
               if(A[i][j] > high[i]) {
                   high[i] = A[i][j];
               }
               // if new low is found
               if(A[i][j] < low[i]) {
                   low[i] = A[i][j];
               }
           }
           avg[i] = (sum / 7.0);
cout << "Average for Week " << (i + 1) << " is: " << (sum / 7.0) << endl;
cout << endl;
}

cout << "_____________________________________________________" << endl;

// 5. calculate averages for each week, and all weeks
// 6. calculate total average of all four weeks
// 7. find high values for each week.
  
       // find overall average
       double totalAverage = (avg[0] + avg[1] + avg[2] + avg[3])/4;
      
cout << " High Values " << endl;
cout << "Week 1: " << high[0] << endl;
cout << "Week 2: " << high[1]<< endl;
cout << "Week 3: " << high[2] << endl;
cout << "Week 4: " << high[3] << endl;
// 8. find low values for each week.
cout << " Low Values " << endl;
cout << "Week 1: " << low[0] << endl;
cout << "Week 2: " << low[1] << endl;
cout << "Week 3: " << low[2] << endl;
cout << "Week 4: " << low[3] << endl;
      
}

// 10. update the current rate
rate += USERBONUS if (overall_avg > USERBONUSLEVEL)
{
rate += USERBONUS;
}
if (rate > USERBONUSLEVEL && low != 0) {
rate += USERAWARD;
}
// 11. update the alias file with the new rate.
//12. out to screen
cout << "\n___________________________________________________________\n";
cout << setw(14);
cout << "OVERALL HIGH = 100" cout << "\n___________________________________________________________\n";

/// 13. close out and exit gracefully,....
cout << "\n\n\n";
return 0;
}
// 9. sort it all out.
void selectionSortAsc(double list[], int length)
{
int index = 0, smallestIndex = 0, minIndex = 0;
double temp;
for (index = 0; index < length; index++) {
/// Step a
//smallestIndex = index;
for (minIndex = 0; minIndex < length - 1; minIndex++) {
if (list[minIndex] > list[minIndex + 1])
// smallestIndex = minIndex;
/// Step b
{
temp = list[minIndex];
list[minIndex] = list[minIndex + 1];
list[minIndex + 1] = temp;
}
}
}
}


Related Solutions

Hello this is for C++ language. I am currently stuck on creating my api for Day...
Hello this is for C++ language. I am currently stuck on creating my api for Day Trading Stocks. as follows I need an api for *//Function Signature * * parameter: * * Return Value: ** *// Write the following function taking in an integer vector (vector &prices) consisting of all prices, in chronological order, for an hypothetical instrument. Your function recommends the maximum profit an investor can make by placing AT MOST one buy and one sell order in the...
Please show how you got the answers so that I can learn how to do this!...
Please show how you got the answers so that I can learn how to do this! 200.00mL of 2.00 M solution of a weak acid is mixed with 300.00 mL of a 2.00 M solution containing its conjugate base. 50.000 g of the slightly soluble salt silver acetate (AgC2H3O2) is added to this buffer solution. After thorough mixing, the solution is assumed to be saturated. To determine the amount of the solid which remains undissolved, the solution is filtered, and...
How do I calculate the rate law constant and find the overall rate law?
How do I calculate the rate law constant and find the overall rate law?
Please do not just give the answer. Please also explain how you got them. Thanks! 1....
Please do not just give the answer. Please also explain how you got them. Thanks! 1. Which of the following is not a valid method of applying LCNRV: A. logical categories of inventory (i.e. product line) B. the entire inventory C. inventory items to be sold within the next year D. individual inventory items E. None of the answer choices are correct 2. Which of the following would not require the company to account for the change retrospectively? A. From...
Hello! I am stuck on only B-1 Recession EPS - I got everything else and I...
Hello! I am stuck on only B-1 Recession EPS - I got everything else and I cannot figure out what I'm doing wrong - I keep getting $4.81, but it's incorrect and I don't know why. Can you help? I pasted my numbers below the question. Sunrise, Inc., has no debt outstanding and a total market value of $240,900. Earnings before interest and taxes, EBIT, are projected to be $40,000 if economic conditions are normal. If there is strong expansion...
(Please show work so I can understand how you got to the answer - Thank you...
(Please show work so I can understand how you got to the answer - Thank you very much ) Via Gelato is a popular neighborhood gelato shop. The company has provided the following data concerning its operations: Fixed Element per Month Variable Element per Liter Actual Total for June Revenue $ 13.00 $ 72,540 Raw materials $ 4.75 $ 30,330 Wages $ 5,700 $ 1.50 $ 14,560 Utilities $ 1,730 $ 0.30 $ 3,800 Rent $ 2,700 $ 2,700 Insurance...
I am stuck on approaching the answer to this question, and most of the answer that...
I am stuck on approaching the answer to this question, and most of the answer that I have found online and on Chegg are do not make any sense regarding this question. What would be a good interpretation of what this question is asking regarding the GDP? "Think about the increases since 2001 in spending for the Department of Homeland Security and the wars in Afghanistan and Iraq. These increases represent government expenditures that have increased GDP. Explain whether you...
while doing FPLC my dye(MHI-148) got stuck in column? . so how can i clean the...
while doing FPLC my dye(MHI-148) got stuck in column? . so how can i clean the column efficient? and why some particle stuck in column?
(In C language) Given a two-dimensional char array, how do I encode it into a one...
(In C language) Given a two-dimensional char array, how do I encode it into a one dimensional integer array? For example: char arr [8][8] = {{1,1,1,1,1,1,1,1}, {1,0,0,0,1,0,0,1}, {1,0,1,0,1,1,0,1}, {1,0,1,0,0,0,0,1}, {1,0,1,1,1,1,0,1}, {1,0,0,0,0,0,0,1}, {1,0,1,0,1,0,1,1}, {1,1,1,1,1,1,1,1}} into int arr2 [8] I know this problem requires bit-shifting but I am unsure how. It also needs to be as efficient as possible. Thanks!
Please show how you got the answer. I am trying to learn! Drilling Experts, Inc. Drilling...
Please show how you got the answer. I am trying to learn! Drilling Experts, Inc. Drilling Experts, Inc. (DEI) finds and develops oil properties and then sells the successful ones to major oil refining companies. DEI is now considering a new potential field, and its geologists have developed the following data, in thousands of dollars. t = 0. A $400 feasibility study would be conducted at t = 0. The results of this study would determine if the company should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT