Why wont my Main display data from my class?

Can anyone see what Im doing wrong when calling my fuctions in my class?

the program compiles it just stops displaying things to the screen after the welcome message section in the main.

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>

using namespace std;


class menuItemType 
{
public:
	menuItemType();
	~menuItemType();
	void accessData();
private:
	void getData(menuItemType item[], ofstream& outData);
	void showMenu(menuItemType item[], ofstream& outData);
	void printCheck (double& total, double& tax, double& totalF, ofstream& outData);
    string itemName;
    double itemCost;
};

menuItemType :: menuItemType()
{
	&menuItemType::getData; 
}
menuItemType :: ~menuItemType()
{
	&menuItemType::printCheck;
}
int main()
{

ofstream outData;
outData.open("OutMenu.txt");
				

cout<< "                  Welcome!                 " << endl;
cout<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
cout<< "  *To select an Item from the list below,  " << endl;
cout<< "just indicate the Item number for the item \n\n" << endl;
				

outData << "                  Welcome!                 " << endl;
outData << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
outData << "  *To select an Item from the list below,  " << endl;
outData<< "just indicate the Item number for the item \n\n" << endl;

menuItemType a;
a.accessData();



    system("pause");

    return 0;

}

void menuItemType :: getData(menuItemType item[], ofstream& outData)
{
    int i=0;
    ifstream inData;
    inData.open("InMenu.txt");
    cout << fixed << setprecision(2);
	outData << fixed << setprecision(2);


    while(!inData.eof()) 
	{
        inData >> item[i].itemName >> item[i].itemCost;
        ++i;
    }

}

void menuItemType :: showMenu(menuItemType item[],ofstream& outData) 
{
	int choice = 0;
    double total = 0.0, totalF = 0.0, tax = 0.0;
    char exit = 'y';
    int j = 1, z = 1, i = 1;

    //the Menu
    for (int i=0; i< 8; i++)
	{
        cout << j << ". " << setw(18) << left << item[i].itemName << "$" << setw(10) << item[i].itemCost << endl;
		outData << j << ". " << setw(18) << left << item[i].itemName << "$" << setw(10) << item[i].itemCost << endl;
		j++;
		
    }

    cout << endl;

    while(exit == 'y' || exit == 'Y')
	{

        cout << "Please Enter your Selection or 0 to Exit : ";
        cin >> choice;

        if(cin.fail()) 
		{
            cout << "~~~~~~~~~Invalid selection~~~~~~~~~" << endl;
            cin.clear();
            cin.ignore(1000,'\n');
        } 
		else if (choice==0) {break;}
            else 
			{
                choice--;
                total += (item[choice].itemCost);
                tax = (total * .05);
                totalF = total + tax;
                cout << endl;
				outData << endl;
            }
            cout << endl;
			outData << endl;

            cout << item[choice].itemName << " " << item[choice].itemCost << endl;
            cout << "======================================================" << endl;
            cout << "Do you want to continue (Y/N): ";
			outData << item[choice].itemName << " " << item[choice].itemCost << endl;
            outData << "======================================================" << endl;
            outData << "Do you want to continue (Y/N): ";
            cin >> exit;

        }
	printCheck(total, tax, totalF, outData);
}
void menuItemType :: accessData()
{
	showMenu();

}
void menuItemType ::  printCheck(double& total, double& tax, double& totalF, ofstream& outData)
 {
     cout << "\n\nThanks for Dinning With Us!" << endl;
	 cout << "<><><><><><><><><><><><><><>\n" << endl;
	 cout << "Customer Receipt            " << endl;
	 cout << "SubTotal:               $" << total <<endl;
	 cout << "Tax:                    $" << tax << endl;
	 cout << "                        -----" << endl;
	 cout << "Total:                  $" << totalF << endl;
	 cout << "Please Come Again!" << endl;

	 outData << "\n\nThanks for Dinning With Us!" << endl;
	 outData << "<><><><><><><><><><><><><><>\n" << endl;
	 outData << "Customer Receipt            " << endl;
	 outData << "SubTotal:               $" << total <<endl;
	 outData << "Tax:                    $" << tax << endl;
	 outData << "                        -----" << endl;
	 outData << "Total:                  $" << totalF << endl;
	 outData << "Please Come Again!" << endl;
 }

Last edited on
Line 133 doesn't look legitimate; showMenu() is supposed to take arguments but you aren't passing anything.
do you have any recomendations on how to fix that?
Well...you need to pass arguments to it. You designed the class/methods, so you should know what you need to be passing there.
I changed it to this and its still not working

1
2
3
4
5
void menuItemType :: accessData()
{
	&menuItemType::showMenu;

}
Heres my whole program as it is now

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>

using namespace std;


