CSNB244 Lab5

6
#include<iostream> #include<string> #include<conio.h> #include<windows.h> #include<stddef.h> using namespace std; struct Course { string courseCode; string courseName; string courseLectureName; }; struct Student { string studentID; string studentName; string studentNickName; Course *subjectTaken; }; int main() { Student *arrPtrPelajar = new Student[5]; Course *arrPtrSubject = new Course[2]; int choice; bool check = false; do { cout<<"1. Add New Student"; cout<<endl; cout<<"2. Display Student List"; cout<<endl; cout<<"3. Add New Course"; cout<<endl; cout<<"4. Display Course Offered"; cout<<endl; cout<<"5. Modify Selected Student"; cout<<endl; cout<<"6. Select Subject Taken and Display"; cout<<endl<<endl; cout<<"Enter your choice (1/2/3/4/5/6) [0 to terminate] : "; cin>>choice; if(choice == 1) { if(arrPtrPelajar[0].studentID == "" ) { for(int i=0 ; i<5 ; i++) { cout<<"Enter Student ID : "; cin>>ws; getline(cin , arrPtrPelajar[i].studentID); cout<<"Enter Student Name : "; getline(cin , arrPtrPelajar[i].studentName); cout<<"Enter Student Nick Name : "; getline(cin , arrPtrPelajar[i].studentNickName); cout<<endl;

Transcript of CSNB244 Lab5

Page 1: CSNB244 Lab5

#include<iostream>#include<string>#include<conio.h>#include<windows.h>#include<stddef.h>

using namespace std;

struct Course{

string courseCode;string courseName;string courseLectureName;

};

struct Student{

string studentID;string studentName;string studentNickName;Course *subjectTaken;

};

int main(){

Student *arrPtrPelajar = new Student[5];Course *arrPtrSubject = new Course[2];

int choice;bool check = false;

do{

cout<<"1. Add New Student";cout<<endl;cout<<"2. Display Student List";cout<<endl;cout<<"3. Add New Course";cout<<endl;cout<<"4. Display Course Offered";cout<<endl;cout<<"5. Modify Selected Student";cout<<endl;cout<<"6. Select Subject Taken and Display";cout<<endl<<endl;cout<<"Enter your choice (1/2/3/4/5/6) [0 to terminate] : ";cin>>choice;

if(choice == 1){

if(arrPtrPelajar[0].studentID == "" ){

for(int i=0 ; i<5 ; i++){

cout<<"Enter Student ID : ";cin>>ws;getline(cin , arrPtrPelajar[i].studentID);cout<<"Enter Student Name : ";getline(cin , arrPtrPelajar[i].studentName);cout<<"Enter Student Nick Name : ";getline(cin , arrPtrPelajar[i].studentNickName);cout<<endl;

Page 2: CSNB244 Lab5

}}

else{

cout<<"Register for Student is Full ";cout<<endl<<endl;cout<<"Press Any Key to Continue";getch();

}

system("cls");}

else if(choice == 3){

system("cls");if(arrPtrSubject[0].courseCode == ""){

for(int i=0 ; i<2 ; i++){

cout<<"Enter Course Code : ";cin>>ws;getline(cin , arrPtrSubject[i].courseCode);cout<<"Enter Course Name : ";getline(cin , arrPtrSubject[i].courseName);cout<<"Enter Lecturer Name : ";getline(cin , arrPtrSubject[i].courseLectureName);cout<<endl;

}}

else{

cout<<"Register for Course is Full ";cout<<endl<<endl;cout<<"Press Any Key to Continue";getch();

}

system("cls");}

else if(choice == 2){

system("cls");

for(int i=0 ; i<5 ; i++){

cout<<(i+1)<<"\tStudent ID : "<<arrPtrPelajar[i].studentID;

cout<<endl;cout<<"\tStudent Name : "<<arrPtrPelajar[i].studentName;cout<<endl;cout<<"\tStudent Nick Name :

"<<arrPtrPelajar[i].studentNickName;cout<<endl<<endl;

}

cout<<"Press Any Key to Continue";getch();system("cls");

}

Page 3: CSNB244 Lab5

else if(choice == 4){

for(int i=0 ; i<2 ; i++){

cout<<"Course Code : "<<arrPtrSubject[i].courseCode;cout<<endl;cout<<"Course Name : "<<arrPtrSubject[i].courseName;cout<<endl;cout<<"Lecturer Name :

"<<arrPtrSubject[i].courseLectureName;cout<<endl<<endl;

}

cout<<"Press Any Key to Continue";getch();

}

else if(choice == 5){

string studID;bool found = false;

cout<<"To adjust Student Name please enter Student ID : ";cin>>ws;getline(cin , studID);

for(int i=0 ; i<5 ; i++){

if(studID.compare(arrPtrPelajar[i].studentID)==0){

cout<<"Enter New Name : ";cin>>ws;getline(cin , arrPtrPelajar[i].studentName);cout<<"Enter New Nick Name : ";getline(cin , arrPtrPelajar[i].studentNickName);found = true ;break;

}}

if(found == false){

cout<<endl<<endl;cout<<"No Record Found ";cout<<endl<<endl;

}

cout<<"Press Any Key to Continue";getch();system("cls");

}

else if(choice == 6){

system("cls");int chooseSub;if(arrPtrPelajar[0].studentID != "" &&

arrPtrSubject[0].courseCode != "" && check == false){

Page 4: CSNB244 Lab5

cout<<"Subject Offered : 1."<<arrPtrSubject[0].courseCode;

cout<<endl;cout<<" :

2."<<arrPtrSubject[1].courseCode;cout<<endl<<endl;for(int i=0 ; i<5 ; i++){

cout<<"ID : "<<arrPtrPelajar[i].studentID;cout<<endl;cout<<"Subject Take ? (1/2) : ";cin>>chooseSub;

while(chooseSub != 1 && chooseSub != 2){

cout<<"Not Invalid !";cout<<"Please Enter (1/2) : ";cin>>chooseSub;if(chooseSub == 1 || chooseSub == 2){

break;}

}

if(chooseSub == 1 ){

arrPtrPelajar[i].subjectTaken = &arrPtrSubject[0];

}else if(chooseSub == 2){

arrPtrPelajar[i].subjectTaken = &arrPtrSubject[1];

}}

check = true ;}

else{

for(int i=0 ; i<5 ; i++){

cout<<"Student ID : "<<arrPtrPelajar[i].studentID;cout<<endl;cout<<"Student Name :

"<<arrPtrPelajar[i].studentName;cout<<endl;cout<<"Student Nick Name :

"<<arrPtrPelajar[i].studentNickName;cout<<endl;cout<<"Course Code :

"<<arrPtrPelajar[i].subjectTaken->courseCode;cout<<endl;cout<<"Course Name :

"<<arrPtrPelajar[i].subjectTaken->courseName;cout<<endl;cout<<"Lecture Name :

"<<arrPtrPelajar[i].subjectTaken->courseLectureName;cout<<endl<<endl;

}

cout<<"Press Any Key to Continue";getch();

Page 5: CSNB244 Lab5

system("cls");}

}

else if (choice != 0){

system("cls");

cout<<"Wrong Choice has been made :) " ;cout<<endl<<endl;

}

}while(choice != 0);}

Page 6: CSNB244 Lab5

system("cls");}

}

else if (choice != 0){

system("cls");

cout<<"Wrong Choice has been made :) " ;cout<<endl<<endl;

}

}while(choice != 0);}