Subject Registration System Using OOP in C++

Assignment Quiz(class)

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 4808 Views - Last Post: 18 January 2006 - 07:31 AM Rate Topic: -----

Topic Sponsor:

#1 henry  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 96
  • Joined: 03-January 06

Subject Registration System Using OOP in C++

Post icon  Posted 14 January 2006 - 11:31 AM

The Question is like this...
about: Subject registration system.
The lecture want
1. Name, Matric Number, Cumulative Grade Percentage Average (CGPA)
CGPA........A=4.0,A-=3.7,B+=3.3,B=3.0,B-=3.7,C+=3.33,C=2.0, F=0.
Name, Matric No,CGPA key in by user. So no need to worried.
2.Condition for CGPA
if CGPA<2.0, can apply up to 18credit hours
if CGPA>2.0, can apply more then 18 credit hours
3.with this condition
the user will select the courses they wan to apply
4. After selected, The program will print out all the selected course that their are entered. [this part i Quite headache]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
THis is my source code:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#include <iostream.h>
#include <cstring>

class subject{
private:
char *name;
char *matric;
int cgpa;
char sub[14][100];
public:
subject(char * =" ",char * =" ",int=0);
~subject(){}
void setData(char * =" ",char * =" ",int=0);
void select();
void print();
};

subject::subject(char *temp1,char *temp2,int c)
{
name=new char [];
strcpy(name,temp1);
matric=new char[];
strcpy(matric,temp2);
cgpa=c;
sub[14][100]={
"GXEX1401 Kursus Kemahiran Maklumat", "1",
"GXEX1403 Titas Kertas 2","2",
"WRES1103 Rekabentuk Digital","3",
"WRES1201 Senibina Sistem Komputer", "3",
"WRES2101 Internet & Intranet", "3",
"WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek","3",
"WXES1112 Matematik Pengkomputeran 1","3"}
}

void subject::setData(char *temp1,char *temp2,int c)
{
name=new char [];
strcpy(name,temp1);
matric=new char[];
strcpy(matric,temp2);
cgpa=c;
sub[14][100]={
"GXEX1401 Kursus Kemahiran Maklumat", "1",
"GXEX1403 Titas Kertas 2","2",
"WRES1103 Rekabentuk Digital","3",
"WRES1201 Senibina Sistem Komputer", "3",
"WRES2101 Internet & Intranet", "3",
"WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek","3",
"WXES1112 Matematik Pengkomputeran 1","3"}
}

void subject::select()
{
cout<<"1.GXEX1401 Kursus Kemahiran Maklumat\t1\n"
<<"2.GXEX1403 Titas Kertas 2\t2\n"
<<"3.WRES1103 Rekabentuk Digital\t3\n"
<<"4.WRES1201 Senibina Sistem Komputer\t3\n"
<<"5.WRES2101 Internet & Intranet\t3\n"
<<"6.WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek\t3\n"
<<"7.WXES1112 Matematik Pengkomputeran 1\t3\n";
if (cgpa<=2.0)
{
int n,counter;
cout<<"You can select less than or equal to 18 credits hours:";
cin>>n;
counter=counter-sub[n+1];


}
else
cout<<"You can select more than 18 hours:";

}

void subject::print()
{
}

void main()
{
char n[20],m[10];
double c;
cout<<"Name:";
cin>>n;
cout<<"Matric number:";
cin>>m;
cout<<"CGPA:";
cin>>c;
}

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
This program still not completed. So give me some tips. Thank
This is urgent assignment
Are there have to use string,cstring, array,........or other
I need you quick reply
I am very appreciate it
Thank you :D

Is This A Good Question/Topic? 0
  • +

Replies To: Subject Registration System Using OOP in C++

#2 henry  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 96
  • Joined: 03-January 06

Re: Subject Registration System Using OOP in C++

Post icon  Posted 15 January 2006 - 01:13 AM

This is my improved code............
I think one day one night already
This code no ERROR but when execute it was blank with message you code have error at the middle side something like disappear) :huh:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#include <iostream.h>
#include <cstring>

class subject{
private:
char *name;
char *matric;
double cgpa;
int sub[10];
public:
subject(char * =" ",char * =" ",double=0);
~subject(){}
void setData(char * =" ",char * =" ",double=0);
void select();
void print();
};

subject::subject(char *temp1,char *temp2,double c)
{
name=new char [];
strcpy(name,temp1);
matric=new char[];
strcpy(matric,temp2);
cgpa=c;
for(int i;i<10;i++)
sub[i]=0;
}

void subject::setData(char *temp1,char *temp2,double c)
{
name=new char [];
strcpy(name,temp1);
matric=new char[];
strcpy(matric,temp2);
cgpa=c;
for(int i;i<10;i++)
sub[i]=0;
}

void subject::select()
{
if (cgpa<=2.0)
{
int i,credit=18;

cout<<"You can select less than or equal to 18 credits hours:\n";
do{
i++;
cout<<"Select your course:\n"
<<"1.GXEX1401 Kursus Kemahiran Maklumat\t1\n"
<<"2.GXEX1403 Titas Kertas 2\t2\n"
<<"3.WRES1103 Rekabentuk Digital\t3\n"
<<"4.WRES1201 Senibina Sistem Komputer\t3\n"
<<"5.WRES2101 Internet & Intranet\t3\n"
<<"6.WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek\t3\n"
<<"7.WXES1112 Matematik Pengkomputeran 1\t3\n"
<<"8.Exit\n";
cin>>sub[i];
switch(sub[i])
{
case 1:
credit-=1;
break;
case 2:
credit-=2;
break;
case 3:
credit-=3;
break;
case 4:
credit-=3;
break;
case 5:
credit-=3;
break;
case 6:
credit-=3;
break;
case 7:
credit-=3;
break;
case 8:
break;
}

}while( ( ( (sub[i])!=8) || (credit>=18) ) && !( ((sub[i])!=8) &&(credit>=18)));


}
else
{
cout<<"You can select more than 18 hours(Maximum=21):\n";
int i,credit=21;
cout<<"You can select less than or equal to 18 credits hours:";
do{
i++;
cout<<"Select your course:\n"
<<"1.GXEX1401 Kursus Kemahiran Maklumat\t1\n"
<<"2.GXEX1403 Titas Kertas 2\t2\n"
<<"3.WRES1103 Rekabentuk Digital\t3\n"
<<"4.WRES1201 Senibina Sistem Komputer\t3\n"
<<"5.WRES2101 Internet & Intranet\t3\n"
<<"6.WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek\t3\n"
<<"7.WXES1112 Matematik Pengkomputeran 1\t3\n"
<<"8.Exit\n";
cin>>sub[i];
switch(sub[i])
{
case 1:
credit-=1;
break;
case 2:
credit-=2;
break;
case 3:
credit-=3;
break;
case 4:
credit-=3;
break;
case 5:
credit-=3;
break;
case 6:
credit-=3;
break;
case 7:
credit-=3;
break;
case 8:
break;
}

}while( ( ( (sub[i])!=8) || (credit>=21) ) && !( ((sub[i])!=8) &&(credit>=21)));
}

}

void subject::print()
{
cout<<"Your Subject Registered:\n";
for(int i=0;i<10;i++)
{
switch(sub[i])
{
case 1:
cout<<"GXEX1401 Kursus Kemahiran Maklumat\t1\n";
break;
case 2:
cout<<"GXEX1403 Titas Kertas 2\t2\n";
break;
case 3:
cout<<"WRES1103 Rekabentuk Digital\t3\n";
break;
case 4:
cout<<"WRES1201 Senibina Sistem Komputer\t3\n";
break;
case 5:
cout<<"WRES2101 Internet & Intranet\t3\n";
break;
case 6:
cout<<"WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek\t3\n";
break;
case 7:
cout<<"WXES1112 Matematik Pengkomputeran 1\t3\n";
break;
case 8:
break;
}
}
cout<<"Thank you";
}

void main()
{
subject obj;
char n[20],m[10];
double c;
cout<<"Name:";
cin>>n;
cout<<"Matric number:";
cin>>m;
cout<<"CGPA:";
cin>>c;
obj.setData(n,m,c);
obj.select();
obj.print();

}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
I need you urgent answer.....
Who out there can help me no matter how expert you are
I appreciate your help
Thank you :D
Was This Post Helpful? 0
  • +
  • -

#3 henry  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 96
  • Joined: 03-January 06

Re: Subject Registration System Using OOP in C++

Post icon  Posted 15 January 2006 - 07:01 AM

I make some correction already (a bit)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#include <iostream.h>
#include <cstring>

class subject{
private:
char *name;
char *matric;
double cgpa;
int sub[10];
public:
subject(char * =" ",char * =" ",double=0);
~subject(){}
void setData(char * =" ",char * =" ",double=0);
void select();
void print();
};

subject::subject(char *temp1,char *temp2,double c)
{
name=new char [];
strcpy(name,temp1);
matric=new char[];
strcpy(matric,temp2);
cgpa=c;
for(int i;i<10;i++)
sub[i]=0;
}

void subject::setData(char *temp1,char *temp2,double c)
{
name=new char [];
strcpy(name,temp1);
matric=new char[];
strcpy(matric,temp2);
cgpa=c;
for(int i;i<10;i++)
sub[i]=0;
}

void subject::select()
{
if (cgpa<=2.0)
{
int i,credit=18;

cout<<"You can select less than or equal to 18 credits hours:\n";
do{
i++;
cout<<"Select your course:\n"
<<"1.GXEX1401 Kursus Kemahiran Maklumat\t1\n"
<<"2.GXEX1403 Titas Kertas 2\t2\n"
<<"3.WRES1103 Rekabentuk Digital\t3\n"
<<"4.WRES1201 Senibina Sistem Komputer\t3\n"
<<"5.WRES2101 Internet & Intranet\t3\n"
<<"6.WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek\t3\n"
<<"7.WXES1112 Matematik Pengkomputeran 1\t3\n"
<<"8.Exit\n";
cin>>sub[i];
switch(sub[i])
{
case 1:
credit-=1;
break;
case 2:
credit-=2;
break;
case 3:
credit-=3;
break;
case 4:
credit-=3;
break;
case 5:
credit-=3;
break;
case 6:
credit-=3;
break;
case 7:
credit-=3;
break;
case 8:
break;
}

}while( ( (sub[i])!=8) || (credit>=18) );// Here only i modify


}
else
{
cout<<"You can select more than 18 hours(Maximum=21):\n";
int i,credit=21;
cout<<"You can select less than or equal to 18 credits hours:";
do{
i++;
cout<<"Select your course:\n"
<<"1.GXEX1401 Kursus Kemahiran Maklumat\t1\n"
<<"2.GXEX1403 Titas Kertas 2\t2\n"
<<"3.WRES1103 Rekabentuk Digital\t3\n"
<<"4.WRES1201 Senibina Sistem Komputer\t3\n"
<<"5.WRES2101 Internet & Intranet\t3\n"
<<"6.WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek\t3\n"
<<"7.WXES1112 Matematik Pengkomputeran 1\t3\n"
<<"8.Exit\n";
cin>>sub[i];
switch(sub[i])
{
case 1:
credit-=1;
break;
case 2:
credit-=2;
break;
case 3:
credit-=3;
break;
case 4:
credit-=3;
break;
case 5:
credit-=3;
break;
case 6:
credit-=3;
break;
case 7:
credit-=3;
break;
case 8:
break;
}

}while(( (sub[i])!=8) || (credit>=21) );// Here i modify
}

}

void subject::print()
{
cout<<"Your Subject Registered:\n";
for(int i=0;i<10;i++)
{
switch(sub[i])
{
case 1:
cout<<"GXEX1401 Kursus Kemahiran Maklumat\t1\n";
break;
case 2:
cout<<"GXEX1403 Titas Kertas 2\t2\n";
break;
case 3:
cout<<"WRES1103 Rekabentuk Digital\t3\n";
break;
case 4:
cout<<"WRES1201 Senibina Sistem Komputer\t3\n";
break;
case 5:
cout<<"WRES2101 Internet & Intranet\t3\n";
break;
case 6:
cout<<"WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek\t3\n";
break;
case 7:
cout<<"WXES1112 Matematik Pengkomputeran 1\t3\n";
break;
case 8:
break;
}
}
cout<<"Thank you";
}

void main()
{
subject obj;
char n[20],m[10];
double c;
cout<<"Name:";
cin>>n;
cout<<"Matric number:";
cin>>m;
cout<<"CGPA:";
cin>>c;
obj.setData(n,m,c);
obj.select();
obj.print();

}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
The modify staff not effected my just now Question
So pls help me................ :rolleyes:
Was This Post Helpful? 0
  • +
  • -

#4 henry  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 96
  • Joined: 03-January 06

Re: Subject Registration System Using OOP in C++

Posted 16 January 2006 - 07:01 AM

:P Help help
I need a fast reply
Thank you................
Was This Post Helpful? 0
  • +
  • -

#5 Jessehk  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 24
  • Joined: 06-January 06

Re: Subject Registration System Using OOP in C++

Posted 16 January 2006 - 03:40 PM

Code is virtually impossible to read when there is no indenting...
Was This Post Helpful? 0
  • +
  • -

#6 bluesuus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 61
  • Joined: 26-December 05

Re: Subject Registration System Using OOP in C++

Posted 16 January 2006 - 04:58 PM

first of all ill indicate the parts of code i fixed and then the complete program is at the end.NOTE that i did not run the complete code, i compiled it online using Comeau C/C++ 4.3.3 online compiler( which is found on http://www.comeaucom...g.com/tryitout/ ) and didnt get any errors.

Mistakes
why are you using pointers for thew name and matric, make them strings, ur new class declaration should be
class subject{
private:
string name;
string matric;
double cgpa;
int sub[10];
public:
subject();
~subject(){}
void setData(string n, string matr, double gpa);
void select();
void print();
};



ur constructor shud be
subject::subject()
{
name = " ";
matric = " ";
cgpa=0.0;
for(int i;i<10;i++)
sub[i]=0;
}



ur setData() shud be

void subject::setData(string n, string matr, double gpa)
{
name = n;
matric = matr;
cgpa=gpa;
}


in ur select() function, first of all ur variables i and credit should be initialised to zero. and in the the switch statemnt credit variable shud be incremented not decremented.

void subject::select()
{
if (cgpa<=2.0)
{
int i=0,credit=0;

cout<<"You can select less than or equal to 18 credits hours:\n";
do{

cout<<"Select your course:\n"
<<"1.GXEX1401 Kursus Kemahiran Maklumat\t1\n"
<<"2.GXEX1403 Titas Kertas 2\t2\n"
<<"3.WRES1103 Rekabentuk Digital\t3\n"
<<"4.WRES1201 Senibina Sistem Komputer\t3\n"
<<"5.WRES2101 Internet & Intranet\t3\n"
<<"6.WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek\t3\n"
<<"7.WXES1112 Matematik Pengkomputeran 1\t3\n"
<<"8.Exit\n";
cin>>sub[i];
switch(sub[i])
{
case 0:
credit+=1;
break;
case 1:
credit+=2;
break;
case 2:
credit+=3; 
break;
case 3:
credit+=3;
break;
case 4:
credit+=3;
break;
case 5:
credit+=3;
break;
case 6:
credit+=3;
break;
case 7:
break;
}

i++;

}while(  credit<=18 );

else
{ 
cout<<"You can select more than 18 hours(Maximum=21):\n";
int i=0,credit=0;
cout<<"You can select less than or equal to 18 credits hours:";
do{

cout<<"Select your course:\n"
<<"1.GXEX1401 Kursus Kemahiran Maklumat\t1\n"
<<"2.GXEX1403 Titas Kertas 2\t2\n"
<<"3.WRES1103 Rekabentuk Digital\t3\n"
<<"4.WRES1201 Senibina Sistem Komputer\t3\n"
<<"5.WRES2101 Internet & Intranet\t3\n"
<<"6.WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek\t3\n"
<<"7.WXES1112 Matematik Pengkomputeran 1\t3\n"
<<"8.Exit\n";
cin>>sub[i];
switch(sub[i])
{
case 0:
credit+=1;
break;
case 1:
credit+=2;
break;
case 2:
credit+=3; 
break;
case 3:
credit+=3;
break;
case 4:
credit+=3;
break;
case 5:
credit+=3;
break;
case 6:
credit+=3;
break;
case 7:
break;
}

}while(credit<=21) );// Here i modify
}

}


and ur main should be
void main()
{
subject obj;
string n, m;
double c;
cout<<"Name:";
cin>>n;
cout<<"Matric number:";
cin>>m;
cout<<"CGPA:";
cin>>c;
obj.setData(n,m,c);
obj.select();
obj.print();

}



okay here is the complete code
#include <iostream>
#include <string>

using namespace std;

class subject{
private:
string name;
string matric;
double cgpa;
int sub[10];
public:
subject();
~subject(){}
void setData(string n, string matr, double gpa);
void select();
void print();
};
subject::subject()
{
name = " ";
matric = " ";
cgpa=0.0;
for(int i = 0;i<10;i++)
sub[i]=0;
}

void subject::setData(string n, string matr, double gpa)
{
name = n;
matric = matr;
cgpa=gpa;
}

void subject::select()
{
if (cgpa<=2.0)
{
int k=0,credit=0;

cout<<"You can select less than or equal to 18 credits hours:\n";
do{

cout<<"Select your course:\n"
<<"1.GXEX1401 Kursus Kemahiran Maklumat\t1\n"
<<"2.GXEX1403 Titas Kertas 2\t2\n"
<<"3.WRES1103 Rekabentuk Digital\t3\n"
<<"4.WRES1201 Senibina Sistem Komputer\t3\n"
<<"5.WRES2101 Internet & Intranet\t3\n"
<<"6.WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek\t3\n"
<<"7.WXES1112 Matematik Pengkomputeran 1\t3\n"
<<"8.Exit\n";
cin>>sub[k];
switch(sub[k])
{
case 0:
credit+=1;
break;
case 1:
credit+=2;
break;
case 2:
credit+=3; 
break;
case 3:
credit+=3;
break;
case 4:
credit+=3;
break;
case 5:
credit+=3;
break;
case 6:
credit+=3;
break;
case 7:
break;
}

k++;

}while(  credit<=18 );
}
else
{ 
cout<<"You can select more than 18 hours(Maximum=21):\n";
int k=0,credit=0;
cout<<"You can select less than or equal to 18 credits hours:";
do{

cout<<"Select your course:\n"
<<"1.GXEX1401 Kursus Kemahiran Maklumat\t1\n"
<<"2.GXEX1403 Titas Kertas 2\t2\n"
<<"3.WRES1103 Rekabentuk Digital\t3\n"
<<"4.WRES1201 Senibina Sistem Komputer\t3\n"
<<"5.WRES2101 Internet & Intranet\t3\n"
<<"6.WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek\t3\n"
<<"7.WXES1112 Matematik Pengkomputeran 1\t3\n"
<<"8.Exit\n";
cin>>sub[k];
switch(sub[k])
{
case 0:
credit+=1;
break;
case 1:
credit+=2;
break;
case 2:
credit+=3; 
break;
case 3:
credit+=3;
break;
case 4:
credit+=3;
break;
case 5:
credit+=3;
break;
case 6:
credit+=3;
break;
case 7:
break;
}
k++;
}while(credit<=21 );
}

}
void subject::print()
{
cout<<"Your Subject Registered:\n";
for(int j=0;j<10;j++)
{
switch(sub[j])
{
case 0:
cout<<"GXEX1401 Kursus Kemahiran Maklumat\t1\n";
break;
case 1:
cout<<"GXEX1403 Titas Kertas 2\t2\n";
break;
case 2:
cout<<"WRES1103 Rekabentuk Digital\t3\n";
break;
case 3:
cout<<"WRES1201 Senibina Sistem Komputer\t3\n";
break;
case 4:
cout<<"WRES2101 Internet & Intranet\t3\n";
break;
case 5:
cout<<"WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek\t3\n";
break;
case 6:
cout<<"WXES1112 Matematik Pengkomputeran 1\t3\n";
break;
case 7:
break;
}
}
cout<<"Thank you";
}
int main()
{
subject obj;
string n, m;
double c;
cout<<"Name:";
getline(cin,n);
cout<<"Matric number:";
getline(cin,m);
cout<<"CGPA:";
cin>>c;
obj.setData(n,m,c);
obj.select();
obj.print();
return 0;
}


This post has been edited by bluesuus: 16 January 2006 - 10:23 PM

Was This Post Helpful? 0
  • +
  • -

#7 henry  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 96
  • Joined: 03-January 06

Re: Subject Registration System Using OOP in C++

Post icon  Posted 16 January 2006 - 08:24 PM

Thank you bluesus.....
Love you.......
Where you stay?
When you regularly online?
I maybe need your help some more?
Silly guy like me need more help
Haha.... :P
Thank bluesus!!
Was This Post Helpful? 0
  • +
  • -

#8 henry  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 96
  • Joined: 03-January 06

Re: Subject Registration System Using OOP in C++

Post icon  Posted 16 January 2006 - 08:40 PM

It still have problem....
If I input name such as Henry Rocky Loke
It consider
Henry as Name
Rocky ask Matric Number
Loke as CGPA
It will crazy printing
Then stop
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
string can input white space or not? :huh:
That why I use *(pointer) with dynamic array
because can input white space.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Who out there can answer my question and modify my answer. ;)
Thank you
Smile.... :P
Was This Post Helpful? 0
  • +
  • -

#9 bluesuus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 61
  • Joined: 26-December 05

Re: Subject Registration System Using OOP in C++

Posted 16 January 2006 - 10:21 PM

henry if u wana input a name containing spaces u use this getline() function, i have modified my code to use those so no problem


NOTE: The only lines i modified in the code are located in the main function

i changed
cin >> n                to              getline( cin, n );

and also i changed
cin >> m              to             getline(cin, m );




so now the program will work as you want it to.Thank you

This post has been edited by bluesuus: 16 January 2006 - 10:25 PM

Was This Post Helpful? 0
  • +
  • -

#10 henry  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 96
  • Joined: 03-January 06

Re: Subject Registration System Using OOP in C++

Post icon  Posted 17 January 2006 - 02:09 AM

If do so
when we enter the input
Name: Loke foo kit //press enter
//press enter
No Matrik: wek11111//press enter
//press enter
cgpa:2.0 //press enter
//press enter
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
We should press enter many time!!!!
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Other is problem occur when the user only registter only one course.
Then he enter 8(exit)
The Result prompt out twice!!!
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
I need your help!!!
Was This Post Helpful? 0
  • +
  • -

#11 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 170
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: Subject Registration System Using OOP in C++

Posted 17 January 2006 - 06:58 AM

henry, on 15 Jan, 2006 - 08:28 PM, said:

switch(sub[i])
{
case 1:
credit-=1;
break;
case 2:
credit-=2;
break;
case 3:
credit-=3;
break;
case 4:
credit-=3;
break;
case 5:
credit-=3;
break;
case 6:
credit-=3;
break;
case 7:
credit-=3;
break;
case 8:
break;
}

Since bluesuus pointed out what you should do, you can try this out too.
I noticed your switch statements perform the action credit-=3 a lot often for various values for subjects.
It takes up loads of lines and really spoils readability as Jessehk mentioned.
Use if statements and combine conditions like this to improve readability:
if(sub[i] >= 3 && sub[i] <=7)
      credit-=3;

Or you can use the case else clause to account for the cases after 2. But beware for value 8 though.

Improving readability has a lot of advantages.
One of them being that others enjoy reading your code [and helping you out eventually too :) ]

Cheers.

This post has been edited by born2c0de: 17 January 2006 - 06:58 AM

Was This Post Helpful? 0
  • +
  • -

#12 dorknexus  Icon User is online

  • or something bad...real bad.
  • member icon

Reputation: 1061
  • View blog
  • Posts: 4,510
  • Joined: 02-May 04

Re: Subject Registration System Using OOP in C++

Posted 17 January 2006 - 10:25 AM

Please remember that the point of this forum is to learn, and posting in code and code alone helps very little with that learning experience. It is preferred that replies explain why something is incorrect and then perhaps use a piece of code to show proper syntax and so on.

DO NOT simply fix someone's code and then repost it. Although this does technically answer one's question, there is no correspondence for future reference (which is a major purpose of the community).

If you're code is lengthy please attach it to the post as a file. and in either case, file or not, code should be properly indented and placed in the code tags

Feed me!!


if you are not sure how to do this you can contact a moderator+ and we will be more than happy to assist.

It is imperative that new members read the rules for a particular forum before they make a post to make the process as streamlined as possible.

C/C++ forum rules
DIC Forum rules (Community guidelines and procedures)
Was This Post Helpful? 0
  • +
  • -

#13 henry  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 96
  • Joined: 03-January 06

Re: Subject Registration System Using OOP in C++

Post icon  Posted 17 January 2006 - 12:30 PM

I really need your help
I still have one more day to hand up the assignment.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Problem 1: :blink:
Why the user should enter twice "enter", then the second question print out?
e.g
Name:Tommy Thank //press enter
//press enter
No.Matric:WEk050050 //press enter
//press enter
CGPA: 2.9 //press enter
//press enter

If you are user u will feel the program is spoil!
If he didn't enter second press.
How to avoid it?
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Question 2: :blink:
when i enter only 1 courses to register then the user enter integer 8 mean want to exit
The print() is printed
But the do while looping is still on?
How to break it!!!!!!
Stupid looping!!!! :angry:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Question 3 :blink:
I still not quite sure this condition
while( credit<18 || sub[k]==8);
If worry can you all fix it
Thank you
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
This is my source code after modify
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#include <iostream>
#include <string>

using namespace std;

class subject{
private:
string name;
string matric;
double cgpa;
int k;
int sub[10];
public:
subject();
~subject(){}
void setData(string n, string matr, double gpa);
void select();
void print();
};
subject::subject()
{
k=0;
name = " ";
matric = " ";
cgpa=0.0;
for(int i = 0;i<10;i++)
sub[i]=0;
}

void subject::setData(string n, string matr, double gpa)
{
name = n;
matric = matr;
cgpa=gpa;

}

