Saturday, 13 January 2018

CPP-Slip11



Slip11

Q.1)     Write a C++ program to find area and volume of cylinder using Inline function.

#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class cylinder
{
                float r,h;
                public:
                void getdata()
                {
                                cout<<"\n Enter radius : ";
                                cin>>r;
                                cout<<"\n Enter height : ";
                                cin>>h;
                }
                inline void area()
                {
                                cout<<"\n Area of cylinder =\t"<<2*3.14*r*h;
                }
                inline void volume()
                {
                                cout<<"\nVolume of clyinder =\t"<<3.14*r*r*h;
                }
};

void main()
{
                clrscr();
                cylinder c;
                c.getdata();
                c.volume();
                c.area();
                getch();
}     

Q.2)     Create a class College containing data members as College_Id, College_Name,
Establishment_year, University_Name.  Write a C++ program with following member functions:
i.        To accept ‘n’ College details
ii.      To display College details of a specified University
iii.    To display College details according to a specified establishment year
 (Use Array of Object and Function overloading)   


#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
class College
{
int College_ID;
char College_Name[20];
int Establishment_year;
char University_Name[20];
public:
void getdata();
void display(College,char*);
void display(College,int);
};

void College::getdata()
{
cout<<"*****************************************";
cout<<"\nEnter the College_Id:";
cin>>College_ID;
cout<<"\nEnter the name of the College:";
cin>>College_Name;
cout<<"\nEnter the Establishment year:";
cin>>Establishment_year;
cout<<"\nEnter the name of the University:";
cin>>University_Name;
}
void College::display(College c,char *n)
{
if((strcmp(n,c.University_Name))==0)
{
cout<<"\n************************************";
cout<<"\nCollege Id:"<<c.College_ID;
cout<<"\nCollege Name:"<<c.College_Name;
cout<<"\nEstablishment Year:"<<c.Establishment_year;
}
}
void College::display(College c,int num)
{
if((num==c.Establishment_year)==1)
{
cout<<"\n*************************************";
cout<<"\nCollege Id:"<<College_ID;
cout<<"\nCollege Name:"<<College_Name;
cout<<"\nUniversity Name:"<<University_Name;
}
}
int main()
{
int ch,k,y;
char a[20];
College cl[10];
clrscr();
cout<<"\n\n************************ MENU **************************";
cout<<"\n1.Enter the details of the College.";
cout<<"\n2.Display College details of a Specified University.";
cout<<"\n3.Display College details according to establishment year:";
cout<<"\n4.Exit.";
do
{
cout<<"\nEnter your choice:";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\nHow many records you wish to enter:";
cin>>k;
for(int i=0;i<k;i++)
{
cl[i].getdata();
}
break;

case 2:
cout<<"\nEnter the name of the University to search:";
cin>>a;
for(i=0;i<k;i++)
{
cl[i].display(cl[i],a);
}
break;

case 3:
cout<<"\nEnter the Establishment year to search:";
cin>>y;
for(i=0;i<k;i++)
{
cl[i].display(cl[i],y);
}
break;

case 4:
exit(0);
default:
cout<<"\nYou have entered wrong choice:";
}
 }while(ch!=4);
 getch();
 return 0;
}