Pages

12 Jun 2012

Cs304 3rd assignment solution spring 2012

In this assignment you have to code/implement the below said classes in running form these classes are,
  • User
  • Listener
  • Administrator

Now for implementing these three classes practically in c++ you have to define classes according to the requirements given below:

  1. Implement data members and member functions for each class
  2. Implement constructor and destructor for each class
  3. Implement setters and getters functions for each class
Implement different type of relations between these classes

//Topic class
class topic{ // Data members of Topic class
int ID;
char  * Title;
char discription[200];
//Public interface of topic class
public:
//Default constructor
topic(){
ID=1;
Title=NULL;
}
//parametrized constructor
topic(int id, char *title){
ID=id;
Title=new char[strlen(title)+1];
strcpy(Title,title);
}
//setter function for ID
void setId() {
int id;
cout<<”\nEnter ID: “;
cin>>id;
}


Solution

/* CRRETE LISTENER CLASS ON YOUR OWN
AND MAKE CHANGES ACCORDING TO THE REQUIRMENT*/
#include
#include
using namespace std;
//Topic class
class user{
// Data members of Topic class
int ID;
char * Naam;
//Public interface of topic class
public:
//Default constructor
user(){
ID=1;
Naam=NULL;
}
//parametrized constructor
user(int id, char *naam){
ID=id;
Naam=new char[strlen(naam)+1];
strcpy(Naam,naam);
}
//setter function for ID
void setId() {
int id;
cout<<"\nEnter ID: ";
cin>>id;
}
void setNaam() {
char pChar[50];
cout< cin.getline(pChar,50);
Naam=new char[strlen(pChar)+1];
strcpy(Naam,pChar);
}
int getId(){
return ID;
}
char * getNaam(){
return Naam;
}
void trackplay()
{
cout<<"\nplay track\n";
}
~user(){
}
};
class admin: public user
{
char pass;
public:
void setpass()
{
cout<<"enter password";
cin>>pass;
}
void trackadd()
{
cout<<“\nadd track\n”;
}
void trackdel()
{
cout<<“delete track”< }
void trackup()
{
cout<<“update track\n”;
}
void artistadd()
{
cout<<“add artist\n”;
}
void artistdel()
{
cout<<“del artsit\n”;
}
void albumadd()
{
cout<<“add album\n”;
}
void albumdel()
{
cout<<“album delete\n”;
}
void albumup()
{
cout<<“update album\n”;
}
void addmc()
{
cout<<“add mc\n”;
}
void delmc()
{
cout<<“del mc\n”;
}
void upmc()
{
cout<<“up mc\n”;
}
~admin()
{}
};
main()
{
user uo;
uo.setId();
uo.setNaam();
uo.trackplay();
admin ao;
ao.setpass();
ao.trackadd();
ao.trackdel();
ao.trackup();
ao.artistadd();
ao.artistdel();
ao.albumadd();
ao.albumdel();
ao.albumup();
ao.addmc();
ao.delmc();
ao.upmc();
system(“pause”);
}

0 comments:

Post a Comment