Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with a C++ program. The program instructions are as follows: 1. Impl

ID: 3668928 • Letter: I

Question

I need help with a C++ program.

The program instructions are as follows:

1. Implement a class named Age. Class Age has the method ReadFile to read the file input.txt. The values in the file contains in each line: first name, last name, age.

2. Create in the Class Age a method named CatchAge used to extract only the age from each line from the input.txt file.

3. In Class Age, create the method ReckonAge, used to get the sum and the average of all the ages found in the input file.

4. In Class Age, creathe the method Output used to print on the screen and also into the file output.txt each of the ages found in the input.txt and also the total sum of all ages and average age. Then make the greetings: (average <= 50) "YOUNG GROUP", (average >50 and <100) "GOOD AGE GROUP", (average >= 100) "TELL THE SECRET".

*Declare struct locally and pass it as argument for pointers, declare it in main or in API.

So far here is what I have:

#include <iostream>
#include <fstream>

using namespace std;

class Age
{
public:

readFile(string firstName, string lastName, int age)
{
ifstream reader;
reader.open("input.txt");
reader >> firstName >> lastName >> age;
reader.close();
}

catchAge(int age)
{

}

reckonAge(int sum, int average)
{

}

output()
{
ofstream writer;
writer.open("output.txt")
writer <<

int average;

if (average <= 50)
{
cout << "YOUNG GROUP" << endl;
}
else if (average > 50 && average < 100)
{
cout << "GOOD AGE GROUP" << endl;
}
else
{
cout << "TELL THE SECRET" << endl;
}

}

};

int main()
{

return 0;
}

Input.txt contain the following:

Also this sample code was provided:

Explanation / Answer

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


using namespace std;

#define MAX 1000

struct InAge{
int sum;
double avg;
};

class Age
{
int AgeList[MAX];
int countAge;

public:

//constructor
Age()
{
countAge = 0;
}

bool isblank(const std::string& s)
{    //True if s is empty or only contains space and/or TABs.
      return s.find_first_not_of(" ")==std::string::npos;
}

void readFile (string filename)
{
    ifstream file(filename.c_str());
    string line;
    int count;

    // getline is true for as long as end of file is not reached
    while(std::getline (file,line)){
        if (! isblank(line)){
            // now the variable string "line" contains the line content
            AgeList[countAge++] = catchAge(line);
        }
    }
    file.close();
}

int catchAge(string line)
{
    string Eachage = line.substr(line.find(" ",line.find(" ")+1)+1);
    return atoi(Eachage.c_str());
}

struct InAge reckonAge()
{
    int i;
    int sum;
    double avg;
    struct InAge result;

    for(i=0;i<countAge;i++)
      sum += AgeList[i];

    result.sum = sum;
    result.avg = sum*1.0/countAge;
    return result;

}

void output()
{
    ofstream writer;
    writer.open("output.txt");
    int i;
    double average;
    struct InAge temp = reckonAge();

    for(i=0;i<countAge;i++)
    {
      cout<<"Age "<<i+1<<": "<<AgeList[i]<<endl;
      writer<<"Age "<<i+1<<": "<<AgeList[i]<<endl;
    }
    cout<<"Sum = "<<temp.sum<<endl;
    writer<<"Sum = "<<temp.sum<<endl;

    average = temp.avg;
    cout<<"Average = "<<average<<endl;
    writer<<"Average = "<<average<<endl;

    if (average <= 50)
    {
    cout << "YOUNG GROUP" << endl;
    writer << "YOUNG GROUP" << endl;
    }
    else if (average > 50 && average < 100)
    {
    cout << "GOOD AGE GROUP" << endl;
    writer << "GOOD AGE GROUP" << endl;
    }
    else
    {
    cout << "TELL THE SECRET" << endl;
    writer << "TELL THE SECRET" << endl;
    }

}

};

int main()
{
Age temp;
temp.readFile("input.txt");
temp.output();
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote