Question #38862

Read in the bowler info below from a file. Calculate the average for the 3 games. If the average is 100 or below, print out bad bowler, if the average is 101-200, print out good bowler, else print out great bowler. Make sure to label everything.

Use a if statement with no else, which means 3 if statements.

snoopy, 200, 230, 240

charlie brown, 76,24, 13

linus, 144, 122, 176
1

Expert's answer

2014-02-04T13:18:54-0500

//Answer on Question#38862 - Programming - C++


#include <iostream>
#include <conio.h>
#include <fstream>
#include <vector>
using namespace std;
class Bowler
{
public:
    char name[100];
    char surname[100];
    int fResult;
    int sResult;
    int tResult;
};
int main()
{
    char InputFilePath[256];
    cout<<"Enter the path to the file : "<<endl;
    cin>>InputFilePath;
    ifstream fileRead;
    fileRead.open(InputFilePath, ios::in);
    if(fileRead.fail())
    {
        cout<<"File doesn't exist. Please check the path again."<<endl;
        return 0;
    }
    vector <Bowler> Bowlers;
    while (!fileRead.eof())
    {
        Bowlers.clear();
        char koma;
        Bowler tmp;
        fileRead>>tmp.name;
        fileRead>>tmp.fResult;
        fileRead>>koma;
        fileRead>>tmp.sResult;
        fileRead>>koma;
        fileRead>>tmp.tResult;
        Bowlers.push_back(tmp);
        Bowler b;
        fileRead>>b.name;
        fileRead>>b.surname;
        fileRead>>b.fResult;
        fileRead>>koma;
        fileRead>>b.sResult;
        fileRead>>koma;
        fileRead>>b.tResult;
        Bowlers.push_back(b);
        Bowler c;
        fileRead>>c.name;
        fileRead>>c.fResult;
        fileRead>>koma;
        fileRead>>c.sResult;
        fileRead>>koma;
        fileRead>>c.tResult;
        Bowlers.push_back(c);
    }
    for(int i=0; i<Bowlers.size(); i++)
    {
        cout<<Bowlers[i].name<<" "<<Bowlers[i].surname<<" "<<Bowlers[i].fResult<<" "<<Bowlers[i].sResult<<" "<<Bowlers[i].tResult<<endl;
    }
    fileRead.close();
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS