slip 21

/* Slip no : 21_1 Write a C++ program to swap two integer values and two float values by using function template.*/


#include<conio.h>
#include<iostream.h>

                template<class T>
void swap(T &n1,T &n2)
{
                T temp;
                temp=n1;
                n1=n2;
                n2=temp;
}
void main()
{       int no1,no2;
                float no3,no4;
                clrscr();
                cout<<"\n Enter 2 interger no : ";
                cin>>no1>>no2;
                cout<<"\n Before swapping : ";
                cout<<"\n no1 = "<<no1 <<"\t no2 = "<<no2;
                swap(no1,no2);
                cout<<"\n After swapping : ";

                cout<<"\n no1 = "<<no1 <<"\t no2 = "<<no2;
                cout<<"\n Enter 2 float no : ";
                cin>>no3>>no4;
                cout<<"\n Before swapping : ";

                cout<<"\n no1 = "<<no3 <<"\t no2 = "<<no4;
                swap(no3,no4);
                cout<<"\n After swapping : ";

                cout<<"\n no1 = "<<no3 <<"\t no2 = "<<no4;
                getch();


}















/* Slip no : 21_2 Imagine a ticket Selling booth at a fair. People passing by are requested to purchase a ticket. A ticket is priced as Rs. 5/- . The ticketbooth keeps the track of the number of peoples that have visited the booth and of the total amount of cash collected.
Create a class ticketbooth that contains No_of_people_visited, Total_Amount_collected. Write C++ program to perform following functions:
To assign initial values.
To increment the No_of_people_visited  if visitors have just visited the booth.
To increment the  No_of_people_visited  and Total_amount_collected if tickets have been purchased.
To display both totals     */
#include<conio.h>
#include<iostream.h>

class ticket
{
static int cnt;
static int amt;
char name[20];
public:
void accept()
{
cout<<"\ Enter name:";
cin>>name;
cnt++;
amt=amt+5;
}

void display()
{
cout<<"\n Name="<<name<<"\t no of persons="<<cnt<<"\t amount collected="<<amt;
}

};
int ticket:: amt;
int ticket::cnt;
void main()
{
int n,i;
ticket ob[20];
clrscr();
cout<<"\n Enter n of persons";
cin>>n;
for(i=0;i<n;i++)
{
ob[i].accept();
ob[i].display();
}
getch();
}
slip 21 slip 21 Reviewed by Dinesh Varal on January 27, 2018 Rating: 5

No comments:

Powered by Blogger.