Nabeel Sabir


Join the forum, it's quick and easy

Nabeel Sabir
Nabeel Sabir
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Pre-Lab 1 :: 26/3/2010

Go down

Is this helpful?

Pre-Lab 1 :: 26/3/2010 I_vote_lcap100%Pre-Lab 1 :: 26/3/2010 I_vote_rcap 100% 
[ 6 ]
Pre-Lab 1 :: 26/3/2010 I_vote_lcap0%Pre-Lab 1 :: 26/3/2010 I_vote_rcap 0% 
[ 0 ]
 
Total Votes : 6
 
 

Pre-Lab 1 :: 26/3/2010 Empty Pre-Lab 1 :: 26/3/2010

Post  Ali Rizwan Thu Mar 25, 2010 2:31 am

Students code the following questions, as they will help you in upcoming graded lab.
Code:
Q1. Replace following constructors with a single constructor.
   class food{
      char * color;
      char *name;
      int weight;
      float price;
      food (){}
      food (){
         color = NULL;
         name = NULL;
         weight = 5;
         price = 0.5;
      }
      food (char *Color, char *Name, int Weight, float Price){   
         color = Color;
         name = Name;
         weight = Weight;
         price = Price;
      }

      food (char *Color = "red", char *Name = "Apple", int Weight = 5, float Price = 0.5){
         color = Color;
         name = Name;
         weight = Weight;
         price = Price;
}
   
   }

Q2. Write a copy constructor which will copy all contents of one object to another.
   class Obj{
      int *abc;
      char *xyz;
      Obj (Obj object){} // Write it twice one for shallow copy and one for deep copy.
   }

   Help: See your lecture slides.
Q3. Write a getter function which will return the current object.
   class Student{
      int rollno;
      char *name;
      Student getStudent (){}
   }

   Help: Use this pointer.
Ali Rizwan
Ali Rizwan
Admin

Posts : 19
Join date : 2010-03-10

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum