Newb Having Trouble Object Class Functions

Hi All,

I am taking a basic programming course at school this semester, and we are currently learning basic C++. My assignment is to write a program that has two object classes. The program I have written (or at least attempted to write) is a program which asks the user to enter a number (1-7) corresponding to the day of the week. Once the day of the week is established, I would like the program to output a drink special, the drink price, a food special, and the food price. I also have a line for "total_amount" where I give a discount if they order both the drink and food special. I am basing this code off similar code from my textbook. I am using Bloodshed Dev-C++ to compile - if that matters.

So:
Object 1 - DAY
Object 2 - DRINK
Object 3 - FOOD

Here is the main program (Specials.cpp)
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
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream.h>
#include<string.h>
#include<day.h>
#include<drink.h>
#include<food.h>

main()
{
      int day_no;
      printf("Please enter the day number to see the specials. \n");
      printf("Enter 1 for Sunday \n");
      printf("Enter 2 for Monday \n");
      printf("Enter 3 for Tuesday \n");
      printf("Enter 4 for Wednesday \n");
      printf("Enter 5 for Thursday \n");
      printf("Enter 6 for Friday \n");
      printf("Enter 7 for Saturday \n");
      cin>> day_no;
      
      
      printf("\n");
      printf("\n");
      printf("\n");
      printf("Welcome to Atlantica Restaurant \n");
      
DAY Day;
Day.InitDay(day_no);
      
      printf("Here are the specials for %s \n", Day.Returnday_name());
      
DRINK Drink;
Drink.InitDrink(Day.Returndrink_number);
                                      
      printf("Drink Special:   %s \n", Drink.Returndrink_name());     
      printf("   Price:   $%3.2f \n", Drink.Returndrink_price());

FOOD Food;
Food.InitFood(Day.Returnfood_number);

      printf("Entree Special:   %s \n", Food.Returnfood_name());
      printf("   Price:   $%3.2f \n", Food.Returnfood_price());

      printf("Purchase both specials and pay just $%u total! \n", Day.Returntotal_amount());
      printf(" \n");
}


Here is day.h
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
78
79
class DAY
{
      private:
              
              int day_number;
              char day_name[10];
              int drink_number;
              int food_number;
              int total_amount;
              
      public:
             DAY()
             {
              };

void InitDay(int Day_no)
{
     day_number=Day_no;
     
     if (day_number==1)
     { strcpy(day_name, "Sunday ");
     drink_number=11;
     food_number=21;
     total_amount=15;
     }
     
     
     if (day_number==2)
     { strcpy(day_name, "Monday ");
     drink_number=12;
     food_number=22;
     total_amount=25;
     }
     
     if (day_number==3)
     { strcpy(day_name, "Tuesday ");
     drink_number=13;
     food_number=23;
     total_amount=15;
     }
     
     if (day_number==4)
     { strcpy(day_name, "Wednesday ");
     drink_number=14;
     food_number=24;
     total_amount=17;
     }
     
     if (day_number==5)
     { strcpy(day_name, "Thursday ");
     drink_number=15;
     food_number=25;
     total_amount=28;
     }
     
     if (day_number==6)
     { strcpy(day_name, "Friday ");
     drink_number=16;
     food_number=26;
     total_amount=24;
     }
     
     if (day_number==7)
     { strcpy(day_name, "Saturday ");
     drink_number=17;
     food_number=27;
     total_amount=16;
     }
}

char *Returnday_name(){return day_name;};

int Returndrink_number(){return drink_number;};

int Returnfood_number(){return food_number;};

int Returntotal_amount(){return total_amount;};

};


Here is drink.h
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
class DRINK
{
      private:
              
              int drink_number;
              char drink_name[50];
              float drink_price;
              
      public:
             DRINK()
             {
              };

void InitDrink(int drink_no) {
     drink_number=Drink_no;
     
     if (drink_number==11)
     { strcpy(drink_name, "Ketel One Cosmopolitan ");
     drink_price=10.99;
     }
     
     if (drink_number==12)
     { strcpy(drink_name, "2008 Twenty Rows Napa Cabernet ");
     drink_price=11.99;
     }
  
     if (drink_number==13)
     { strcpy(drink_name, "Harpoon IPA ");
     drink_price=6.00;
     }

     if (drink_number==14)
     { strcpy(drink_name, "2009 Cameron Hughes Sauvignon Blanc ");
     drink_price=10.99;
     }
     
     if (drink_number==15)
     { strcpy(drink_name, "Hornitos Grand Gold Margerita ");
     drink_price=8.25;
     }
     
     if (drink_number==16)
     { strcpy(drink_name, "Knob Creek Bourbon Manhattan ");
     drink_price=9.99;
     }
     
     if (drink_number==17)
     { strcpy(drink_name, "Privateer Silver Mojito ");
     drink_price=9.50;
     }
}

char *Returndrink_name()
                      {return drink_name;};

float Returndrink_price()
                         {return drink_price;};

};


and lastly, here is food.h
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
class FOOD
{
      private:
              
              int food_number;
              char food_name[50];
              float food_price;
              
