After sorting can`t change bool value

Hello..

I try to build a data structure with those options
a) Book a student
b) Delete a student
c) Sort students


If i book a student and after delete the student(change bool value to false and name to "") its working.

But if i book a student, and after i sort them i have a problem. The delete not working...

I try to make a small code just to give you an idea of my problem so yo can help me.


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

class classroom
{
public:
    string studentClass;
    bool studentBonus;
    string studentName;

    void classroom::createStudent(string sClass, bool bonus, string name);
};
void bookStudent(classroom bStudent[]);
void deleteStudent(classroom dStudent[]);
void sortStudent(classroom sStudent[]);
void classroom::createStudent(string sClass, bool bonus, string name)
{
    studentClass=sClass;
    studentBonus=bonus;
    studentName=name;
}

void showMenu(classroom mStudent[])
{
	char option;

	//display the choices of the user
	cout<<"a) Book a student"<<endl;
	cout<<"b) Delete a student"<<endl;
	cout<<"c) Sort students"<<endl;
	cin>> option;

		switch (option)
	{
	case 'a':
		cout<<endl;
		bookStudent(mStudent);
		showMenu(mStudent);
		break;
	case 'b':
		cout<<endl;
		deleteStudent(mStudent);
		showMenu(mStudent);
		break;
	case 'c':
		cout<<endl;
		sortStudent(mStudent);
		showMenu(mStudent);
		break;
	default:
		cout<<endl;
	}
}
void bookStudent(classroom bStudent[])
{
	//declare local variables
	int i=0;

    string bStudentClass;
    bool bStudentBonus;
    string bStudentName;

	//initialize local variables
	bStudentBonus=false;
	

	cin.ignore();
	cout<<"Enter student name"<<endl;
	getline(cin,bStudentName);


	cout<<"Enter seat id: "<<endl;
	cin>>bStudentClass;

	cout<<endl;

	if (bStudentClass=="A1")
		i=0;
	else
	if (bStudentClass=="A2")
		i=1;

	bStudent[i].createStudent(bStudentClass,true,bStudentName);
}
void deleteStudent(classroom dStudent[])
{
	//declare local variables
	int i=0;

    string bStudentClass;
    bool bStudentBonus;
    string bStudentName;

	//initialize local variables
	bStudentBonus=false;

	cout<<"Enter student class "<<endl;
	cin>>bStudentClass;

	cout<<endl;

	if (bStudentClass=="A1")
		i=0;
	else
	if (bStudentClass=="A2")
		i=1;

	dStudent[i].createStudent(bStudentClass,false,"");
}
void sortStudent(classroom sStudent[])
{
     bool doMore;

    do {
        doMore = false;  // assume this is last pass over array
        for (int i=0; i<10-1; i++) {
            if (sStudent[i].studentName > sStudent[i+1].studentName) {
                // exchange elements
                classroom temp = sStudent[i]; sStudent[i] = sStudent[i+1]; sStudent[i+1] = temp;
                doMore = true;  // after exchange, must look again
            }
        }
    } while (doMore);

        for (int j=0;j<10;j++)
        {
			if (sStudent[j].studentBonus==true)
			{
				 cout<<sStudent[j].studentName<<"    "<<sStudent[j].studentClass;
				cout<<endl;
			}
        }
		cout<<endl;
}
int main()
{
    //number of students
    const int numstudents=10;
    
    //create structure
    classroom student[numstudents];

    //initialize variables
    student[0].createStudent("A1",false,"Wella Trina");
    student[1].createStudent("A2",false,"George Ali");
    student[2].createStudent("A3",false,"Comina Riviera");

	showMenu(student);
    return 0;//indicate that program end succesfully
}//end main  


Thanks!
Topic archived. No new replies allowed.