class menuItemType 
{
public:
	menuItemType();
	~menuItemType();
	void accessData();

public:
	string itemName;
    double itemCost;
	void getData(menuItemType item[], ofstream& outData);
	void showMenu(menuItemType item[], ofstream& outData);
	void printCheck (double& total, double& tax, double& totalF, ofstream& outData);

};

menuItemType :: menuItemType()
{
	&menuItemType::getData; 
}
menuItemType :: ~menuItemType()
{
	&menuItemType::printCheck;
}

void menuItemType :: accessData()
{
	&menuItemType::showMenu;

}

void menuItemType :: getData(menuItemType item[], ofstream& outData)
{
    int i=0;
    ifstream inData;
    inData.open("InMenu.txt");
    cout << fixed << setprecision(2);
	outData << fixed << setprecision(2);


    while(!inData.eof()) 
	{
        inData >> item[i].itemName >> item[i].itemCost;
        ++i;
    }

}

void menuItemType :: showMenu(menuItemType item[],ofstream& outData) 
{
	int choice = 0;
    double total = 0.0, totalF = 0.0, tax = 0.0;
    char exit = 'y';
    int j = 1, z = 1, i = 1;

    for (int i=0; i< 8; i++)
	{
        cout << j << ". " << setw(18) << left << item[i].itemName << "$" << setw(10) << item[i].itemCost << endl;
		outData << j << ". " << setw(18) << left << item[i].itemName << "$" << setw(10) << item[i].itemCost << endl;
		j++;
		
    }

    cout << endl;

    while(exit == 'y' || exit == 'Y')
	{

        cout << "Please Enter your Selection or 0 to Exit : ";
        cin >> choice;

        if(cin.fail()) 
		{
            cout << "~~~~~~~~~Invalid selection~~~~~~~~~" << endl;
            cin.clear();
            cin.ignore(1000,'\n');
        } 
		else if (choice==0) {break;}
            else 
			{
                choice--;
                total += (item[choice].itemCost);
                tax = (total * .05);
                totalF = total + tax;
                cout << endl;
				outData << endl;
            }
            cout << endl;
			outData << endl;

            cout << item[choice].itemName << " " << item[choice].itemCost << endl;
            cout << "======================================================" << endl;
            cout << "Do you want to continue (Y/N): ";
			outData << item[choice].itemName << " " << item[choice].itemCost << endl;
            outData << "======================================================" << endl;
            outData << "Do you want to continue (Y/N): ";
            cin >> exit;

        }
	printCheck(total, tax, totalF, outData);
}

void menuItemType ::  printCheck(double& total, double& tax, double& totalF, ofstream& outData)
 {
     cout << "\n\nThanks for Dinning With Us!" << endl;
	 cout << "<><><><><><><><><><><><><><>\n" << endl;
	 cout << "Customer Receipt            " << endl;
	 cout << "SubTotal:               $" << total <<endl;
	 cout << "Tax:                    $" << tax << endl;
	 cout << "                        -----" << endl;
	 cout << "Total:                  $" << totalF << endl;
	 cout << "Please Come Again!" << endl;

	 outData << "\n\nThanks for Dinning With Us!" << endl;
	 outData << "<><><><><><><><><><><><><><>\n" << endl;
	 outData << "Customer Receipt            " << endl;
	 outData << "SubTotal:               $" << total <<endl;
	 outData << "Tax:                    $" << tax << endl;
	 outData << "                        -----" << endl;
	 outData << "Total:                  $" << totalF << endl;
	 outData << "Please Come Again!" << endl;
 }

int main()
{
	//menuItemType myMenu;
	

ofstream outData;
outData.open("OutMenu.txt");


cout<< "          Welcome         " << endl;
cout<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
cout<< "  *To select an Item from the list below,  " << endl;
cout<< "just indicate the Item number for the item \n\n" << endl;

outData << "          Welcome!         " << endl;
outData << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
outData << "  *To select an Item from the list below,  " << endl;
outData<< "just indicate the Item number for the item \n\n" << endl;

menuItemType menu;
menu.accessData();

&menuItemType::getData;
&menuItemType::showMenu;


menuItemType();



    system("pause");

    return 0;

}
Lines 27, 31, and 36 do nothing. What are they supposed to do?
At a guess I'd say they're supposed to look like this:
1
2
3
4
5
6
7
8
9
menuItemType::menuItemType ()
{
    getData();
}

menuItemType::~menuItemType ()
{
    printCheck();
}


EDIT: also
1
2
3
4
menuItemType::accessData ()
{
    showMenu();
}
Last edited on
After I make these adjustments am I properly calling my functions in the main?
@Zhuge those linesa are used to set up my constructor and destructor so I can properly call those functions from the main
Well like I said, those lines do nothing. They are fancy no-ops. It'd be the same if you wrote:
1
2
3
4
menuItemType :: menuItemType()
{
	2; 
}

You've created a constructor (etc.) that does nothing. What do you mean by "properly call those functions?"
Topic archived. No new replies allowed.