Friday, 27 April 2018
Tuesday, 24 April 2018
OOPs Terminologies
June-2018
* A Constructor is a member function with the same name as that of its class and it is used to initialize the object of that class type with a legal initial value.* Constructors are automatically invoked by the compiler.
* A Destructor is a member function with the same name as that if its class but is preceded by a tilde(~) and it is used deinitializes an object.
link: https://www.youtube.com/watch?v=X_yruQkVGUs
C++ can constructor be private
In C++, constructor is automatically called when object of a class is created. ... With the Named Constructor Idiom, you declare all the class's constructors in theprivate or protected sections, and then for accessing objects of class, you create public static functions.
Can a constructor be private in C++ ?
https://www.geeksforgeeks.org/can-constructor-private-cpp/
Constructor Overloading. Constructor can beoverloaded in a similar way as function overloading.Overloaded constructors have the same name (name of the class) but different number of arguments. Depending upon the number and type of arguments passed, specific constructor is called.
*How does a class
enforce data-hiding, abstraction, and encapsulation?
A class
binds together data and its associated functions under one unit thereby
enforcing encapsulation as encapsulation means wrapping up data and associated
functions together into a single unit.
A class groups its members into three sections: private,
protected and public. The private and protected members remain hidden from
outside world. Thus through private and protected members, a class enforces
data-hiding.
The outside world is given only the essential and necessary
information through public members, rest of the things remains hidden, which is
nothing but abstraction. As abstraction means representation of essential
features without including the background details or explanation.
Enlist some
advantages of opp.
i.
Reusability of code
ii.
Ease of comprehension
iii.
Ease of fabrication and maintenance
iv. Easy redesign and extension
Monday, 23 April 2018
12th D Computer Science April Monthly Test 2018- Blue Print
Max Marks : 25 Duration: 01 Hour
1. Naming Identifier and Keyword - 02 marks
2. Naming Header files for the built in function. - 01 marks
3. Syntax Error finding -02 makrs
4. Output finding : Pointer concept -03 marks
5. Output finding: Array of characters -03 marks
6. Output finding : Random numbers -03 marks
7. Direct Questions(OOPs)
Terminologies: (Data Hiding, Data Abstraction, Data Encapsulation, Class & Objects,
Polymorphism, Inheritance.)
a) Terminology-I -02 marks
b) Terminology-II - 02marks
c) Terminology-III -03 marks
8. Class Writing problem with the help of description - 04 marks
Good Luck
1. Naming Identifier and Keyword - 02 marks
2. Naming Header files for the built in function. - 01 marks
3. Syntax Error finding -02 makrs
4. Output finding : Pointer concept -03 marks
5. Output finding: Array of characters -03 marks
6. Output finding : Random numbers -03 marks
7. Direct Questions(OOPs)
Terminologies: (Data Hiding, Data Abstraction, Data Encapsulation, Class & Objects,
Polymorphism, Inheritance.)
a) Terminology-I -02 marks
b) Terminology-II - 02marks
c) Terminology-III -03 marks
8. Class Writing problem with the help of description - 04 marks
Good Luck
Tuesday, 17 April 2018
12-D Prg-4 Class Hotel program
/* Define a class Hotel with following description private members RNo. of int, name of string, tariff(float), nod (number of days) of int. Cal() function to calculate and return amount as number of days.
if the value of nod*tariff > 1000 then amount= 1.05* nod *tariff.
*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class hotel
{
int rno ;
float amount;
char name[50];
float tarrif;
int nod;
void calc() ;
public:
void checkin();
void checkout();
};
void hotel::calc ()
{ if(nod*tarrif>=1000)
{amount=1.05*nod*tarrif;
cout << "\nThe amount is " ;
cout << amount ;
getch() ;
}
else
{
amount=nod*tarrif;
cout<<"\n amount is:";
cout << amount ;
getch() ;
}
}
void hotel::checkin()
{
cout<<"\n enter room no.";
cin>>rno;
cout<<"\n enter name :";
gets(name);
cout<<"enter tariff :";
cin>>tarrif;
cout<<"\n entet the no. of days:";
cin>>nod;
}
void hotel:: checkout()
{
cout<<"\nthe room no is"<<rno;
cout<<"\n the name is:";
puts(name);
cout<<"\n tariff is:"<<tarrif;
cout<<"\n no. of days is:"<<nod;
calc();
}
void main ()
{
clrscr ();
hotel x ;
x.checkin();
x.checkout();
}
*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class hotel
{
int rno ;
float amount;
char name[50];
float tarrif;
int nod;
void calc() ;
public:
void checkin();
void checkout();
};
void hotel::calc ()
{ if(nod*tarrif>=1000)
{amount=1.05*nod*tarrif;
cout << "\nThe amount is " ;
cout << amount ;
getch() ;
}
else
{
amount=nod*tarrif;
cout<<"\n amount is:";
cout << amount ;
getch() ;
}
}
void hotel::checkin()
{
cout<<"\n enter room no.";
cin>>rno;
cout<<"\n enter name :";
gets(name);
cout<<"enter tariff :";
cin>>tarrif;
cout<<"\n entet the no. of days:";
cin>>nod;
}
void hotel:: checkout()
{
cout<<"\nthe room no is"<<rno;
cout<<"\n the name is:";
puts(name);
cout<<"\n tariff is:"<<tarrif;
cout<<"\n no. of days is:"<<nod;
calc();
}
void main ()
{
clrscr ();
hotel x ;
x.checkin();
x.checkout();
}
12-D Prog-3 Define a class Travel Plan
Define a class Travel Plan for the following description
/*12-C Prog-3 Define a class Travel Plan
private:
Tcode int
Tname string
Source string
Destination string
Distance float
Fare int
->Function Calfare() which calculates and returns fare according to following
criteria.
Distance Fare
<= 1000 500
> 1000 and <=2500 750
>2500 100
public:
->Function ReadData() to read the data members and
call function Calfare() to calculate fare;
->Function ShowData() to print the values of all the data members.*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class TravelPlan
{
int Tcode;
char Tname[20];
char Source[30];
char Destination[30];
float Distance;
int Fare;
int calFare();
public:
void ReadData();
void ShowData();
};
int TravelPlan :: calFare()
{
if(Distance <= 1000)
return 500;
else if(Distance <= 2500)
return 750;
else
return 1000;
}
void TravelPlan :: ReadData()
{
cout<<"\n Enter Travel code \n";
cin>>Tcode;
cout<<"\n Enter Travel Name ";
gets(Tname);
cout<<"\n Enter Source\n";
gets(Source);
cout<<"\n Enter Destination \n";
gets(Destination);
cout<<"\n Enter Distance \n";
cin>>Distance;
Fare=calFare();
}
void TravelPlan :: ShowData()
{
cout<<"\n Travel Code "<<Tcode;
cout<<"\n Travel Name "<<Tname;
cout<<"\n Travel source "<<Source;
cout<<"\n Destination "<<Destination;
cout<<"\n Distance"<<Distance;
cout<<"\n Fare"<<Fare;
}
void main()
{
clrscr();
TravelPlan T;
T.ReadData();
T.ShowData();
getch();
}
private:
Tcode int
Tname string
Source string
Destination string
Distance float
Fare int
->Function Calfare() which calculates and returns fare according to following
criteria.
Distance Fare
<= 1000 500
> 1000 and <=2500 750
>2500 100
public:
->Function ReadData() to read the data members and
call function Calfare() to calculate fare;
->Function ShowData() to print the values of all the data members.*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class TravelPlan
{
int Tcode;
char Tname[20];
char Source[30];
char Destination[30];
float Distance;
int Fare;
int calFare();
public:
void ReadData();
void ShowData();
};
int TravelPlan :: calFare()
{
if(Distance <= 1000)
return 500;
else if(Distance <= 2500)
return 750;
else
return 1000;
}
void TravelPlan :: ReadData()
{
cout<<"\n Enter Travel code \n";
cin>>Tcode;
cout<<"\n Enter Travel Name ";
gets(Tname);
cout<<"\n Enter Source\n";
gets(Source);
cout<<"\n Enter Destination \n";
gets(Destination);
cout<<"\n Enter Distance \n";
cin>>Distance;
Fare=calFare();
}
void TravelPlan :: ShowData()
{
cout<<"\n Travel Code "<<Tcode;
cout<<"\n Travel Name "<<Tname;
cout<<"\n Travel source "<<Source;
cout<<"\n Destination "<<Destination;
cout<<"\n Distance"<<Distance;
cout<<"\n Fare"<<Fare;
}
void main()
{
clrscr();
TravelPlan T;
T.ReadData();
T.ShowData();
getch();
}
12-D Prog-2 Define a struct employee to store employee code, employee name, address, phone no., salary. Create 5 objects of employee type read their values and print in ascending order of salary */
/*12-C Prog-2 Define a struct employee to store employee code, employee
name, address, phone no., salary. Create 5 objects of employee type
read their values and print in ascending order of salary */
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
struct employee
{
int empcode;
char empname[30];
char adress[40];
long phone;
float salary;
};
void read(employee &E)
{
cout<<"\n Enter employee code";
cin>>E.empcode;
cout<<"\n Enter employee name";
gets(E.empname);
cout<<"\n Enter employee's address";
gets(E.adress);
cout<<"\n Enter employee's phone no";
cin>>E.phone;
cout<<"\n Enter salary";
cin>>E.salary;
}
void Arrange(employee E[], int size)
{
int i,j;
employee T;
for(i=0;i<size;i++)
{
for(j=i+1;j<size;j++)
{
if(E[i].salary > E[j].salary)
{
T=E[i];
E[i]=E[j];
E[j]=T;
}
}
}
}
void print(employee E)
{
cout<<"\n Employee code"<<E.empcode;
cout<<"\n Employee Name";
puts(E.empname);
cout<<"Employee Adress";
puts(E.adress);
cout<<"\n Employee Phone no"<<E.phone;
cout<<"\n Employee salary"<<E.salary;
}
void main()
{
clrscr();
employee emp[5];
cout<<"\n Enter details of Employee";
for(int i=0; i<5; i++)
{
cout<<"\n Enter details of employee";
read(emp[i]);
}
Arrange(emp,5);
cout<<"\n Employees according to ascending order of salary\n";
for(i=0;i<5;i++)
{
cout<<"\n Employee"<<i+1;
print(emp[i]);
}
getch();
}
name, address, phone no., salary. Create 5 objects of employee type
read their values and print in ascending order of salary */
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
struct employee
{
int empcode;
char empname[30];
char adress[40];
long phone;
float salary;
};
void read(employee &E)
{
cout<<"\n Enter employee code";
cin>>E.empcode;
cout<<"\n Enter employee name";
gets(E.empname);
cout<<"\n Enter employee's address";
gets(E.adress);
cout<<"\n Enter employee's phone no";
cin>>E.phone;
cout<<"\n Enter salary";
cin>>E.salary;
}
void Arrange(employee E[], int size)
{
int i,j;
employee T;
for(i=0;i<size;i++)
{
for(j=i+1;j<size;j++)
{
if(E[i].salary > E[j].salary)
{
T=E[i];
E[i]=E[j];
E[j]=T;
}
}
}
}
void print(employee E)
{
cout<<"\n Employee code"<<E.empcode;
cout<<"\n Employee Name";
puts(E.empname);
cout<<"Employee Adress";
puts(E.adress);
cout<<"\n Employee Phone no"<<E.phone;
cout<<"\n Employee salary"<<E.salary;
}
void main()
{
clrscr();
employee emp[5];
cout<<"\n Enter details of Employee";
for(int i=0; i<5; i++)
{
cout<<"\n Enter details of employee";
read(emp[i]);
}
Arrange(emp,5);
cout<<"\n Employees according to ascending order of salary\n";
for(i=0;i<5;i++)
{
cout<<"\n Employee"<<i+1;
print(emp[i]);
}
getch();
}
12D-Prg-1-Write a Program to define a class myarray.
12D-Prg-1-Write a Program to define a class myarray.
12C-Prg-1-Write a Program to define a class myarray. which reads n elements of int type. Write
4 member functions
1. input();
2.output();
3.large(); // largest element logic
4.small(); // smallest element logic
#include<iostream.h>
#include<conio.h>
class myarray
{ int a[50],l,i,n,s;
public:
void input();
void large();
void small();
void output();
};
void myarray::input()
{
cout<<"enter no. of elements=";
cin>>n;
cout<<"\nenter the elements";
for(i=0;i<n;i++)
cin>>a[i];
}
void myarray::large()
{
l=a[0];
for(i=1;i<n;i++)
{ if(l<a[i])
l=a[i];
}
}
void myarray::small()
{
s=a[0];
for(i=1;i<n;i++)
{ if(s>a[i])
s=a[i];
}
}
void myarray::output()
{
cout<<"\nlargest ="<<l;
cout<<"\nsmallest="<<s;
}
void main()
{
clrscr();
myarray obj1;
obj1.input();
obj1.large();
obj1.small();
obj1.output();
getch();
}
4 member functions
1. input();
2.output();
3.large(); // largest element logic
4.small(); // smallest element logic
#include<iostream.h>
#include<conio.h>
class myarray
{ int a[50],l,i,n,s;
public:
void input();
void large();
void small();
void output();
};
void myarray::input()
{
cout<<"enter no. of elements=";
cin>>n;
cout<<"\nenter the elements";
for(i=0;i<n;i++)
cin>>a[i];
}
void myarray::large()
{
l=a[0];
for(i=1;i<n;i++)
{ if(l<a[i])
l=a[i];
}
}
void myarray::small()
{
s=a[0];
for(i=1;i<n;i++)
{ if(s>a[i])
s=a[i];
}
}
void myarray::output()
{
cout<<"\nlargest ="<<l;
cout<<"\nsmallest="<<s;
}
void main()
{
clrscr();
myarray obj1;
obj1.input();
obj1.large();
obj1.small();
obj1.output();
getch();
}
Subscribe to:
Posts (Atom)