https://www.google.com/contributor/welcome/?utm_source=publisher&utm_medium=banner&utm_campaign=2376261057261409

Search This Blog

Search with our Site

Custom Search

Sunday, January 8, 2012

CS304 Assignment No 4 Solution & Discussion Due Date: 12-01-2012


Object Oriented Programming (CS304)

Assignment No.04


Total Marks                                                                                                                       10


Deadline


Your assignment must be uploaded before or on 12th January, 2012.

Rules for Making


It should be clear that your assignment will not get any credit if:

o                   The assignment is submitted after due date
o                   The assignment is copied

Objectives


This assignment has been designed so that you would be able to implement the concept of Inheritance in OOP. After the completion of this assignment you should have a good grasp on how to implement.

o                   Setters and getter member functions
o                   Multilevel inheritance
o                   Polymorphism
o                   Using basic constructs of OOP in a program


In previous assignments we have understood all the basics of the Electronic Card System including the Object Model Diagram and highlighted the Abstraction of classes in terms of attributes and functions prototype. In 3rd assignment we implement different classes that are related to Users of Electronic Card System. Now in this assignment we are going to implement different classes that are related to Cards of Electronic Card System.

Assignment:














Object Model for 4th Assignment:


Mehindi Cards
 

 
DisplayCards()

 



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

·         Cards
·         Birth Cards
·         Marriage Cards
·         Friendship Cards
·         Mehindi Cards
·         Walima Cards
·         Baraat Cards

Meaning after completion of this assignment your c++ program will be able to

1.       How to implement data members and member function
2.       How to implement constructor and destructor
3.       How to implement setters and getters
4.       How to make an abstract class
5.       How to display cards information

Now for implementing these seven classes practically in c++, you have to define classes according to the following requirements:

  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
  4. Make Cards class as an abstract class
  5. Implement the given class hierarchy in C++


Override the “DisplayCards()” method in the derived classes (MarriageCards, BirthCards, FriendshipCards ), such that:

In the main () function, when we call “DisplayCards ()” method by “BirthCards” object, it displays:

“You are now going to see the Birth Cards”

When we call “DisplayCards ()” method by “MarriageCards” object, it displays:

“You are now going to see the Marriage Cards”


When we call “DisplayCards ()” method by “FriendshipCards” object, it displays:

“You are now going to see the Friendship Cards”


Also in main() function, Polymorphically called the “DisplayCards()” function, such that:


If we call “DisplayCards()” method by “MarriageCards” reference. And through that reference call the overloaded constructor of “Mehindi class”, then it displays:

ID=123
Name=ABC
“You are now going to see the Mehindi Cards”


If we call “DisplayCards()” method by “MarriageCards” reference. And through that reference call the overloaded constructor of “Baraat class”, then it displays:

ID=345
Name=XYZ
“You are now going to see the Baraat Cards”

If we call “DisplayCards()” method by “MarriageCards” reference. And through that reference call the overloaded constructor of “Mehindi class”, then it displays::

ID=789
Name=PQR
“You are now going to see the Walima Cards”

Note:

User defined default constructor, and overloaded constructor for each class is required.

Where id and name are the user given values, which are passed to the overloaded constructor of MehindiCards, BaraatCards, and WalimaCards.

In this assignment polymorphism is achieved at the 3rd level (in the given hierarchy), if we want to implement the polymorphism in the 2nd level (MarriageCards, BirthCards, FriendshipCards), then is it possible in the given scenario? If possible, then on what conditions it is possible. Just describe in 2 to 3 lines, no need to implement in coding.



                                                                                                                     


Sample Example of data members and member functions, constructor, destructor, setters and getters:

//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;
      }

       
    void setTitle() {
     char pChar[50];
     cout<<endl<<"\nEnter Title: ";
     cin.getline(pChar,50);
     Title=new char[strlen(pChar)+1];
     strcpy(Title,pChar);
       }   

    void setTitle(char * title){
        Title=title;
        }
       
    void setdiscription(){
        cout<<"\nplease enter discription of title"<<endl;
        cin.getline(discription,200);
        }


    int getId(){
     return ID;
     }
    
    char * getTitle(){
       return Title;
       }
       
    void add(){
        cout<<"\n*****************************************\n";
        cout<<"\nAdding new information in add method";
        setTitle();
        setdiscription();
        cout<<"\n*****************************************\n"; 
        }
   
   bool select(){
        cout<<"Topic selection Area:"<<endl;
        int select;
        if (select==1)
        cout<<"\nTopic is selected"<<endl;
        else
        cout<<"\nTopic is not selected"<<endl;
        }

    int search(){
        cout<<"In Search Mehtod:"<<endl;
       int found=0;
       if (found)
                        return 1;
               else
                        return 0;
                        }                     

    void View() {
        cout<<"Viewing the Information";
        cout<<"\n*****************************************\n";
        cout<<"\nTitle is:"<< Title ;
        cout<<endl<<"\nDescription is:"<<discription[100];
        cout<<"\n*****************************************\n";
        }
           
    void print(){
        cout<<"\n*****************************************\n";
        cout<<endl<<"\nPrinting the Information:"<<endl;
        cout<<"Title:"<<Title<<endl<<"Discription:"<<discription;
        cout<<"\n*****************************************\n"; 
          }
         
    void download(){
        cout<<"\n*****************************************\n";
        cout<<"\nDownloading the information:"<<endl;
        cout<<"Downloading under processing, Please wait:"<<endl;
        cout<<"You are downloding the following:"<<endl<<Title<<"file";
        cout<<" and the following discription"<<endl<<discription<<"File";
        cout<<"\n*****************************************\n";
       
        }
       
    void remove(){
        cout<<"\n*****************************************\n";
        cout<<"\nDeleting the information"<<endl;
        cout<<"\n*****************************************\n";
        delete []Title;
        delete [] discription;
         }

    ~topic(){
       
        }
    };
   

      
class SubTopic: public topic {  
     int SubID;
     char * title;
     char discription[100];

     public:
   
         void setSubID(){
             int subid;
             cout<<"Enter ID of Sub topic:";
             cin>>subid;
             }
                
         void setdiscription(char []){
             char dChar[200];
             cout<<"Enter discription of Sub topic:"<<endl;
             cin.getline(dChar,200,'\n');
             }
            
         int getSubID(){
             return SubID;
             }
            
        void setTitle(){
             char pChar[50];
             char dChar[200];
             cout<<endl<<"Enter Title : ";
             cin.getline(pChar,50);
             cout<<endl<<"Enter Title discription:";
             cin.getline(dChar,200);
             if(strlen(dChar)>=90){
             cout<<"Eligible for being a topic"<<endl;
             }
             else
             {
             cout<<"Title just contains name and no description"<<endl;
             }
             }
       
         ~SubTopic(){
            
            
             }
   
    };

How to make an abstract class:

class Shape {
           
public:
            virtual void draw() = 0;
}



Polymorphically calling in main() function:

int main(){
Shape* _shape = new Line();
_shape->draw();
Shape* _shape = new Line();
_shape->draw();
system(“pause”);
}

Important Note:

This assignment is only based on “Cards” (data members, constructor/ destructor, setters and getters functions, domain knowledge member functions etc) of Electronic Card System.

Uploading Instructions:
You have to upload your running zipped Dev c++ project.

No comments:

Post a Comment