A little confused: Classes and Objects

Working on my class assignment, and I'm not sure if I'm going about the right way.

Error Messages:
1. error c1083: Cannot open include file 'MenuBuilder.h': No such file or directory.
^How do I make a header file?^

2. IntelliSense: Cannot open source file "MenuBuilder.h"

Assignment:
Create a Test Menu class
For main method and to call the Menu Driven class

Create a MenuBuilder Class
This will be where you create statements for the following:
1. Check balance
2. Make withdrawal
3. Make deposit
4. View account information
5. View statement
6. View bank information
7. Exit
Create a MenuBuilder.h
1. Include a header file in your program.
2. This will be where you utilize standardized Identifiers,
preprocessor directives, classes, namespaces, and so forth.

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
 #include <iostream>
#include <cctype>
#include <string>
#include <MenuBuilder.h>
using namespace std;


int testMenu()
{
	//Declarations
	int answer;
	while (answer != 7)
	{

		//Prompt for input
		cout << "Welcome to the DeVry Bank Automated Teller Machine\n\n";
		cout << "What would you like to do today?\n";
		cout << "\t\t1. Check Balance\n";
		cout << "\t\t2. Make Withdrawal\n";
		cout << "\t\t3. Make Deposit\n";
		cout << "\t\t4. View Account Information\n";
		cout << "\t\t5. View Statement\n";
		cout << "\t\t6. View Bank Information\n";
		cout << "\t\t7. Exit\n";

		cin >> answer;
		while ((answer < 1) || (answer > 7))
		{
			cout << "Error: Please enter a number in numerical form between 1 and 7.\n";
			cout << "\t\t1. Check Balance\n";
			cout << "\t\t2. Make Withdrawal\n";
			cout << "\t\t3. Make Deposit\n";
			cout << "\t\t4. View Account Information\n";
			cout << "\t\t5. View Statement\n";
			cout << "\t\t6. View Bank Information\n";
			cout << "\t\t7. Exit\n";
			cin >> answer;
		}//end while 2 (error message)

		switch (answer)
		{
		case 7: return answer;
		default: MenuBuilder;
		}//end switch
	}//end first while loop (not 7)
	
}

class MenuBuilder
{
public:
	double balance = 24394.51; 
	int answer = 0;
	string name = "Sierra McGivney";
	int accountNum = 123454321;

	int checkBalance(MenuBuilder answer)
	{

	}

	void makeWithdrawal()
	{

	}

	void makeDeposit()
	{

	}

	void accountInfo()
	{

	}

	void statement()
	{

	}

	void bankInfo()
	{

	}
};


 
#include "MenuBuilder.h" 
Oh, thanks for noticing this, but do you have an idea of what I need to put in this file? I'm a bit confused about that.
At line 43 do you meant:
1
2
default: MenuBuilder();
break;

if so change class MenuBuilder to void MenuBuilder()

You should add break; at the end of switch case or switch default
Last edited on
This is what I have in the 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
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
#include <iostream>
#include <string>
using namespace std;

int answer;
class Menu
{
public:
	double balance = 24394.51;
	string name = "Sierra McGivney";
	int accountNum = 123454321;

	Menu menu1()
	{
		cout << "Your current balance is: $" << balance << endl;
		return;
	}

	Menu menu2()
	{
		cout << "How much would you like to withdrawal?\t";
		int amount = 0;
		cin >> amount;
		if (amount <= balance)
		{
			cout << "Transaction Approved!\n";
		}
		while (amount > balance)
		{
			cout << "How much would you like to withdrawal?\t$";
			int amount = 0;
			cin >> amount;
			if (amount <= balance)
			{
				cout << "Transaction Approved." << endl; break;
			}
			else
			{
				cout << "Transaction Denied! Not enough funds.\n"; break;
			}
		}
		return;
	}

	Menu menu3()
	{
		cout << "How much would you like to deposit?\t$";
		int amount = 0;
		cin >> amount;
		balance += amount;
		cout << "Transaction Approved!";
		answer = 0;
		return;
	}

	Menu menu4()
	{
		cout << "Student Name:\t" << name;
		cout << "Account Number:\t" << accountNum;
		answer = 0;
		return;
	}

