2075
Object-Oriented Programming BSC.CSIT 2075
Group A
2.Depict the difference between private and public derivation. Explain derived class constructor with suitable example.
#include <iostream>
using namespace std;
class A{
public:
A(int x){
cout<<"constructor A called "<< x<<endl;
}
};
class B{
public:
B(int y){
cout<<"constructor b called "<<y<<endl;
}
};
class C:public A,public B{
public:
C(int x,int y,int z):A(x),B(y){
cout<<"constructor C called "<<z<<endl;
}
};
int main(){
C c(5,7,9);
return 0;
}
Output:
constructor A called 5
constructor b called 7
constructor C called 9
Group B
4. Write a member function called reverseit() that reverses a string (an array of characters). use a for loop that swaps the first and last character, then second and next-to last characters and so on. The string should be passed to reverseit() as argument.
#include <iostream>
#include <cstring>
using namespace std;
void reverseit(char str[100])
{
int len = strlen(str);
for (int i = 0; i < len / 2; i++)
{
char temp = str[i];
str[i] = str[len - 1 - i];
str[len - 1 - i] = temp;
}
}
int main()
{
char name[100];
cout << "Enter Your name : ";
gets(name);
reverseit(name);
cout << "Reverse string : " << name;
return 0;
}
Output:
Enter Your name : codeabid
Reverse string : dibaedoc