void subject::select()
{
if (cgpa<=2.0)
{
int credit=0;

cout<<"You can select less than or equal to 18 credits hours:\n";


do{
cout<<"Select your course:\n"
<<"1.GXEX1401 Kursus Kemahiran Maklumat\t1\n"
<<"2.GXEX1403 Titas Kertas 2\t2\n"
<<"3.WRES1103 Rekabentuk Digital\t3\n"
<<"4.WRES1201 Senibina Sistem Komputer\t3\n"
<<"5.WRES2101 Internet & Intranet\t3\n"
<<"6.WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek\t3\n"
<<"7.WXES1112 Matematik Pengkomputeran 1\t3\n"
<<"8.Exit\n";
cin>>sub[k];
switch(sub[k])
{
case 1:
credit+=1;
break;
case 2:
credit+=2;
break;
case 3:
credit+=3;
break;
case 4:
credit+=3;
break;
case 5:
credit+=3;
break;
case 6:
credit+=3;
break;
case 7:
credit+=3;
break;
case 8:
print();
break;
}

k++;

}while( credit<18 || sub[k]==8);
}
else if (cgpa>2.0)
{
cout<<"You can select more than 18 hours(Maximum=21):\n";
int credit=0;
cout<<"You can select less than or equal to 18 credits hours:";
do{

cout<<"Select your course:\n"
<<"1.GXEX1401 Kursus Kemahiran Maklumat\t1\n"
<<"2.GXEX1403 Titas Kertas 2\t2\n"
<<"3.WRES1103 Rekabentuk Digital\t3\n"
<<"4.WRES1201 Senibina Sistem Komputer\t3\n"
<<"5.WRES2101 Internet & Intranet\t3\n"
<<"6.WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek\t3\n"
<<"7.WXES1112 Matematik Pengkomputeran 1\t3\n"
<<"8.Exit\n";
cin>>sub[k];
switch(sub[k])
{
case 1:
credit+=1;
break;
case 2:
credit+=2;
break;
case 3:
credit+=3;
break;
case 4:
credit+=3;
break;
case 5:
credit+=3;
break;
case 6:
credit+=3;
break;
case 7:
credit+=3;
break;
case 8:
print();
break;
}
k++;
}while(credit<21 || sub[k]==8 );
}

}
void subject::print()
{
cout<<"Name:"<<name<<endl;
cout<<"Number Matric:"<<matric<<endl;
cout<<"CGPA:"<<cgpa<<endl;
cout<<"Your Subject Registered:\n";
for(int j=0;j<k;j++)
{
switch(sub[j])
{
case 1:
cout<<"GXEX1401 Kursus Kemahiran Maklumat\t1\n";
break;
case 2:
cout<<"GXEX1403 Titas Kertas 2\t2\n";
break;
case 3:
cout<<"WRES1103 Rekabentuk Digital\t3\n";
break;
case 4:
cout<<"WRES1201 Senibina Sistem Komputer\t3\n";
break;
case 5:
cout<<"WRES2101 Internet & Intranet\t3\n";
break;
case 6:
cout<<"WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek\t3\n";
break;
case 7:
cout<<"WXES1112 Matematik Pengkomputeran 1\t3\n";
break;
}
}
cout<<"Thank you\n";
}
int main()
{
subject obj;
string n, m;
double c;
cout<<"Name:";
getline(cin,n);
cin.ignore();
cout<<"Matric number:";
getline(cin,m);
cin.ignore();
cout<<"CGPA:";
cin>>c;
obj.setData(n,m,c);
obj.select();
obj.print();
return 0;
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
I really need a fast respond
I need your cooperation
Please don't be cruel see me die......(in final mark) :huh:
Thank you
Smile :D
Was This Post Helpful? 0
  • +
  • -

#14 henry  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 96
  • Joined: 03-January 06

Re: Subject Registration System Using OOP in C++

Post icon  Posted 17 January 2006 - 12:53 PM

Question 5
-------------
Where to print() at the Function select()
if put after else:
probability will happen:
1. User enter 1 course only then exit
It will looping and print out twice
2.It save when the user register equal to his credit hours

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Then how to put?
Where to put it?
difficult la :P
Thank you
Was This Post Helpful? 0
  • +
  • -

#15 bluesuus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 61
  • Joined: 26-December 05

Re: Subject Registration System Using OOP in C++

Posted 17 January 2006 - 03:54 PM

hey henry, i now understand the problem.The program is now working as i have tested it myself.The modified is below but pls take ur tym and go thru all the correction and explanation i did

coorection and exlanation
remove the cin.ignore() functions and the user of ur program will not hve to press enter twice.

correction and explanation
the reason why it keeps on looping even if u press 8 is because of your while condition.

ur while condition is like this
while( credit < 18 || sub[k]==8 )

what that means is if one test is true the loop shud contnue, so even if u press 8 the loop checks the credit condition which is still less than 18 and finds it to be true, so it will go in the loop again.

the correct version shud be

while( credit < 18 && sub[k]!=8 )

what this while loop is doing is to check that all conditions are satisfied, if either one is false the loop body will not be entered

correction and explanation
i have made a small change to ur switch statements by removing K++ and putting it in all the cases and also i removed case 8 in the program as the while condition is performing that task

correction and explanation
the reason why it prints twice was because in your case 8 u r calling the print() function and also u r calling it again in the main function, that is why it prints twice.So i removed the case8 and now only the print() in the main function executes


complete working program[SIZE=7]

#include <iostream>
#include <string>

using namespace std;

class subject{
private:
string name;
string matric;
double cgpa;
int k;

int sub[8];
public:
subject();
~subject(){}
void setData(string n, string matr, double gpa);
void select();
void print();
};
subject::subject()
{
k=0;
name = " ";
matric = " ";
cgpa=0.0;
for(int i = 0;i<8;i++)
sub[i]=0;
}

void subject::setData(string n, string matr, double gpa)
{
name = n;
matric = matr;
cgpa=gpa;

}

void subject::select()
{
if (cgpa<=2.0)
{
int credit=0;

cout<<"You can select less than or equal to 18 credits hours:\n";


do{
cout<<"Select your course:\n"
<<"1.GXEX1401 Kursus Kemahiran Maklumat\t1\n"
<<"2.GXEX1403 Titas Kertas 2\t2\n"
<<"3.WRES1103 Rekabentuk Digital\t3\n"
<<"4.WRES1201 Senibina Sistem Komputer\t3\n"
<<"5.WRES2101 Internet & Intranet\t3\n"
<<"6.WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek\t3\n"
<<"7.WXES1112 Matematik Pengkomputeran 1\t3\n"
<<"8.Exit\n";
cin>>sub[k];

switch(sub[k])
{
case 1:
credit+=1;
k++;
break;
case 2:
credit+=2;
k++;
break;
case 3:
credit+=3;
k++;
break;
case 4:
credit+=3;
k++;
break;
case 5:
credit+=3;
k++;
break;
case 6:
credit+=3;
k++;
break;
case 7:
credit+=3;
k++;
break;

}


}while( credit<18 && sub[k]!=8);

}
else if (cgpa>2.0)
{ 
cout<<"You can select more than 18 hours(Maximum=21):\n";
int credit=0;
cout<<"You can select less than or equal to 18 credits hours:";
do{

cout<<"Select your course:\n"
<<"1.GXEX1401 Kursus Kemahiran Maklumat\t1\n"
<<"2.GXEX1403 Titas Kertas 2\t2\n"
<<"3.WRES1103 Rekabentuk Digital\t3\n"
<<"4.WRES1201 Senibina Sistem Komputer\t3\n"
<<"5.WRES2101 Internet & Intranet\t3\n"
<<"6.WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek\t3\n"
<<"7.WXES1112 Matematik Pengkomputeran 1\t3\n"
<<"8.Exit\n";
cin>>sub[k];
switch(sub[k])
{
case 1:
credit+=1;
k++;
break;
case 2:
credit+=2;
k++;
break;
case 3:
credit+=3;
k++;
break;
case 4:
credit+=3;
k++;
break;
case 5:
credit+=3;
k++;
break;
case 6:
credit+=3;
k++;
break;
case 7:
credit+=3;
k++;
break;
}

}while(credit<21 && sub[k]!=8 );
}

}
void subject::print()
{
cout<<"Name:"<<name<<endl;
cout<<"Number Matric:"<<matric<<endl;
cout<<"CGPA:"<<cgpa<<endl;
cout<<"Your Subject Registered:\n";
for(int j=0;j < k;j++)
{
switch(sub[j])
{
case 1:
cout<<"GXEX1401 Kursus Kemahiran Maklumat\t1\n";
break;
case 2:
cout<<"GXEX1403 Titas Kertas 2\t2\n";
break;
case 3:
cout<<"WRES1103 Rekabentuk Digital\t3\n";
break;
case 4:
cout<<"WRES1201 Senibina Sistem Komputer\t3\n";
break;
case 5:
cout<<"WRES2101 Internet & Intranet\t3\n";
break;
case 6:
cout<<"WXES1111 Prinsip Pengaturcaraan Berorientasikan Objek\t3\n";
break;
case 7:
cout<<"WXES1112 Matematik Pengkomputeran 1\t3\n";
break;
}
}
cout<<"Thank you\n";
}
int main()
{
subject obj;
string n, m;
double c;
cout<<"Name:";
getline(cin,n);
//cin.ignore();
cout<<"Matric number:";
getline(cin,m);
//cin.ignore();
cout<<"CGPA:";
cin>>c;
obj.setData(n,m,c);
obj.select();
obj.print();
return 0;
}



Good luck
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2