simple student data show program

hi friends
just started c++ programming times ago and now i should give my first project to the teacher-_- i only have 5-6 hours to give it :[
and now the problem
write an app to get students names/course names and their marks!!then show the marks in courses accending (in menu by tapping 2 and enter )
or show the card for the chosen student(in menu by tapping 3 and enter);
as the amount of students /marks and courses are not known i thought i should use arrays
but now i dont know how to show separate students marks or separate courses!!!
here is my code!!!please help meeeeeeeeee!!:) tnx

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
#include <iostream>
#include <conio.h>
using namespace std;
string course[20];
string student[20];
double marks[50];
int td,ts,x,y,z,k=1,all,E=0;
int b1,b2,b3;
int main()
{
    int choise,choise3;
    string choise2;
     do{
       cout<<"========================================================================================================================\n\t\t\t\t\tyyy\n\t\t\t\t\t\t <I> \n========================================================================================================================\n";
       cout<<"|1|save the information\n";
       cout<<"|2|show course information\n\n";
       cout<<"|3|show card for specific student\n";
       cout<<"|4|exit\n";
       cout<<"__________________________________________________________________________________\n";
       cout<<"your selection:";cin>>choise;
     switch (choise)
      {
      case 1:
    cout<<"========================================================================================================================\n\t\t\t\t\t       <S.i>\n\t\t\t\t\t\t\n========================================================================================================================\n";
	cout<<"\namount of students:";cin>>ts;
    cout<<"\namount of courses:";cin>>td;
    all=td*ts;
    for(int A=0;A<ts;A++)
        {if (k>=1)
            {cout<<"student "<<A+1<<" name:";getline(cin,student[A]);
            }else
            cout<<"student "<<A+1<<" name:";getline(cin,student[A]);
            k--;}
    for (int B=0;B<td;B++)
        {cout<<"course "<<B+1<<" name:";getline(cin,course[B],'\n');}
        for (int zz=0;zz<ts;zz++)
        {
            for (int sa=0;sa<td;sa++)
            {
                cout<<student[zz]<<"'s mark in "<<course[sa]<<"   = ";cin>>marks[E];E++;
            }

        }
        cout<<"\t\t\t\t     **DONE!**\n";
        break;
      case 2:
          do{
           cout<<"========================================================================================================================\n\t\t\t\t\t       <COURSE MENU>\n\t\t\t\t\t\t\n========================================================================================================================\n";
           cout<<"__________________________________________________________________________________\n";
           cout<<"ENTER THE COURSE NAME:";cin>>choise2;
           for(int t = 0; t < td; t++){
           if(course[t] == choise2)
            {
             cout <<"SHOW MARKS FOR "<<choise2<<":\n";
             cout <<"------------------------------------------\n";
              for(int ak=0;ak<td;ak++)
                cout<<student[ak]<<"\n";
               }
      }
          }while (choise2!="back");
        break;
      case 3:
              cout<<"========================================================================================================================\n\t\t\t\t\t       <CARD MENU>\n\t\t\t\t\t\t\n========================================================================================================================\n";
      for(int iu=0;iu<all;iu++)
      {

      }
        break;
       }
     }while (choise!=4);
}

im really stuck here-_-

really dont know who to do something for showing each curse and student information separatly:(
Last edited on
Honestly it's a bit of a mess.

Many of the braces don't match. For example the } before the last while should be for the first do, but instead it's the closing bracket for the switch statement. Im not sure if this is only how the code looks on this website, but if this is how the code looks in your IDE, then you need to learn how to do Indentation.

1
2
3
4
5
6
7
8
9
if()
{
    while()
    {
         if()
         {
         }
     }
}


So you can proparly see which bracket belongs to what.

Edit: It's actually spelt choice, not choise.

but now i dont know how to show separate students marks or separate courses!


You need to be more clear with your question, do you want to simply print out the student marks?
Last edited on
hi tarik
tnx for replay and advice bro

the problem is not braces i think the copy process wasnt true here in the code//the app compiles if you test and no errores!
but my problem is how to show the courses separately ... and of course their marks ...becasue printing the array with loop prints all the array not a specific part for example only the computer scene course
im i wrong????
im just a noob :D
So there's a few ways to approach this problem. Has your teacher taught you about vectors yet? Because they would be more reasonable when dealing with a varying number of items.

Also other notable things you're doing that you dont want to make a habit:
- multiple statements on one line ( cout << "hi"; cin >> a; needs to be on 2 lines.)
- super long lines (try to keep it below 80 as long lines are hard to read)
In case you didnt know in c++ and c if you have 2 string litterals next to each other they will act like one. "hello " "world!" will actually be looked at like "hello world!"so please you want to program like other people will be reading it 100 of the time!
Hey. That's weird. Because this code did not compile for me. Either way...

So by the looks of it, you want to ask the user what course they want, and then print out the course and it's marks, and only the course they chose, nothing else. Is that correct?
I NEED SOME OUTPUT LIKE THIS FOR SECOND MENU WHEN I CHOOSE BLAHBLAHBLAH
SHOWING MARKS FOR COURSE : BLAHBLAHBLAH
---------------------------------------
NAME MARK GRADE

JOHNY 18 1
SCCOT 15 2
MANUEL 9 3

AND SOME OUTPUT LIKE THIS WHEN I USE THE THIRD MENU
CARD FOR STUDENT : JOHNY
--------------------------------------
COURSE NAME MARK GRADE

BLAHBLAHBLAH 18 1
BLIHBLIHBLIH 2 3
BLOOHBLOOHBLOOH 15 2

@noobforce
thanks for your advice's !
dont blame me too much :D im only a noob and you should force me :P :D
jk;
no bro i dont know nothing about vectors...can you show me a easy example!!

@tarikNeaj
exactly yess!!
i only want to get some students and some courses and then some marks...then just show the marks in the courses or showing the whole courses marks for a student:_
btw you have to #include <string>
to be able to use getline(cin, student[A]);

vectors act alot like array but are much more useful because they can change size.
This site has a tutorial which can show you how to use them. If you havnt used them in class then the prof probably wont let you which is stupid but is life.

I think a problem here is that the directions are a bit unclear.
I almost feel like you need more options.
are you trying to store student names, courses, and grades?
how are you going to associate a student to a course? can a student have more than one course?
again thanks dear noob force:)
yep, he/she could have more than one course
it simply got amount of students;amount of courses and then asks every students marks in the courses...
i think i did it (not?) ?:D
with that code i store them into arrays...
but with arrays i only can print them all!! no choose and no specific course or student
i want what i explained up as output did you saw it bro?

and if my code is wholly wrong and stupid(:D) ,how do you do to solve this problem and do the project, i mean how do you associate students with courses and getting this output:
SHOWING MARKS FOR COURSE : BLAHBLAHBLAH
---------------------------------------
NAME MARK GRADE

JOHNY 18 1
SCCOT 15 2
MANUEL 9 3
Last edited on
Ok i see what youd like to do now!
Every student is associated/enrolled in every course.
I'd suggest using a 2D array if the teacher lets you use one:
double marks[MAX_COURSES][MAX_STUDENTS] = {};
I'll post an example of what you'd like to do in a minute.
Has your teacher talked about functions btw?
big big big thanks to you!!!!!
yes he has:D
im waiting for you example...
not so much time only 2 hours:(
do you think i could do it in 2hours?
i'm gonna try and idk when you had this assigned but don't do this again where you're concerned how much time you have left.
tnx sure ok:D
sry but are you going to show me the example bro?
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
/*
write an app to get students names/course names and their marks!!
then show the marks in courses accending (in menu by tapping 2 and enter )
or show the card for the chosen student(in menu by tapping 3 and enter);
*/

#include <iostream>
#include <string>
#include <vector>

using namespace std;

//change these values how you please.
const int MAX_COURSES = 10;
const int MAX_STUDENTS = 10;

char getChoice() {
	char choice;
	cout << "===simple student data show app===" << endl;
	cout << "1) Save the information" << endl;
	cout << "2) Show course information" << endl;
	cout << "3) Show card for specific student" << endl;
	cout << "4) Exit" << endl;
	cout << "\tSelection: ";
	// I use a char instead of an int because it's much more difficult to fail where as if someone
	// typed out a 'w' instead of a '2' your program would stop unless you knew how to fix it
	cin >> choice;
	return choice;
}

void setData(
	string students[MAX_STUDENTS],
	string courses[MAX_COURSES],
	double marks[MAX_COURSES][MAX_STUDENTS],
	int & num_students,
	int & num_courses)
{
	// input students their class and their marks
	//im not sure if you've been taught how to deal with invalid
	//input in streams so lets pray noone puts a 'r' instread of a '6' here
	// and also that they dont put higher than 10.
	cout << "Number of students(1-" << MAX_STUDENTS << "): ";
	cin >> num_students;

	cout << "Number of courses(1-" << MAX_COURSES << "): ";
	cin >> num_courses;

	for (int i = 0; i < num_students; ++i) {
		cout << "Student name: ";
		getline(cin, students[i]);
	}

	for (int i = 0; i < num_courses; ++i) {
		cout << "Course name: ";
		getline(cin, courses[i]);
	}

	for (int course = 0; course < num_students; ++course) {
		for (int student = 0; student < num_courses; ++student) {
			cout << "(" << students[student] << ": " << courses[course] << ": ";
			//please don't put a 'g' here only numbers D:
			cin >> marks[course][student];
		}
	}

}

void copyData(
	string students[MAX_STUDENTS],
	double marks[MAX_STUDENTS],
	string cpy_students[MAX_STUDENTS],
	double cpy_marks[MAX_STUDENTS],
	const int NUM_STUDENTS) {
	for (int i = 0; i < NUM_STUDENTS; ++i) {
		cpy_students[i] = students[i];
		cpy_marks[i] = marks[i];
	}
}

void sortData(
	string cpy_students[],
	double cpy_marks[],
	const int NUM_STUDENTS) //selection sort b/c idk if you can use <algorithm>
{
	for (int i = 0; i < MAX_STUDENTS; ++i) {
		int highest_mark = i;
		for (int j = i; j < MAX_STUDENTS; ++j)
			if (cpy_marks[j] > cpy_marks[highest_mark])
				highest_mark = j;
		std::swap(cpy_marks[i], cpy_marks[highest_mark]);
		std::swap(cpy_students[i], cpy_students[highest_mark]);
	}
}

void displayData(
	string cpy_students[],
	double cpy_marks[],
	const int NUM_STUDENTS)
{
	for (int i = 0; i < NUM_STUDENTS; ++i)
		cout << i + 1 << " " << cpy_students[i] << ": " << cpy_marks[i];
}

void displayAndSortData(
	string students[MAX_STUDENTS],
	string courses[MAX_COURSES],
	double marks[MAX_COURSES][MAX_STUDENTS],
	const int NUM_STUDENTS,
	const int NUM_COURSES)
{
	for (int course = 0; course < NUM_COURSES; ++course) {
		string cpy_students[MAX_STUDENTS];
		double cpy_marks[MAX_STUDENTS];

		copyData(students, marks[course], cpy_students, cpy_marks, NUM_STUDENTS);
		sortData(cpy_students, cpy_marks, NUM_STUDENTS);
		cout << courses[course] << endl;
		displayData(cpy_students, cpy_marks, NUM_STUDENTS);
	}
}

bool evalChoice(
	char choice,
	string students[MAX_STUDENTS],
	string courses[MAX_COURSES],
	double marks[MAX_COURSES][MAX_STUDENTS],
	int & num_students,
	int & num_courses)
{
	bool cont = true;
	switch (choice) {
	case '1':
		setData(students, courses, marks, num_students, num_courses);
		break;
	case '2':
		displayAndSortData(students, courses, marks, num_students, num_courses);
		break;
	case '3':
		// you fill in the blank for this one :)
		break;
	case '4':
		cont = false;
		break;
	default:
		cout << "A non valid character was entered." << endl;
		cout << "Please try again." << endl;
	}
	return cont;
}

int main() {
	bool cont = true; //continue looping?
	char choice = 0;

	string students[MAX_STUDENTS];
	string courses[MAX_COURSES];
	double marks[MAX_COURSES][MAX_STUDENTS] = {}; // make all the values 0.
	int num_students = 0;
	int num_courses = 0;

	do {
		choice = getChoice();
		cont = evalChoice(choice, students, courses, marks, num_students, num_courses);
	} while (cont);
}
As you continue learning youll learn how much easier this could have been using more STL libraries and the what not. Also I forgot the cin.ignore() s and other things but you can take it from here. You simply copy what you need out of the main array and place them into your copy manipulate it and then go from there.
wow wow wow
special thanks to you noobforce!!
i really dont know how to say thanks to you...
you are really a big big programmer ...
special thanks to you bro!!
which source do you recommend to learn c++ from beginning ? i really love programming !!
again noobforce idk how to say thank to you!!!!!
Topic archived. No new replies allowed.