How To Exam?

a knowledge trading engine...


Sardar Patel University 2006 B.E Computer Science CP312 – Object-Oriented Programming(Internal ) - Question Paper

Tuesday, 29 January 2013 10:45Web
? A friend function is not member of class but still it has access to the private elements.
? It is also useful in operator overloading and the creation of certain kinds of I/O functions.

Marks Distribution: 1st point is compulsory to be mentioned in the ans.1 marks for explaining it correctly.

7. Advantages of new and delete over malloc() and free():

? malloc() function always returns the void pointer so we need to perform the kind casting to desired kind while new always return the pointer of the specified kind so there is no need for kind casting.
? New automatically allocates the memory large enough to hold the object of specified kind so we don’t need to mention size.
? New and delete are operator so they can overloaded while malloc() and free() are functions.
? We can initialize the dynamically allocated memory.

Marks Distribution: 1st and 2nd point must appear in your ans to get full marks.0.5 marks for third and fourth points.

[05]
[b] #include
#include
class test
{
int no;
public:
test(int n)
{
no=n;
}
friend int count_freq(test *ob,int size);
};
int count_freq(test *ob,int size)
{
int count=0,chk;
cout<<"Enter the number to check the frequency:";
cin>>chk;
for(int i=0;i {
if(ob[i].no==chk)
count++;
}
return count;
}
void main()
{
clrscr();
test ob[10]={0,1,3,4,6,6,9,9,0,0};
int out;
out=count_freq(ob,10);
cout<<"\nThe frequency of the Number = "< getch();
}

Marks Distribution: 0.5 marks for constructor function, 0.5 for the main function and two marks for the accurate logic of count_freq function. It is compulsory to pass the array of objects to this function and not necessary to make it friend function. [03]
Q-2
[a]

#include
#include
class date
{
int day,month,year;
public:
date();
date(int d,int m,int y);
friend date operator+(int d,date ob);
date operator++(int notused);
void display();
};
date::date()
{
day=month=year=0;
}
date::date(int d,int m,int y)
{
day=d;
month=m;
year=y;
}
void date::display()
{
cout<}
date date::operator++(int notused)
{
date temp(day,month,year);
day++;
if(day>30)
{
day=1;
month++;
if(month>12)
{
month=1;
year++;
}
}
return temp;
}
date operator+(int day,date ob)
{
date temp;
temp.day=day+ob.day;
temp.month=ob.month;
temp.year=ob.year;
while(temp.day>30)
{
if(temp.day>365)
{
temp.year+=temp.day/365;
temp.day=temp.day%365;
}
else
{
temp.month+=temp.day/30;
temp.day=temp.day%30;
if(temp.month>12)
{
temp.month-=12;
temp.year++;
}
}

}
return temp;
}
void main()
{
clrscr();
date o1(1,4,2000),o2,o3;
o2=712+o1;
o3=o1++;
o2.display();
o1.display();
getch();
}

Marks Distribution: 0.5 marks for accurate initialization, 0.5 for the main function,1 mark for the accurate logic of operator + function and one mark for the accurate logic of operator ++ function. It is compulsory to overload + operator using friend function. You need to handle the change of month and year when you increment the number of days or add number of days to current date.

[03]
[b] Correct syntax for the program code.
? First fault is that destructor cannot have any argument nor it can take any parameters.
? Second fault is we cannot initialize the data member while we are declaring them in class. We can initialize them either in constructor or in a few function.

Class Time
{
public: ~time();
private: int hr; int min; int sec;
};

Marks Distribution: 0.5 mark for every of the fault.

[01]
[c] Output:
Constructor 1
Constructor 2 0.5 mark
Constructor 0
Constructor 0
Destructor 7
Destructor two one mark
Destructor 7
Destructor 7
Destructor two 0.5 mark
Destructor 1
[02]
[d] Output:
Address of ptr two 3
1 1

Marks Distribution: 0.5 mark for giving 1st 3 outputs accurate and 0.5 mark for 2nd two. [01]






( 0 Votes )

Add comment


Security code
Refresh

Earning:   Approval pending.
You are here: PAPER Sardar Patel University 2006 B.E Computer Science CP312 – Object-Oriented Programming(Internal ) - Question Paper