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 167 168 169 170 171 172 173 174 175
|
#include <iostream>
#include <string>
using namespace std;
struct student{
int student_ID[30];
string student_name[30];
string nickname[30];
int sub;
};
struct course{
int course_code[30];
string course_name[30];
string lecturer_name[30];
};
void add_student(student detail[],int);
void display_student(student detail[],int);
void add_new_course(course info[],int);
void display_course(course info[],int);
void modify(student detail[],int);
void assign(student detail,course sub);
int i;
int j;
int size;
int size2;
int choice;
int data;
int subject;
student detail[20];
course info[20];
void main()///this is no void main in standard c++, only int main
{
cout<<"1. Add new students"<<endl;
cout<<"2. Display student list"<<endl;
cout<<"3. Add new course"<<endl;
cout<<"4. Display Course Offered"<<endl;
cout<<"5. Modify selected student name"<<endl;
cout<<"6. Assign a student to a subject listed in the list"<<endl;
cout<<"7. End of program"<<endl;
cout<<"Please select what do wish to perform? : "<<endl;
cin>>choice;
cout<<"You entered :"<<choice<<"."<<endl;
switch (choice){
case 1:
add_student(student detail[i],size);///your function should take an array not a declaration of a class object
///should be like this {add_student(detail,size)}
break;
case 2:
display_student(student detail[i],size);///similar to above
break;
case 3:
add_new_course(course Info[j],int size2);///similar to above
break;
case 4:
void display_course(course Info[j],int size2);///similar to above
break;
case 5:
modify(student Detail[i],int size);///similar to above
break;
case 6:
assign(student Detail,course sub);///you've got a problem calling functions in main, check that carefully
break;
default:
printf("You chose not to do anything\n");
break;
}
void add_student(student Detail[],int size)
{
student Detail[size];///this is a local array you'll be overshadowing your parameter Detail
///remove it it's not needed
for(int i=0;i<size;i++)
{
cout<<"Enter your student ID:";
cin>> Detail[i].student_ID;
cout<<"Enter your student name:";
cin>> Detail[i].student_name;
cout<<"Enter your nickname:";
cin>> Detail[i].nickname;
}
}
void display_student(student Detail[],int size)///now this is what you should be doing, seems the error above was a mistake
{
for (int i =0; i <5;i++)
{
/// oooh no , please provide the right instructions to the user
./// if indeed you need the user to provide some input you'll require cin>>
cout<<"Enter your student ID:"<<Detail[i].student_ID<<endl;
///cin>>Detail[i].student_ID something like that
cout<<"Enter your student name:"<<Detail[i].student_name<<endl;
cout<<"Enter your nickname:"<<Detail[i].nickname<<endl;
}
}
void add_new_course(course Info[],int size2)
{
course Info[size2];///ooh no! again, remove this, you don't need to re declare your
/// parameters to use them.
for(int j=0;j<2;j++)
{
cout<<"Enter your course code:";
cin>> Detail[j].course_code;/// no no no, i don't understand {Detail[j] or Info[j]}
/// provide the right parameter
cout<<"Enter your course name:";
cin>> Detail[j].course_name;
cout<<"Enter your lecturer name:";
cin>> Detail[j].lecturer_name;
}
}
void display_course(course Info[],int size2///this is good
{
for (int j =0; j <2;j++)
{
cout<<"Enter your course code:"<<Detail[j].course_code<<endl;///no no no the instructions provided do not match
cout<<"Enter your course name:"<<Detail[j].course_name<<endl;/// with what this function id doing.
cout<<"Enter your lecturer name:"<<Detail[j].lecturer_name<<endl;
}
}
void modify(student Detail[],int size)
{
int num, new_name;
cout<<"Enter the number of the student to modify : ";
cin>>num;
i = num-1;
cout<<"Enter new name of student : ";
cin>>data[i].new_name;/// please provide the correct parameter to your functions {data[i] /?? Detail[]??}
}
void assign(student Detail,course sub)
{
int num_student,num_subject ;
cout<<"Please enter number of student to assign the subject : ";
cin>>num_student;
cout<<"Choose only subject that want to assign to the student from the list. Please enter number of the subject : ";
cin>>num_subject;
i = num_student-1; /// hey avoid global variables as much as possible, they'll just
/// stay in your ram doing nothing, always declare your variables
j = num_sub-1; /// when you need to use them.
///hey please provide the correct instructions to the user, here you're not reading anything from the keyboard.
cout<<"Enter your student ID:"<<Detail[i].student_ID<<endl ;
cout<<"Enter your student name:"<<Detail[i].student_name<<endl;
cout<<"Enter your nickname:"<<Detail[i].nickname<<endl;
cout<<endl;
cout<<"Enter your course code:"<<Detail[j].course_code<<endl;
cout<<"Enter your course name:"<<Detail[j].course_name<<endl;
cout<<"Enter your lecturer name:"<<Detail[j].lecturer_name<<endl;
cout<<endl;
}
return 0;
}
| |