Pre-Lab 1 :: 26/3/2010
Page 1 of 1
Is this helpful?
Pre-Lab 1 :: 26/3/2010
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- Admin
- Posts : 19
Join date : 2010-03-10
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|