Innovative Lab Cse 18bme1225
Innovative Lab Cse 18bme1225
m.push_back(meet[i].pos);
time_limit = meet[i].end;
}
}
for (int i = 0; i < m.size(); i++) {
cout << m[i] << " ";
}
}
int main()
{
int s[] = { 1, 3, 0, 5, 8, 5 };
int f[] = { 2, 4, 6, 7, 9, 9 };
int n = sizeof(s) / sizeof(s[0]);
maxMeeting(s, f, n);
return 0;
}
Q2) An electricity board charges the following rates to
domestic users to
discourage large
consumption of energy:
- 60P per unit
- 80P per unit
- 90P per unit
than
Rs.300.00 than an additional surcharge of 15% is added
Write a C++ program to read the names of users and
number of units
consumed and print out
the charges with names.( Use Static data
members,Constructor,Exception error
handling )
#include <iostream>
using namespace std;
int main()
{
cout<<"\n\n\n\tElectricity Board Charges\n";
cout<<"\n\tTo Discourage Large Consumption of
energy\n\n";
float tc;
char name[20];
cout<<"\n\nEnter USER name :-";
cin>>name;
cout<<"\n\nEnter Number of Units Consumed:-";
float unit;
cin>>unit;
if(unit<=100)
tc=unit*60;
else if(unit<=300)
tc=unit*80;
else
tc=unit*90;
float surchase=0;
if(tc>300)
surchase=tc*15;
float total_cost;
total_cost = 50 + surchase + tc;
cout<<"\n\nYOUR BILL AMOUNT IS "<<total_cost;
return 0;
}
Q3) Develop a C++ program in which user is asked to enter
two time periods and these two periods are stored in
structure variables. The program calculates the difference
between these two time periods(Use Friend function and
Friend class)
#include <iostream>
using namespace std;
struct TIME
{
int seconds;
int minutes;
int hours;
};
void computeTimeDifference(struct TIME, struct TIME, struct
TIME *);
int main()
{
struct TIME t1, t2, difference;
cout << "Enter start time." << endl;
cout << "Enter hours, minutes and seconds respectively: ";
cin >> t1.hours >> t1.minutes >> t1.seconds;
cout << "Enter stop time." << endl;
cout << "Enter hours, minutes and seconds respectively: ";
cin >> t2.hours >> t2.minutes >> t2.seconds;
computeTimeDifference(t1, t2, &difference);
cout << endl << "TIME DIFFERENCE: " << t1.hours << ":" <<
t1.minutes << ":"
<< t1.seconds;
cout << " - " << t2.hours << ":" << t2.minutes << ":" <<
t2.seconds;
cout << " = " << difference.hours << ":" <<
difference.minutes << ":" <<
difference.seconds;
return 0;
}
void computeTimeDifference(struct TIME t1, struct TIME t2,
struct TIME
*difference){
#include<iostream>
using namespace std;
inline int add(int a, int b)
{
return a+b;
}
inline double division(double x, double y)
{
return x/y;
}
inline float difference(float a, float b)
{
return a-b;
}
inline int mod(int x, int y)
{
return x%y;
}
inline long int multiplication(long int a, long int b)
{
return a*b;
}
int main()
{
int a,b;
double x,y;
float i,j;
long int e,f;
cout<<"\nEnter 2 integer values for calculating there
sum:\n";
cin>>a>>b;
cout<<"\nSum of "<<a<<"and "<<b<<" = "<<add(a,b)<<"\n";
cout<<"\nEnter 2 double values for performing division:\n";
cin>>x>>y;
cout<<"\nValue of "<<x<<" divided by "<<y<<" =
"<<division(x,y)<<"\n";
cout<<"\nEnter 2 float values for calculating there difference
:\n";
cin>>i>>j;
cout<<"\nDifference between "<<i<<" and "<<j<<" =
"<<difference(i,j)<<"\n";
cout<<"Enter 2 integer values for calculating there
modulus:\n";
cin>>a>>b;
cout<<"\n"<<a<<" modulus "<<b<<" = "<<mod(a,b)<<"\n";
cout<<"\nEnter 2 long integer values for calculating there
product:\n";
cin>>e>>f;
cout<<"\nProduct of "<<e<<" and "<<f<<" =
"<<multiplication(e,f)<<"\n";
return 0;
}
Q6) Write a C++ program to implement flight class with data
member as flight no.,source, destination and fare. Write a
member function to display the flight information using this
pointer
#include <iostream>
using namespace std;
void setRoute(char *path[], float *fare, float *tfare){
int i=0;
for(i=0;i<5;i++){
cout<<"Enter flight route:"<<endl;
cout<<"Route ["<<i+1<<"] : ";
path[i]=new char[100];
cin.ignore(1);
cin.getline(path[i],100);
cout<<"Enter fare: ";
cin>>fare[i];
tfare[i]=fare[i]+(fare[i]*19/100);
}
}
void displayPath(char *path[],float *fare, float *tfare){
int i=0;
cout<<"Available flight routes are:"<<endl;
for(i=0;i<5;i++){
cout<<"Route ["<<i+1<<"] : "<<path[i]
<<" - Fare: "<<fare[i]<<",Total Fare: "<<tfare[i]<<endl;
}
}
int main(){
//variable to store flight route
char *route[5];
float fare[5],totalFare[5];
char name[30],path[100];
int d,m,y;
int routeId;
setRoute(route,fare,totalFare);
cout<<endl<<endl;
cout<<"Enter name: ";
cin.ignore(1);
cin.getline(name,30);
cout<<"Enter date of travel (d m y): ";
cin>>d>>m>>y;
displayPath(route,fare,totalFare);
cout<<"Choose flight route (1 to 5): ";
cin>>routeId;
if(routeId<1 || routeId>5){
cout<<"Invalid flight route!!!"<<endl;
return 0;
}
cout<<endl<<endl;
cout<<"Congratulations... "<<name<<" your ticket has been
booked."<<endl;
cout<<"Travel date is: "<<d<<"/"<<m<<"/"<<y<<endl;
cout<<"Flight route: "<<route[routeId-1]<<endl;
cout<<"Total fare is: "<<totalFare[routeId-1]<<endl;
return 0;
}
Q7) Write a program to count the words and characters in
given text using virtual function
#include <iostream>
#include <ctype.h>
using namespace std;
class words {
public:
char a[200];
virtual void countl()
{}
void countw()
{int count=1;
cin.getline(a,200);
for(int i=0;a[i]!='\0';i++)
{
if(isspace(a[i]))
count++;
}
cout<<"There are "<<count<<" words"<<endl;
}
};
int main()
{
words* bptr;
letters d;
bptr = &d;
bptr->countl();
bptr->countw();
}
#include <iostream>
using namespace std;
class Minus{
public:
int val;
Minus operator-(){
val=-1*val;
cout<<val;
}
};
int main()
{
Minus m;
cin>>m.val;
-m;
return 0;
}
#include <iostream>
using namespace std;
class frindfunc2;
class frindfunc1{
public:
int a,b;
void input1(){
cin>>a>>b;
}
friend void add(frindfunc1,frindfunc2);
};
class frindfunc2{
public:
int c,d,e;
void input2(){
cin>>c>>d>>e;
}
friend void add(frindfunc1,frindfunc2);
};
void add(frindfunc1 obj1,frindfunc2 obj2)
{
int tot;
float avg;
tot=obj1.a+obj1.b+obj2.c+obj2.d+obj2.e;
avg=tot/5;
cout<<"average is="<<avg;
}
int main()
{
frindfunc1 f1;
frindfunc2 f2;
f1.input1();
f2.input2();
add(f1,f2);
return 0;
}
#include <iostream>
#include <fstream>
using namespace std;
class Employee{
char name[100];
int empid;
int salary;
friend class Department;
public:
void getdetails()
{
cout<<"Enter Employee name "<<endl;
cin>>name;
cout<<"Enter employee id"<<endl;
cin>>empid;
cout<<"Enter employee salary"<<endl;
cin>>salary;
}
};
class Department{
char deptname[100];
public:
void getdeets()
{
cout<<"Enter department name"<<endl;
cin>>deptname;
}
void showall(Employee obj)
{cout<<"Employee Name "<<obj.name<<endl;
cout<<"Employee ID "<<obj.empid<<endl;
cout<<"Employee Salary "<<obj.salary<<endl;
cout<<"Department Name "<<deptname<<endl;
}
};
int main(){
Employee obj;
Department obj2;
obj.getdetails();
obj2.getdeets();
obj2.showall(obj);
return 0;
}
Q11) Write a C++ program to find the read two data items
and find the sum using class template
#include <iostream>
using namespace std;
template<class t1,class t2>
void sum(t1 a,t2 b)
{
cout<<"\nSum="<<a+b<<endl;
}
int main()
{
int a,b;
float x,y;
cout<<"\nEnter two integer data: ";
cin>>a>>b;
cout<<"\nEnter two float data: ";
cin>>x>>y;
sum(a,b);
sum(x,y);
sum(a,x);
return 0;
}
#include <iostream>
#include<stdlib.h>
using namespace std;
int count = 0;
struct Node{
int num;
struct Node* next;
}*head=NULL;
void insert(int val){
struct Node* temp=(struct Node*)malloc(sizeof(struct
Node));
if(head==NULL && count<10){
head=(struct Node*)malloc(sizeof(struct Node));
head->num=val;
head->next=NULL;
count++;
}
else if(count<100){
temp->num=val;
temp->next=head;
head=temp;
count++;
}
else if(count>=100){
cout<<"Stack is Full"<<endl;
}
}
void del(){
if(head!=NULL)
head=head->next;
else
cout<<"Stack is empty"<<endl;
}
void show(){
if(head==NULL)
cout<<"Underflow";
struct Node* temp=(struct Node*)malloc(sizeof(struct
Node));
temp=head;
while(temp!=NULL){
cout<<"->"<<temp->num;
temp=temp->next;
}
}
int main()
{
int c=1;
while(c==1){
int val;
cin>>val;
insert(val);
cin>>c;
}
del();
show();
return 0;
}