      public:
             FOOD()
             {
              };

void InitFood(int food_no) {
     food_number=food_no;
     
     if (food_number==21)
     { strcpy(food_name, "Carne Asada Quesadilla ");
     food_price=8.99;
     }
     
     if (food_number==22)
     { strcpy(food_name, "Lamb Cassoulet ");
     food_price=28.00;
     }
     
     if (food_number==23)
     { strcpy(food_name, "Beer Battered Fish & Chips ");
     food_price=12.99;
     }
     
     if (food_number==24)
     { strcpy(food_name, "Shrimp Scampi over Linguini ");
     food_price=11.99;
     }
     
     if (food_number==25)
     { strcpy(food_name, "Authentic Spanish Paella ");
     food_price=24.99;
     }
     
     if (food_number==26)
     { strcpy(food_name, "Memphis Style Baby Back Ribs ");
     food_price=18.49;
     }
     
     if (food_number==27)
     { strcpy(food_name, "Caribbean Spiced Seared Scallops ");
     food_price=22.99;
     }
     
     
}

char *Returnfood_name()
                      {return food_name;};

float Returnfood_price()
                         {return food_price;};

};


When I try to compile I get the following errors:

In file included from F:\MIS 212\Restaurant Specials Program\specials.cpp:7:
C:/Dev-Cpp/include/drink.h: In member function `void DRINK::InitDrink(int)':
C:/Dev-Cpp/include/drink.h:15: error: `Drink_no' undeclared (first use this function)
C:/Dev-Cpp/include/drink.h:15: error: (Each undeclared identifier is reported only once for each function it appears in.)

F:\MIS 212\Restaurant Specials Program\specials.cpp: In function `int main()':

F:\MIS 212\Restaurant Specials Program\specials.cpp:35: error: no matching function for call to `DRINK::InitDrink(<unknown type>)'
C:/Dev-Cpp/include/drink.h:14: note: candidates are: void DRINK::InitDrink(int)
F:\MIS 212\Restaurant Specials Program\specials.cpp:41: error: no matching function for call to `FOOD::InitFood(<unknown type>)'
C:/Dev-Cpp/include/food.h:14: note: candidates are: void FOOD::InitFood(int)

So I have been trying to mess around with the code for a while, and research different sites for a solution, but it seems I am having no luck. I am curious if the errors are caused by "day_no" being used by day.h, and not being accepted for use in food/drink.h files.

I am initializing drink.h based on drink_no, and I have not declared drink_no in drink.h before the void part. If I declare drink_no, should I put it in the public or private part? The same would be true of food_no I would assume. I am going to keep trying to fix this, but any and all help is greatly appreciated.

Also, in my text example - the code uses some sort of compound return command, such that instead of just saying (this is from the text):
"Order.ReturnOrder_Amount());"
it uses "Order.ReturnOrder_Amount()*Book.ReturnBook_Price());"
What does this combination do?

Thank you for your time.

Sincerely,
CW
Shameless Bump.
One error maybe.

1
2
3
4
//...
void InitDrink(int drink_no) {
     drink_number=Drink_no;     /// Drink_no should be drink_no 
//... 

One error maybe.


Ah thank you. I have corrected this, but am still having the same errors.
Also:

Drink.InitDrink(Day.Returndrink_number); // Should be Day.Returndrink_number()

Food.InitFood(Day.Returnfood_number); // Should be Day.Returnfood_number()

main() // Should be int main()

printf(/*...*/); // Why printf and not cout?
I have corrected that, and I now have the remaining errors upon compile:

C:\Users\Christian\Desktop\C++ Programs\specials.cpp: In function `int main()':
C:\Users\Christian\Desktop\C++ Programs\specials.cpp:35: error: no matching function for call to `DRINK::InitDrink(<unknown type>)'
C:/Dev-Cpp/include/drink.h:14: note: candidates are: void DRINK::InitDrink(int)
C:\Users\Christian\Desktop\C++ Programs\specials.cpp:41: error: no matching function for call to `FOOD::InitFood(<unknown type>)'
C:/Dev-Cpp/include/food.h:14: note: candidates are: void FOOD::InitFood(int)

These are obviously two very similar errors. One is for the food.h file, and one for the drink.h file. I have tried declaring different variables in each of those files, but this has made things worse.
Are you sure you corrected it to

Drink.InitDrink(Day.Returndrink_number()); // Parenthesis necessary!

Food.InitFood(Day.Returnfood_number()); // Parenthesis necessary!
?
Last edited on

long double main (44)
Also:

Drink.InitDrink(Day.Returndrink_number); // Should be Day.Returndrink_number()

Food.InitFood(Day.Returnfood_number); // Should be Day.Returnfood_number()

main() // Should be int main()

printf(/*...*/); // Why printf and not cout?


You, sir, are a genius! It runs, but the window does not stay open. Is there are way to keep the window open? THANK YOU THANK YOU THANK YOU THANK YOU!
Oh - I was using printf because that is what the text book uses.
Nvm, I was running the program instead of using the "Run to Cursor" option! You are the best! I am very happy to have this working! My brain was beginning to fry!
Topic archived. No new replies allowed.