	Menu menu5()
	{
		string date1 = "01/01/11", date2 = "01/15/11", date3 = "02/28/11";
		string place1 = "McDonald's", place2 = "Kwik Trip", place3 = "Target";
		double value1 = 6.27, value2 = 34.93, value3 = 124.21;
		cout << date1 << " - " << place1 << " - " << value1;
		cout << date2 << " - " << place2 << " - " << value2;
		cout << endl;
		return;
	}

	Menu menu6()
	{
		cout << "DeVry Bank, established 2011\n";
		cout << "(123) 456-7890\n";
		cout << "12345 1st st.\n";
		cout << "Someplace, NJ 12345";
		return;
	}
};
	


This is what I have in the main file:
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

#include "MenuBuilder.h"

int testMenu(int &answer)
{
	
	while (answer != 7)
	{
		//Prompt for input
		cout << "Welcome to the DeVry Bank Automated Teller Machine\n\n";
		cout << "What would you like to do today?\n";
		cout << "\t\t1. Check Balance\n";
		cout << "\t\t2. Make Withdrawal\n";
		cout << "\t\t3. Make Deposit\n";
		cout << "\t\t4. View Account Information\n";
		cout << "\t\t5. View Statement\n";
		cout << "\t\t6. View Bank Information\n";
		cout << "\t\t7. Exit\n";

		cin >> answer;
		while ((answer < 1) || (answer > 7))
		{
			cout << "Error: Please enter a number in numerical form between 1 and 7.\n";
			cout << "\t\t1. Check Balance\n";
			cout << "\t\t2. Make Withdrawal\n";
			cout << "\t\t3. Make Deposit\n";
			cout << "\t\t4. View Account Information\n";
			cout << "\t\t5. View Statement\n";
			cout << "\t\t6. View Bank Information\n";
			cout << "\t\t7. Exit\n";
			cin >> answer;
		}//end while 2 (error message)	
	switch (answer)
	{
	case 1: Menu menu1(); answer = 0; return answer;
	case 2: Menu menu2(); answer = 0; return answer;
	case 3: Menu menu3(); answer = 0; return answer;
	case 4: Menu menu4(); answer = 0; return answer;
	case 5: Menu menu5(); answer = 0; return answer;
	case 6: Menu menu6(); answer = 0; return answer;
	default: return answer; answer = 0; return answer;
	}//end switch
	}//end first while loop (not 7)


}



Error 1 error C2561: 'Menu::menu1' : function must return a value c:\users\damir\documents\visual studio 2013\projects\w6_lab\w6_lab\menubuilder.h 16 1 w6_lab
Error 2 error C2561: 'Menu::menu2' : function must return a value c:\users\damir\documents\visual studio 2013\projects\w6_lab\w6_lab\menubuilder.h 42 1 w6_lab
Error 3 error C2561: 'Menu::menu3' : function must return a value c:\users\damir\documents\visual studio 2013\projects\w6_lab\w6_lab\menubuilder.h 53 1 w6_lab
Error 4 error C2561: 'Menu::menu4' : function must return a value c:\users\damir\documents\visual studio 2013\projects\w6_lab\w6_lab\menubuilder.h 61 1 w6_lab
Error 5 error C2561: 'Menu::menu5' : function must return a value c:\users\damir\documents\visual studio 2013\projects\w6_lab\w6_lab\menubuilder.h 72 1 w6_lab
Error 6 error C2561: 'Menu::menu6' : function must return a value c:\users\damir\documents\visual studio 2013\projects\w6_lab\w6_lab\menubuilder.h 81 1 w6_lab
Last edited on
Change return value of menu1(), menu2(), ... (Menu) to void and remove all the return;

1
2
3
void menu1() {
	cout << "Your current balance is: $" << balance << endl;
	}


Try to add break; after each switch case and after switch default
Last edited on
Okay, so I did that but none of the errors disappeared. Unfortunately, I think the problem lies with my class functions.


main code
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
#include "MenuBuilder.h"

