I have this program I'm working on for a small assignment The instructions will be posted. If you could give me any help it would be highly appreciated. I'm just completely stuck.
/*
This program reads ice cream survey data from the text file survey.txt
and writes a report on this to the text file report.txt. Each line of
survey.txt shows a flavor (in the first 20 columns) followed by a user's
rating of this flavor. There are 5 different flavors, so that the first
5 lines are the survey responses for the first user, the next 5 lines
are the responses for the second user, etc. The flavors are always
listed in the same order. We do not know in advance how many users
answered the survey. The report file simply shows each flavor and
the total of the ratings numbers for it.
*/
#include "flavor.h"
constint NumFlavors = 5;
typedef FlavorClass FlavorArrayType[NumFlavors];
// Fill in the function prototypes:
float WriteReport
ReadData
void main(void)
{
FlavorArrayType FlavorArray;
fstream InFile, OutFile;
// One can assign one object into another of the same type PROVIDED
// all of the data resides inside of the object:
FlavorArray[0] = FlavorClass("vanilla");
FlavorArray[1] = FlavorClass("chocolate");
FlavorArray[2] = FlavorClass("strawberry");
FlavorArray[3] = FlavorClass("pralines and cream");
FlavorArray[4] = FlavorClass("blueberry");
//open the survey.txt file for reading
InFile.open("survey.txt");
if (InFile.fail())
{
cout<< "The File did not open, exiting program." << endl;
exit(1);
}
ReadData(InFile, FlavorArray); //while/ fail loop
// close that filestream
InFile.close()
{
cout<< "Closing file." << endl;
}
//Open the report.txt file for writing
OutFile.open("report.txt")
if (OutFile.fail())
{
cout<< "The File did not open, Exiting program." << endl;
exit(1);
}
WriteReport(OutFile, FlavorArray); // print array, maybe use loop
// close that filestream
Outfile.close()
{
cout<< "closing file." << endl;
}
}
// Put the code for the WriteReport and ReadData functions here.
#include <iostream>
#include <fstream>
#include <cstdlib> // You may be able to remove this one. Try it and see.
usingnamespace std;
constint StringMax = 21; // holds 20 characters and a NULL
typedefchar ShortString[StringMax];
class FlavorClass
{
private:
ShortString Name;
int Total;
public:
FlavorClass(ShortString InitialName = "", int InitialTotal = 0);
void SetName(ShortString FlavorName);
void GetName(ShortString FlavorName) const;
int GetTotal(void) const;
void AddToTotal(int Increment);
};
Flavor: vanilla Total rating: 24
Flavor: chocolate Total rating: 14
Flavor: strawberry Total rating: 20
Flavor: pralines and cream Total rating: 25
Flavor: blueberry Total rating: 18
If you guys could give me any help or feed back I would really appreciated it. I'm just completely stuck on this one.
I just cant get it to compile. Where there are comments marked off at is what I'm suppose to do. I some of it. The comment at the top of the .cpp are my instructions I'm just lost. I believe its a giant survey. I need to use Filo IO and an array. It all needs to be using objects.
It's considered objects and classes. would it help if I found a webpage on it to explain it a little better? I just have to use Filo IO and classes to get this program to compile and read and write to a txt file.
If your compiler is giving you errors, post those errors. You need to provide us with more information that we can work with. I assume you've been provided a skeleton program and you need to finish it?
The issue is there is errors because I'm having trouble finishing the program where ever there are comments is where I have to add my own code. so my current code that I added could be wrong