Object oriented help

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* 

   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"

const int 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.


Then here is my header file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <fstream>
#include <cstdlib>  // You may be able to remove this one.  Try it and see.
using namespace std;

const int StringMax = 21;   // holds 20 characters and a NULL

typedef char 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);
   };


Here is my survey.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
vanilla             8
chocolate           2
strawberry          9
pralines_and_cream  10
blueberry           7
vanilla             10
chocolate           8
strawberry          5
pralines_and_cream  6
blueberry           3
vanilla             6
chocolate           4
strawberry          6
pralines_and_cream  9
blueberry           8


Lastly this is my report.txt file

1
2
3
4
5
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.
closed account (zb0S216C)
atown282 wrote:
"I'm just completely stuck on this one."

...and so are we. What's your problem?

Wazzak
Last edited on
You should not expect us to seek errors in your code. Post your problem or any compile errors you have.
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.
I could help but till now I do not know what is "object oriented help".:)
You are really confusing yourself with all those typedefs.
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?
 
void main(void)
makes me cringe. Main should never be void, instead it should return an int at the end of the program.
Of course it doesn't compile. You need to terminate each line with a ;

Like lines 54, 70, 61, 22

Line 24 doesn't make sense at all. You have to write the whole prototype of the function. I.e. parameter and return type.

And don't forget the semicolon!

Do you think the braces on line 55/57 and 71/73 have a special meaning? No they don't.
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
Topic archived. No new replies allowed.