int testMenu(int &answer)
{
	
	while (answer != 7)
	{
		//Prompt for input
		cout << "Welcome to the DeVry Bank Automated Teller Machine\n\n";
		cout << "What would you like to do today?\n";
		cout << "\t\t1. Check Balance\n";
		cout << "\t\t2. Make Withdrawal\n";
		cout << "\t\t3. Make Deposit\n";
		cout << "\t\t4. View Account Information\n";
		cout << "\t\t5. View Statement\n";
		cout << "\t\t6. View Bank Information\n";
		cout << "\t\t7. Exit\n";

		cin >> answer;
		while ((answer < 1) || (answer > 7))
		{
			cout << "Error: Please enter a number in numerical form between 1 and 7.\n";
			cout << "\t\t1. Check Balance\n";
			cout << "\t\t2. Make Withdrawal\n";
			cout << "\t\t3. Make Deposit\n";
			cout << "\t\t4. View Account Information\n";
			cout << "\t\t5. View Statement\n";
			cout << "\t\t6. View Bank Information\n";
			cout << "\t\t7. Exit\n";
			cin >> answer;
		}//end while 2 (error message)	
	switch (answer)
	{
	case 1: Menu menu1(); break;
	case 2: Menu menu2(); break;
	case 3: Menu menu3(); break;
	case 4: Menu menu4(); break;
	case 5: Menu menu5(); break;
	case 6: Menu menu6(); break;
	default: break;
	}//end switch
	}//end first while loop (not 7)


}



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
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
#include <iostream>
#include <string>
using namespace std;

int answer;
class Menu
{
public:
	double balance = 24394.51;
	string name = "Sierra McGivney";
	int accountNum = 123454321;

	Menu menu1()
	{
		cout << "Your current balance is: $" << balance << endl;
		return;
	}

	Menu menu2()
	{
		cout << "How much would you like to withdrawal?\t";
		int amount = 0;
		cin >> amount;
		if (amount <= balance)
		{
			cout << "Transaction Approved!\n";
		}
		while (amount > balance)
		{
			cout << "How much would you like to withdrawal?\t$";
			int amount = 0;
			cin >> amount;
			if (amount <= balance)
			{
				cout << "Transaction Approved." << endl; break;
			}
			else
			{
				cout << "Transaction Denied! Not enough funds.\n"; break;
			}
		}
		return;
	}

	Menu menu3()
	{
		cout << "How much would you like to deposit?\t$";
		int amount = 0;
		cin >> amount;
		balance += amount;
		cout << "Transaction Approved!";
		answer = 0;
		return;
	}

	Menu menu4()
	{
		cout << "Student Name:\t" << name;
		cout << "Account Number:\t" << accountNum;
		answer = 0;
		return;
	}

	Menu menu5()
	{
		string date1 = "01/01/11", date2 = "01/15/11", date3 = "02/28/11";
		string place1 = "McDonald's", place2 = "Kwik Trip", place3 = "Target";
		double value1 = 6.27, value2 = 34.93, value3 = 124.21;
		cout << date1 << " - " << place1 << " - " << value1;
		cout << date2 << " - " << place2 << " - " << value2;
		cout << endl;
		return;
	}

	Menu menu6()
	{
		cout << "DeVry Bank, established 2011\n";
		cout << "(123) 456-7890\n";
		cout << "12345 1st st.\n";
		cout << "Someplace, NJ 12345";
		return;
	}
};
	


Error Messages:
Error 1 error C2561: 'Menu::menu1' : function must return a value c:\users\damir\documents\visual studio 2013\projects\w6_lab\w6_lab\menubuilder.h 16 1 w6_lab
Error 2 error C2561: 'Menu::menu2' : function must return a value c:\users\damir\documents\visual studio 2013\projects\w6_lab\w6_lab\menubuilder.h 42 1 w6_lab
Error 3 error C2561: 'Menu::menu3' : function must return a value c:\users\damir\documents\visual studio 2013\projects\w6_lab\w6_lab\menubuilder.h 53 1 w6_lab
Error 4 error C2561: 'Menu::menu4' : function must return a value c:\users\damir\documents\visual studio 2013\projects\w6_lab\w6_lab\menubuilder.h 61 1 w6_lab
Error 5 error C2561: 'Menu::menu5' : function must return a value c:\users\damir\documents\visual studio 2013\projects\w6_lab\w6_lab\menubuilder.h 72 1 w6_lab
Error 6 error C2561: 'Menu::menu6' : function must return a value c:\users\damir\documents\visual studio 2013\projects\w6_lab\w6_lab\menubuilder.h 81 1 w6_lab

Last edited on
Er... read my previous post, it's been edited
Whoops! Didn't see that it changed! Here's what I have now:


main code
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
#include "MenuBuilder.h"

int testMenu(int &answer)
{
	
	while (answer != 7)
	{
		//Prompt for input
		cout << "Welcome to the DeVry Bank Automated Teller Machine\n\n";
		cout << "What would you like to do today?\n";
		cout << "\t\t1. Check Balance\n";
		cout << "\t\t2. Make Withdrawal\n";
		cout << "\t\t3. Make Deposit\n";
		cout << "\t\t4. View Account Information\n";
		cout << "\t\t5. View Statement\n";
		cout << "\t\t6. View Bank Information\n";
		cout << "\t\t7. Exit\n";

		cin >> answer;
		while ((answer < 1) || (answer > 7))
		{
			cout << "Error: Please enter a number in numerical form between 1 and 7.\n";
			cout << "\t\t1. Check Balance\n";
			cout << "\t\t2. Make Withdrawal\n";
			cout << "\t\t3. Make Deposit\n";
			cout << "\t\t4. View Account Information\n";
			cout << "\t\t5. View Statement\n";
			cout << "\t\t6. View Bank Information\n";
			cout << "\t\t7. Exit\n";
			cin >> answer;
		}//end while 2 (error message)	
	switch (answer)
	{
	case 1: void menu1(); break;
	case 2: void menu2(); break;
	case 3: void menu3(); break;
	case 4: void menu4(); break;
	case 5: void menu5(); break;
	case 6: void menu6(); break;
	default: break;
	}//end switch
	}//end first while loop (not 7)

	return 0;
}



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
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
#include <iostream>
#include <string>
using namespace std;

int answer;
class Menu
{
public:
	double balance = 24394.51;
	string name = "Sierra McGivney";
	int accountNum = 123454321;

	void menu1()
	{
		cout << "Your current balance is: $" << balance << endl;
		return;
	}

	void menu2()
	{
		cout << "How much would you like to withdrawal?\t";
		int amount = 0;
		cin >> amount;
		if (amount <= balance)
		{
			cout << "Transaction Approved!\n";
		}
		while (amount > balance)
		{
			cout << "How much would you like to withdrawal?\t$";
			int amount = 0;
			cin >> amount;
			if (amount <= balance)
			{
				cout << "Transaction Approved." << endl; break;
			}
			else
			{
				cout << "Transaction Denied! Not enough funds.\n"; break;
			}
		}
		return;
	}

	void menu3()
	{
		cout << "How much would you like to deposit?\t$";
		int amount = 0;
		cin >> amount;
		balance += amount;
		cout << "Transaction Approved!";
		answer = 0;
		return;
	}

	void menu4()
	{
		cout << "Student Name:\t" << name;
		cout << "Account Number:\t" << accountNum;
		answer = 0;
		return;
	}

	void menu5()
	{
		string date1 = "01/01/11", date2 = "01/15/11", date3 = "02/28/11";
		string place1 = "McDonald's", place2 = "Kwik Trip", place3 = "Target";
		double value1 = 6.27, value2 = 34.93, value3 = 124.21;
		cout << date1 << " - " << place1 << " - " << value1;
		cout << date2 << " - " << place2 << " - " << value2;
		cout << endl;
		return;
	}

	void menu6()
	{
		cout << "DeVry Bank, established 2011\n";
		cout << "(123) 456-7890\n";
		cout << "12345 1st st.\n";
		cout << "Someplace, NJ 12345";
		return;
	}
};
	
	


Error Messages:
Error 2 error LNK1120: 1 unresolved externals c:\users\damir\documents\visual studio 2013\Projects\w6_lab\Debug\w6_lab.exe 1 1 w6_lab
Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup c:\Users\Damir\documents\visual studio 2013\Projects\w6_lab\w6_lab\MSVCRTD.lib(crtexe.obj) w6_lab
int main() missing
And dude, you misunderstood me.

MenuBuilder.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
#include <iostream>
#include <string>
using namespace std;

int answer;
class Menu
{
public:
	double balance = 24394.51;
	string name = "Sierra McGivney";
	int accountNum = 123454321;

	void menu1()
	{
		cout << "Your current balance is: $" << balance << endl;
	}

	void menu2()
	{
		cout << "How much would you like to withdrawal?\t";
		int amount = 0;
		cin >> amount;
		if (amount <= balance)
		{
			cout << "Transaction Approved!\n";
		}
		while (amount > balance)
		{
			cout << "How much would you like to withdrawal?\t$";
			int amount = 0;
			cin >> amount;
			if (amount <= balance)
			{
				cout << "Transaction Approved." << endl; break;
			}
			else
			{
				cout << "Transaction Denied! Not enough funds.\n"; break;
			}
		}
	}

	void menu3()
	{
		cout << "How much would you like to deposit?\t$";
		int amount = 0;
		cin >> amount;
		balance += amount;
		cout << "Transaction Approved!";
		answer = 0;
	}

	void menu4()
	{
		cout << "Student Name:\t" << name;
		cout << "Account Number:\t" << accountNum;
		answer = 0;
	}

	void menu5()
	{
		string date1 = "01/01/11", date2 = "01/15/11", date3 = "02/28/11";
		string place1 = "McDonald's", place2 = "Kwik Trip", place3 = "Target";
		double value1 = 6.27, value2 = 34.93, value3 = 124.21;
		cout << date1 << " - " << place1 << " - " << value1;
		cout << date2 << " - " << place2 << " - " << value2;
		cout << endl;
	}

	void menu6()
	{
		cout << "DeVry Bank, established 2011\n";
		cout << "(123) 456-7890\n";
		cout << "12345 1st st.\n";
		cout << "Someplace, NJ 12345";
	}
} menu; //notice changes here 


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
#include "MenuBuilder.h"

int testMenu() //notice changes here
{
	int answer = 0; //notice changes here
	while (answer != 7)
	{
		//Prompt for input
		cout << "Welcome to the DeVry Bank Automated Teller Machine\n\n";
		cout << "What would you like to do today?\n";
		cout << "\t\t1. Check Balance\n";
		cout << "\t\t2. Make Withdrawal\n";
		cout << "\t\t3. Make Deposit\n";
		cout << "\t\t4. View Account Information\n";
		cout << "\t\t5. View Statement\n";
		cout << "\t\t6. View Bank Information\n";
		cout << "\t\t7. Exit\n";

		cin >> answer;
		while ((answer < 1) || (answer > 7))
		{
			cout << "Error: Please enter a number in numerical form between 1 and 7.\n";
			cout << "\t\t1. Check Balance\n";
			cout << "\t\t2. Make Withdrawal\n";
			cout << "\t\t3. Make Deposit\n";
			cout << "\t\t4. View Account Information\n";
			cout << "\t\t5. View Statement\n";
			cout << "\t\t6. View Bank Information\n";
			cout << "\t\t7. Exit\n";
			cin >> answer;
		}//end while 2 (error message)	
		switch (answer)
		{
                //notice changes here
		case 1: menu.menu1(); break; //notice changes here too
		case 2: menu.menu2(); break; //remember the change in the MenuBuilder.h ending
		case 3: menu.menu3(); break;
		case 4: menu.menu4(); break;
		case 5: menu.menu5(); break;
		case 6: menu.menu6(); break;
		default: break;
		}//end switch
	}//end first while loop (not 7)

	return 0;
}

int main() { //missing
	testMenu();
	return 0;
}
Oh! Sorry, I didn't understand that you meant the classes as well. If I may ask a quick question, you put menu at the end of the class function so that it would return to the main function, correct? Or am I totally not getting it?
Last edited on
I did that to create (menu is) an instance of class Menu. So that I can call menu1(), menu2(),...
Instead of coding this in the int main():
Menu menu;
Last edited on
I see. That's interesting, and thank your for explaining. Probably couldn't have figured this out without your help. :)
You're welcome
Topic archived. No new replies allowed.