Struct and for loops

I am trying to make a basic small program for school that takes a structure of a classroom and allows the user to create/edit a new classroom using the struct. The instructions for this assignment say to just create a function that will allow you to add data to the attributes of the classroom. Which i have done and tested and it works. Create a function that allows you to print out the classroom information. I have a function prototyped for that step and don't feel i'll need help doing that part. Then compare two classrooms based on the size (number of chairs) and report which classroom is larger. Also compare two classrooms base on utilization. I haven't gotten that far or tried to code that part yet but I figure I list the full assignment so you know what I am trying to accomplish.

The problem I am having has to do with my for loop inside the edit function. When trying to set my iterator to be the same size as my vector using "vector.max_size" I get a compile error well several but all linked to the same thing. Basically I want to list all the created classes by pulling the className string from the vector and have the user choose which class they want to edit.

error
1
2
3
4
5
6
7
error C3867: 'std::vector<classroom,std::allocator<_Ty>>::max_size': function
 call missing argument list; use '&std::vector<classroom,std::allocator<_Ty>>::max_size'
 to create a pointer to member
1>          with
1>          [
1>              _Ty=classroom
1>          ]


My guess is that some how there is a way to set the vectors size or allocate it in a way that will not throw the error? I think it might also be linked to how my add function is set up. Using "storedClass.push_back(classroom());" to allocate the first position in the vector so that I can add the newclassroom struct and edit using vector[0].className; etc.

Can some one please point me in the right direction on how I should be going about solving this issue or maybe let me know if there is a better way to do this? I know i need to use the vector for the comparison step later on.

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
  // Structures.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void addClass();
void showClass();
void editClass();
void menuSystem();



struct classroom 
		{
			//data-types being declared
			string className;
			int roomNum;
			string lecture;
			int chairs;
			bool window;
			bool projector;
			bool available;
		};
vector<classroom> storedClass;

int _tmain(int argc, _TCHAR* argv[])
{
	menuSystem();

	return 0;
}

void menuSystem()
{
	int choice;

	system("CLS");

	cout << "\t\tWhat would you like to do..." << endl;
	cout << "\t1. add classroom" << endl;
	cout << "\t2. edit classroom" << endl;
	cout << "\t3. show classroom" << endl;
	cout << "\t4. exit" << endl;
	cin >> choice;

	if (choice == 1)
	{
		addClass();
	}
	if (choice == 2)
	{
		editClass();
	}
	if (choice == 3)
	{
		showClass();
	}
	if (choice < 1 || choice > 3)
		return;
}

void addClass()
{	
	system("CLS");
	
	storedClass.push_back(classroom());
	char temp;
	
	cout << "Please name the classroom : ";
	cin >> storedClass[0].className;
	cout << endl;
	cout << "What is the room number?: ";
	cin >> storedClass[0].roomNum;
	cout << endl;
	cout << "What lecture is this for: ";
	cin >> storedClass[0].lecture;
	cout << endl;
	cout << "How many chairs are there: ";
	cin >> storedClass[0].chairs;
	cout << endl;
	cout << "Are there windows (y/n): ";
	cin >> temp;
	if (temp == 'y'){
		storedClass[0].window = true;
	}
	else
	{
		storedClass[0].window = false;
	}
	cout << endl;
	cout << "Is there a projector (y/n): ";
	cin >> temp;
	if (temp == 'y'){
		storedClass[0].projector = true;
	}
	else
	{
		storedClass[0].projector = false;
	}
	cout << endl;
	cout << "Is it avialable (y/n): ";
	cin >> temp;
	if (temp == 'y'){
		storedClass[0].available = true;
	}
	else
	{
		storedClass[0].available = false;
	}
	cout << endl;		

	cout << "\t\t\tNew Classroom succesfully added!!!" << endl;
	system("PAUSE");

	menuSystem();
}

void editClass()
{
	cout << "\t\tWhich class do you want to edit?" << endl;
	for (int i = 0; i < storedClass.max_size; i++)
	{
		cout << "\t\t" << i << ". "<< storedClass[i].className << endl;
	}

	/*
	cout << "\t\tWhat would you like to edit?" << endl;
	cout << "\t1. Class Name" << endl;
	cout << "\t2. Room Number" << endl;
	cout << "\t3. Lecture" << endl;
	cout << "\t4. Chairs" << endl;
	cout << "\t5. Windows" << endl;
	cout << "\t6. Projector" << endl;
	cout << "\t7. Available" << endl;*/	
}

void showClass()
{

}
Last edited on
Line 126: max_size is a function. You need () to call the function. You probably want size(), not max_size(). size() tells you how many entries are currently in the vector. max_size() tells you how many entries the vector can hold without reallocating storage. These are not the same thing.
holy crap no idea why i didnt realize that. Thank you!! I just got off a semester of java so c++ was still being refreshed in my mind.
Topic archived. No new replies allowed.