SlideShare a Scribd company logo
1 | P a g e
C++ Tour
1. Write C++ program that uses various functions to sum following
series:
(i) (1) + (1+2) + (1+2+3) + (1+2+3+4) +…………… upto N terms
(ii) (22) + (22+42) +(22+42+62) +(22+42+62+82) up to N terms
(iii) 1 + 1/3+ 1/5+ 1/7 + 1/9+….. Up to N terms.
PROGRAM(i):
#include<iostream.h>
#include<conio.h>
void main()
{
int k=0, m=0;
clrscr();
cout<<"Enterthe limit of the series: ";
cin>>m;
for(inti=1;i<=m;i++)
{
for(intj=1;j<=i;j++)
k+=j;
}
cout<<"Sum of the given series is: "<<k;
getch();
}
Program (ii)
#include<iostream.h>
#include<conio.h>
void main()
{
int k=0, m=0, s=0;
clrscr();
cout<<"Enter the limit of the series: ";
cin>>m;
for(int i=2;i<=m;i=i+2)
{
for(int j=2;j<=i;j=j+2)
{
s=j*j;
k+=s;
}
}
cout<<"Sum of the given series is: "<<k;
getch();
}
Program (iii)
#include<iostream.h>
#include<conio.h>
void main()
{
float k, s=1;
int m=0;
clrscr();
cout<<"Enterthe limit of the series: ";
cin>>m;
for(intj=3;j<=m;j=j+2)
{
k=(float)1/j;s+=k;
}
cout<<endl;
cout<<"Sum of the given series is: "<<s;
getch();
2 | P a g e
}
2. Write a program to record score of a cricket match. One array stores
information of batting team such as bat'sman name, runs scored, indication if
out, mode by which out along with total runs, overs played, total overs and extras.
The other array stores information about bowling team such as bowler's name,
over's bowled, maiden overs, runs given, and wicked taken. The program reads in
the above information and depending upon the user'schoice, it displays either the
batting team's information or the bowling team's information.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct batting
{char batsman[20];
int run, out, tot_run, overs, total_over,extra;
};
struct bowling
{char bowler[20];
int overs, maiden_overs, runs, wicket;
};
void main()
{int b,f;
clrscr();
batting bat_team[12]; bowling bo_team[12];
cout<<"n Enter records of batting team :nn"<<endl;
cout<<"Enterthe no of bat's man:";
cin>>b;
for(inti = 0; i < b ; i++)
{cout<<"n Enter bat's man name :";
gets(bat_team[i].batsman);
cout<<"n Enter run scored :";
cin>>bat_team[i].run;
cout<<"n Type 0 NOT-OUT,Type 1 if OUT:";
cin>>bat_team[i].out;
cout<<"n Enter total run :";
cin>>bat_team[i].tot_run;
cout<<"n Enter no. of overs played :";
cin>>bat_team[i].overs;
cout<<"n Enter total over:";
cin>>bat_team[i].total_over;
cout<<"n Extra ?";
cin>>bat_team[i].extra;
}
cout<<"n Enter records of bowling team :nn"<<endl;
cout<<"enter the no of Bowlers:";
cin>>f;
for(i = 0; i < f ; i++)
{cout<<"n Enter bowler'sname :";
gets(bo_team[i].bowler);
3 | P a g e
cout<<"n Enter overs bowled :";
cin>>bo_team[i].overs;
cout<<"n Enter maiden overs :";
cin>>bo_team[i].maiden_overs;
cout<<"n Enter runs :";
cin>>bo_team[i].runs;
cout<<"n Enter wickedtaken:";
cin>>bo_team[i].wicket;}
char ch;
int n;
do
{clrscr();
cout<<"n Enter 1 to view batting team information:";
cout<<"n Enter 2 to view bowlingteam information:";
cout<<"n Enter your choice:";
cin>>n;
switch(n)
{case 1:
cout<<"n ************* BATTINGTEAM *************n";
cout<<"n Name t RUN-Scored Out Total-run Over's-playedTotal-OversExtra ";
for(i = 0; i < b; i++)
{cout<<"n"<<bat_team[i].batsman <<"t"<<bat_team[i].run<<" ";
if(bat_team[i].out)
cout<<"OUT";
else
cout<<"NOT-OUT";
cout<< " " <<bat_team[i].tot_run<< " " <<bat_team[i].overs << " " <<bat_team[i].total_over
<< " "<<bat_team[i].extra;}
break;
case 2:
cout<< "n ************* BOWLINGTEAM*************n";
cout<< "n Name t Overs_bowledMaiden-Overs Runs-Given Wicket-Taken";
for(i = 0; i < f ; i++)
{cout<<"n"<<bo_team[i].bowler<< "t"<<bo_team[i].overs<< " ";
cout<< " "<<bo_team[i].maiden_overs<< " "<<bo_team[i].runs<< " "<<bo_team[i].wicket<<"";}
break;
default:
cout<< "n Wrong choice.";
}
cout<<"n Do youcontinue (y/n)";cin>>ch; }while(ch=='y'||ch=='Y');
getch();
}
4 | P a g e
Classes and objects
1. Define a class Applicant in C++ with the following description:
Private Members:
1. A data member ANo (Admission Number) of type long ,A data member Name
of type string
2. A data member Agg (Aggregate Marks) of type float ,A data member Grade of
type char
3. A member function GradeMe() to find the Grade as per the Aggregate Marks
obtained by a student. Equivalent Aggregate Marks range and the respective
Grades are shown as follows:
Aggregate Marks
Grade >=80 A
less than 80 and >=65 B
less than 65 ad >=50 C
less than 50 D
Public Members:
1. A function ENTER() to allow user to enter values for Ao, Name, Agg and call
function GradeMe() to find the Grade.
2. A fuctionRESULT() to allow user to view the content of all the data members.
Program:-
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class Applicant
{
long ANO;
char NAME[25], Grade;
float Agg;
void GradeMe()
{
if(Agg>=80)
Grade='A';
else if(Agg>=65 && Agg<80)
Grade='B';
else if(Agg>=50 && Agg<65)
Grade='C';
else if(Agg<50)
Grade='D';
}
public:
void ENTER()
{
5 | P a g e
cout<<"EnterAdmission No:";
cin>>ANO;
cout<<"EnterName of the Applicant :";
gets(NAME);
cout<<"EnterAggregare Marks obtained by the Candidate out of 100:";
cin>>Agg;
GradeMe();
}
void RESULT()
{
cout<<"*******Applicat Details***********"<<endl;
cout<<"Admission No: "<<ANO<<endl;
cout<<"Name of the Applicant: "<<NAME<<endl;
cout<<”Aggregare Marks obtained by the Candidate out of 100:"<<Agg<<endl;
cout<<"Grade Obtained: "<<Grade<<endl; }
};
void main()
{ clrscr();
Applicant a1;
a1.ENTER();
a1.RESULT();
getch();
}
6 | P a g e
2. Write a C++ program to perform various operations on a string class without
using language supported built-in string functions. The operations on a class are:
a) Read a string
b) Display the string
c) Reverse the string
d) Copy the string into an empty string
e) Concatenate two strings
Program:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<process.h>
class string
{char str1[20];
char str2[20];
public:
void read()
{cout<<"nEnter string :=> ";
cin>>str1; }
void Display()
{cout<<endl<<"The entered string is: "<<str1; }
void reverse();
void copy();
void concatenate();};
void string::reverse()
{inti,l,j=0;
cout<<"nEnter string :=> ";
cin>>str1;
l=strlen(str1);
for(i=l-1;i>=0;i--)
{str2[j]=str1[i];
j++; }
str2[j]='0';
cout<<"Reverse is: "<<str2; }
void string::copy()
{int i;
cout<<"nEnter string :=> ";
cin>>str1;
for(i=0;i<=strlen(str1);i++)
{ str2[i]=str1[i]; }
7 | P a g e
str2[i]='0';
cout<<"Copy is: "<<str2; }
void string::concatenate()
{inti,l;
cout<<"nEnter string1 :=> ";
cin>>str1;
cout<<"nEnter string2 :=> ";
cin>>str2;
l=strlen(str1);
for(i=0;i<=l;i++)
{str1[l+i]=str2[i]; }
cout<<"Copy is: "<<str1; }
void main()
{ clrscr();
int choice; string s1;
l1:
cout<<"n1.Read the string"<<endl;
cout<<"2.Display the string "<<endl;
cout<<"3.Reverse the string"<<endl;
cout<<"4.Copy the string"<<endl;
cout<<"5.Concatenate two strings"<<endl;
cout<<"6.Exit"<<endl;
cout<<"Enteryour choice:";
cin>>choice;
switch(choice)
{case 1:
s1.read();
goto l1;
break;
case 2:
s1.Display();
goto l1;
break;
case 3:
s1.reverse();
goto l1;
break;
case 4:
s1.copy();
goto l1;
break;
case 5:
s1.concatenate();
goto l1;
break;
case 6:
exit(0);
break;
}
getch();
8 | P a g e
}
3. Define a class named HOUSING in C++ with the following description:
Private Members:
REG_NO integer (Ranges 10 - 2000)
NAME Array of characters (String)
TYPE Character
COST Float
Public Members:
1. Function Read_Data() to read an object of HOUSING type. Function Display() to
display the details of an object.
2. Function Draw-Nos() to choose and display the details of 2 houses selected
randomly from an array of 10 objects of type HOUSING. Use randomfunction to
generate the registration nos. to match with REG_NO from the array.
Program:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
classHOUSING
{private:
intREG_NO;
char NAME[50];
char TYPE[20];
floatCOST;
public:
voidRead_Data();
voidDisplay();
voidDraw_Nos();
};
voidHOUSING::Read_Data()
{cout<<"Enter RegNo(10 - 1000): ";
cin>>REG_NO;
cout<<"Name:";
gets(NAME);
cout<<"Type:";
gets(TYPE);
cout<<"Cost: ";
cin>>COST;
}
voidHOUSING::Display()
{cout<<"RegNo:"<<REG_NO<<endl;
cout<<"Name:"<<NAME<<endl;
cout<<"Type:"<<TYPE<<endl;
cout<<"Cost: "<<COST<<endl;
}
voidHOUSING::Draw_Nos()
{intArr[5];
intno1,no2,i;
randomize();
no1=random(991)+10;
cout<<"Randomno-
1:"<<no1<<endl<<"Randomno-
2:"<<no2<<endl;
for(i=0;i<100;i++)
{
if((Arr[i]==no1)||(Arr[i]==no2))
Display();
} }
voidmain()
{ clrscr();
HOUSING a1;
a1.Read_Data();
a1.Display();
a1.Draw_Nos();
getch();
}
9 | P a g e
Constructor and destructor
1. Define a class Tour C++ with the description given below:
Private Members:
TCodeof type string
NoofAdults of type integer
NoofKids of type integer
Kilometres of type integer
TotalFare of type float
Public Members:
1. A constructor to assign initial values as follows:
TCode with the word "NULL"
NoofAdults as 0
NoofKids as 0
Kilometres as 0
TotalFare as 0
2. A function AssignFare() which calculates and assign the value of the date
member TotalFare as follows:
For each Adult
Fare(Rs) ForKilometres
500 >=1000
300 <1000 &>=500
200 <500
For each Kid the above Fare will be 50% of the Fare mentioned in the above table.
For example:
If Distance is 850, NoofAdults=2 and NoofKids =3 ,ThenTotalFare should be
calculated as NoofAdults*30 + NoofKids *150 i.e., 2*300+3*150=1050
3. A function EnterTour() to input the values of the data members TCode,
Noofadults, NoofKids and Kilometres; and invoke the AssignFare() function
4. A Function ShowTour() which display the content of all the data members
for a Tour.
Program:-
#include<iostream.h>
#include<conio.h>
#include<string.h>
class Tour
{
char TCode[5];
int NoofAdults,NoofKids, Kilometeres,TotalFare;
public:
Tour ()
{
10 | P a g e
strcpy(TCode,"NULL");
NoofAdults=0;
NoofKids =0;
Kilometeres =0;
TotalFare=0;
}
void AssignFare()
{
int I,j;
TotalFare=0;
for(inti=0;i<NoofAdults;i++)
{
if(Kilometeres>=1000)
TotalFare+=500;
else if(Kilometeres>=500)
TotalFare+=300;
else
TotalFare+=200;
}
for(j=0;j<NoofKids;j++)
{
if(Kilometeres>=1000)
TotalFare+=500/2;
else if(Kilometeres>=500)
TotalFare+=300/2;
else
TotalFare+=200/2;
}
}
void EnterTour()
{
cout<<"Entervalue of travel code:";
cin>>TCode;
cout<<"EnterNo. of Adults:";
cin>>NoofAdults;
cout<<"EnterNo. of Children:";
cin>>NoofKids;
cout<<"EnterDistance:";
cin>>Kilometeres;
AssignFare();
}
void ShowTour()
{
cout<<"Travelcode:"<<TCode<<endl;
cout<<"Noof Adults:"<<NoofAdults<<endl;
cout<<"Noof Children:"<<NoofKids<<endl;
cout<<"Distance:"<< Kilometeres <<endl;
cout<<"TotalFare:"<<TotalFare<<endl;
}
}t;
void main()
{
clrscr();
t.EnterTour();
t.ShowTour();
getch();
}
11 | P a g e
Inheritance
1. Assume that a bank maintains two kinds of accounts for customers, one called as
savings account and the other as current account. The saving account provides
compound interest and withdrawal facilities but not cheque book facility. The
current account provides cheque book facility but no interest. Current account
holders should also maintains a minimum balance and if the balance falls below
this level, a service charge is imposed.
Create a class Account that stores customer name, account number and opening
balance.
From this derive the classes Current and saving to make them more specific to
their requirements. Include necessary member functions in order to achieve the
following tasks:
(i) Deposit an amount for a customer and update the balance
(ii) Display the account details
(iii) Compute and deposit interest
(iv)Withdraw amount for a customer after checking the balance and update the
balance.
(v) Check for the minimum balance (for current account holders), impose penalty,
if necessary, and update the balance.
Implement these without using any constructor.
Program:-
#include<process.h>
#include<iostream.h>
#include<conio.h>
#include<math.h>
int const min_bal=500;
class account
{
int ac_no;
char cu_name[20];
protected:
int o_bal;
public:
void in();
void out();
};
void account::in()
{
cout<<"Enterthe accountnumber of Customer:";
cin>>ac_no;
cout<<"Enterthe name of Customer:";
cin>>cu_name;
cout<<"Enterthe Opening Balance:";
cin>>o_bal;
}
void account::out()
{
cout<<"===============================Customer
Info========================"<<endl;
12 | P a g e
cout<<"Accountno of Customer:"<<ac_no<<endl;
cout<<"Customer Name:"<<cu_name<<endl;
cout<<"Current Opening Balance:"<<o_bal<<endl;
}
class current:public account
{
float dep,wit;
public:
void depo();
void with();
void pena();
}c;
void current::pena()
{
if(o_bal<min_bal)
{
o_bal=o_bal-150;
}
cout<<"YourTotal Amount after Penalty:"<<o_bal<<endl;
}
void current::depo()
{
if(o_bal>min_bal)
{
cout<<"Enteryour deposit Amount:";
cin>>dep;
o_bal+=dep;
account::out();
cout<<"YourTotal Amount after Deposit:"<<o_bal<<endl;
}
else
{
cout<<"YourBalance is not sufficientto open Account:"<<endl;
}
}
void current::with()
{
if(o_bal>min_bal)
{
cout<<"EnterYour amount to Withdraw:";
cin>>wit;
if(wit<o_bal-min_bal)
{
o_bal-=wit;
account::out();
cout<<"YourTotal Amount after withdraw is:"<<o_bal<<endl;
if(o_bal<min_bal)
{
pena();
}
}
else
{
account::out();
cout<<"Withdraw not Possible:"<<endl;
}
}
13 | P a g e
else
{
account::out();
cout<<"YourBalance is not sufficientto open account:"<<endl;
pena();
}
}
class savings:public account
{
float dep,wit,c_int,r,t;
public:
void depo()
{
cout<<"Enteryour deposit Amount:";
cin>>dep;
o_bal+=dep;
account::out();
cout<<"YourTotal Amount after deposit is:"<<o_bal<<endl;
}
void with()
{
cout<<"EnterYour amount to Withdraw:";
cin>>wit;
if(wit<o_bal-min_bal)
{
o_bal-=wit;
account::out();
cout<<"YourTotal Amount after withdraw is:"<<o_bal<<endl;
}
else
{
account::out();
cout<<"Withdraw not Possible:"<<endl;
}
}
void c_in()
{
cout<<o_bal<<endl;
cout<<"Enteryour rate:";
cin>>r;
cout<<"Enteryour time:";
cin>>t;
c_int=o_bal*pow(1+r/100,t)-o_bal;
o_bal+=c_int;
account::out();
cout<<"YourCompound interest is:"<<c_int<<endl;
cout<<"The Main Balance is:"<<o_bal<<endl;
}
}s;
void main()
{
int n,cu,sa;
char ch;
do
{
clrscr();
cout<<"1.CURRENT:"<<endl;
14 | P a g e
cout<<"2.SAVINGS:"<<endl;
cout<<"3.Exit:"<<endl;
cout<<"Enteryour choice:";
cin>>n;
switch(n)
{
clrscr();
case 1:
c.in();
cout<<"1.Deposit:"<<endl;
cout<<"2.Withdraw:"<<endl;
cout<<"3.Exit:"<<endl;
cout<<"Enteryour choice:";
cin>>cu;
switch(cu)
{
case 1:
c.depo();
break;
case 2:
c.with();
break;
case 3:
exit(0);
break;
}
break;
case 2:
clrscr();
s.in();
cout<<"1.Deposit:"<<endl;
cout<<"2.Withdraw:"<<endl;
cout<<"3.Compound interest:"<<endl;
cout<<"4.Exit:"<<endl;
cout<<"Enteryour choice:";
cin>>sa;
switch(sa)
{
case 1:
s.depo();
break;
case 2:
s.with();
break;
case 3:
s.c_in();
break;
case 4:
exit(0);
break;
}
break;
case 3:
exit(0);
break;
}
cout<<"EnterY or y to continue:";
15 | P a g e
cin>>ch;
}
while(ch=='Y' ||ch=='y');
getch();
}
2. Write a declaration for a class Person which has the following:
1. data members name, phone
2. set and get functions for every data member
3. a display function
4. a destructor
(i) For the Person class above, write each of the constructor, the assignment
operator, and the getName member function. Use member initialization lists as
often as possible.
(ii) Given the Person class above, write the declaration for a class Spouse that
inherits from Person and does the following:
1. has an extra data member spouseName
2. redefines the display member function.
(iii) For the Spouse class above, write each of the constructors and the display
member function. Use member initialization lists as often as possible.
Program:-
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
classPerson
{
public:
longphone;
char name[20];
voidset()
{ strcpy(name,"NULL");
phone=7878963522;
}
voidget()
{ cout<<"Enter name:";
gets(name);
cout<<"Enter phone:";
cin>>phone;
}
voiddisplay()
16 | P a g e
{ cout<<"Name:"<<name<<endl;
cout<<"Phone:"<<phone<<endl;
}
Person()
{ strcpy(name,"Rahul");
phone=9965869922;
}
Person(charna[20],longph)
{ name[20]=na[20];
phone=ph;}
voidgetName()
{ cout<<"Enter name:";
gets(name);
}
};
classSpouse:publicPerson
{
char spouseName[20];
public:
voidgetName()
{
cout<<"Enter name:";
gets(spouseName);
}
voiddisplay()
{cout<<"Name:"<<spouseName<<endl;
cout<<"Phone:"<<phone<<endl;
cout<<"spouse name:"<<spouseName<<endl;
}
Spouse()
{strcpy(spouseName,"NULL");
}};
voidmain()
{
clrscr();
Personp;
Spouse s;
p.set();
p.get();
p.display();
s.getName();
s.display();
getch();
};
3. Create the following class hierarchy in C++.
17 | P a g e
Data file handling
1. Write a program to read text file “Article.txt” and do the following
a) Find to & the.
b) Count vowels.
c) Count number of words.
d) Count Upper letters.
e) Count Digit & Special character.
Program:-
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<fstream.h>
#include<ctype.h>
#include<string.h>
classDFH
{
public:
voidopen()
{
ofstreamfi;
fi.open("Article.txt");
fi<<"See the magicof C++"<<endl;
fi.close();
}
voidTt()
{
open();
18 | P a g e
char n[80];
inta=0,d=0;
clrscr();
ifstreamf("Article.txt");
while(!f.eof())
{
f>>n;
for(inti=0;n[i]!=NULL;i++)
{
n[i]=tolower(n[i]);
}
if(strcmp(n,"to")==0)
a++;
else if(strcmp(n,"the")==0)
d++;
}
cout<<"Occurence of to in file is{"<<a<<"}Times"<<endl;
cout<<"Occurence of the infile is{"<<d<<"}Times"<<endl;
getch();
}
voidCv()
{
open();
char c;
intv=0;
clrscr();
ifstreamf("Article.txt");
while(!f.eof())
{
f.get(c);
if(c=='a'||c=='A'||c=='e'||c=='E'||c=='i'||c=='I'||c=='o'||c=='O'||c=='u'||c=='U')
{
v++;
}
}
cout<<"Total numbersvowels="<<v<<endl;
}
voidNow()
{
open();
char word[80];
intcount=0;
clrscr();
ifstreamf("Article.txt");
while(!f.eof())
{
f>>word;
count++;
}
cout<<"Numberof wordsinthe file:"<<count-1<<endl;
}
voidUp()
{
open();
char c[80];
19 | P a g e
intl=0;
clrscr();
ifstreamf("Article.txt");
while(!f.eof())
{
f>>c;
for(inti=0;c[i]!=NULL;i++)
{
if(isupper(c[i]))
{
l++;
}
}
}
cout<<"Total numbersof Upperletters="<<l<<endl;
}
voidDsc()
{
open();
char j[80];
intn=0;
clrscr();
ifstreamf("Article.txt");
while(!f.eof())
{
f>>j;
for(inti=0;j[i]!=NULL;i++)
{
if(isdigit(j[i]))
{
n++;
}
}
}
cout<<"Total numbersof digits="<<n<<endl;
}
}N;
voidmain()
{
intn;
char ch;
do
{
clrscr();
cout<<"1.Findto & the"<<endl;
cout<<"2.CountVowels"<<endl;
cout<<"3.Countno of words"<<endl;
cout<<"4.CountUpper letters"<<endl;
cout<<"5.Digit& special character"<<endl;
cout<<"6.Exit"<<endl;
cout<<"Enter yourchoice fromabove:";
cin>>n;
switch(n)
{
case 1:
20 | P a g e
N.Tt();
break;
case 2:
N.Cv();
break;
case 3:
N.Now();
break;
case 4:
N.Up();
break;
case 5:
N.Dsc();
break;
case 6:
exit(0);
break;
default:
cout<<"Wrong Choice..........!!!!!!!!!!!!!"<<endl;
}
cout<<"Enter Y or y to continue:";
cin>>ch;
}while(ch=='Y'|| ch=='y');
getch();
}
Array
Program 1:
Write a functionin C++ to print the product ofeach column of a two dimensional integerarray
passedas the argument of the function.
Explain:If the two dimensional array contains
Then the output shouldappear:
Product of Column1=24
Product of Column2=30
Product of Column3=240
#include<iostream.h>
#include<conio.h>
voidColProd(intA[4][3],intr,intc)
1 2 4
3 5 6
4 3 2
2 1 5
21 | P a g e
{ intProd[50],i,j;
for(j=0;j<c;j++)
{ Prod[j]=1;
for(i=0;i<r;i++)
Prod[j]*=A[i][j];
cout<<"Productof Column"<<j+1<<"="<<Prod[j]<<endl;}
}
voidmain()
{
intArr[4][3]={{1,2,4},{3,5,6},{4,3,2},{2,1,5}};
clrscr();
ColProd(Arr,4,3);
getch();
}
Program 2:
Write a function in C++ which accepts a 2D array of integers and its size as
arguments and display the elements which lie on diagonals.
[Assuming the 2D Array to be a square matrix with odd dimension i.e., 3 x 3, 5 x 5,
7 x 7 etc….] Example, if the array content is
5 4 3 6 7 8 1 2 9
Output through the function should be: Diagonal One: 5 7 9
Diagonal Two: 3 7 1
#include<iostream.h>
#include<conio.h>
#define max 100
void diagnol(int a[max][max],int n=3,int m=3)
{
int i,j;
cout<<"nn";
cout<<"diagonal 1";
cout<<"nn";
22 | P a g e
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{if(i==j) { cout<<a[i][j]<<"t"; }
}}
cout<<"nn";
cout<<"diagonal 2";
cout<<"nn";
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{if(i+j==m-1)
{
cout<<a[i][j]<<"t";
}
}
}
}
void main()
{
clrscr();
int a[max][max],i,j,m,n;
cout<<"enter the no. of row:";
cin>>n;
cout<<"enter the no. of column:";
cin>>m;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cout<<"enter elements a["<<i+1<<"]["<<j+1<<"];";
// cout<<"n";
cin>>a[i][j];
}
}
diagnol(a,n,m);
getch();
}
Program 3:
Insert or Delete an element in array.
#include<iostream.h>
#include<conio.h>
#include<process.h>
classID
{
public:
voidInsert()
{
inta[60],n,item,pos;
clrscr();
cout<<"Enter the no.of Elements:";
cin>>n;
for(inti=0;i<n;i++)
23 | P a g e
{
cout<<"Element["<<i+1<<"]:";
cin>>a[i];
}
cout<<"Enter the itemtobe inserted:";
cin>>item;
cout<<"Enter the position:";
cin>>pos;
for(i=n;i>=pos;i--)
{
a[i+1]=a[i];
}
a[pos]=item;
n=n+1;
cout<<"The modifiedarrayis:"<<endl;
for(i=0;i<n;i++)
{
cout<<"Element["<<i+1<<"]:"<<a[i]<<endl;
}
getch();
}
voidDelete()
{
clrscr();
inta[50],x,n,i,j,b[50];
cout<<"Enter the no of Elements:";
cin>>n;
for(i=0;i<n;++i)
{
cout<<"Element["<<i+1<<"]:";
cin>>a[i];
}
cout<<"Enter elementtodelete:";
cin>>x;
for(i=0,j=0;i<n;++i)
{
if(a[i]!=x)
{
b[j++]=a[i];
}
}
if(j==n)
{
cout<<"Soory!!!Elementisnotinthe Array";
exit(0);
}
else
{
cout<<"NewArrayis ";
for(i=0;i<j;i++)
{
cout<<"Element["<<"]:"<<b[i]<<endl;
}
}
24 | P a g e
getch();
}
}f;
voidmain()
{
intn;
char ch;
do
{
clrscr();
cout<<"1.Insert"<<endl;
cout<<"2.Delete"<<endl;
cout<<"3.Exit"<<endl;
cout<<"Enter the numberfromabove:";
cin>>n ;
switch(n)
{
case 1:
f.Insert();
break;
case 2:
f.Delete();
break;
case 3:
exit(0);
break;
default:
cout<<"Wrong Choice!!!!!!!!!!!!!!!!!!"<<endl;
}
cout<<"Enter Y or y to continue";
cin>>ch;
}while(ch=='y'||ch=='Y');
getch();
}
Program 4:
Stack
#include<iostream.h>
#include<conio.h>
#include<process.h>
#define max 5
inttop=-1;
classstack
{
int x,s[max],si;
public:
25 | P a g e
voidpush();
voidpop();
voidpeep();
voiddisplay();
}s1;
voidstack::push()
{
cout<<"Enter the Elementtoinsert:";
cin>>x;
if(top==max-1)
{
cout<<"Stack isoverflow:"<<endl;
}
else
{
top++;
s[top]=x;
cout<<"ElementPushedinstack............:"<<endl;
}
}
voidstack::pop()
{
if(top==-1)
{
cout<<"stack isUnderflow......"<<endl;
}
else
{
cout<<"Element["<<s[top]<<"] isPoped:"<<endl;
top--;
}
}
voidstack::peep()
{
cout<<"Your Elementis:"<<s[top]<<endl;
}
voidstack::display()
{for(inti=top;i>=0;i--)
{
cout<<s[i]<<endl;}
}
voidmain()
{intn;
char ch;
clrscr();
cout<<"1.Push"<<endl;
cout<<"2.Pop"<<endl;
cout<<"3.Peep"<<endl;
cout<<"4.Display"<<endl;
cout<<"5.Exit"<<endl;
do
{cout<<"Enteryour choice fromabove:";
cin>>n;
switch(n)
{case 1:
26 | P a g e
s1.push();
break;
case 2:
s1.pop();
break;
case 3:
s1.peep();
break;
case 4:
s1.display();
break;
case 5:
exit(0);
break;
default:
cout<<"Invalidchoice:"<<endl;
}
cout<<"Enter Y to continue:";
cin>>ch;
}
while(ch=='Y'||ch=='y');
getch();
}
Program 3:
Queue
#include<iostream.h>
#include<conio.h>
#include<process.h>
classqueue
27 | P a g e
{intx,f,r,q[5];
public:
queue()
{f=r=0;
}
voidinsert();
voidDelete();
voiddisplay();
}q;
voidqueue::insert()
{cout<<"Enteryour Element:";
cin>>x;
if(r<5)
{r++;
q[r]=x;
}
else
{cout<<"Queue isOverflow:"<<endl;
}
if(f==0)
{f=1;
}
}
voidqueue::Delete()
{if(f==0)
{cout<<"Quque isUnderflow:"<<endl;
}
else
{x=q[f];
cout<<"Elementisdeleted********"<<endl;
}
if(f==r)
{f=r=0;
}
else
{f+=1;
}
}
voidqueue::display()
{if(f==0|| r==0)
{
cout<<"Queue isUnderflow:"<<endl;
}
else
{for(inti=f;i<=r;i++)
{cout<<q[i]<<"";
}
}
}
voidmain()
{intn;
char ch;
clrscr();
cout<<"1.Insert"<<endl;
cout<<"2.Delete"<<endl;
28 | P a g e
cout<<"3.Display"<<endl;
cout<<"4.Exit"<<endl;
do
{
cout<<"Enter Your choice:";
cin>>n;
switch(n)
{
case 1:
q.insert();
break;
case 2:
q.Delete();
break;
case 3:
q.display();
break;
case 4:
exit(0);
break;
default:
cout<<"Invalidoption...."<<endl;
}
cout<<"Enetr y to Continue:";
cin>>ch;
}
while(ch=='Y'||ch=='y');
getch();
}
Program 4:
29 | P a g e
Dynamic stack
#include<process.h>
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct nod
{
intrno;
char sname[20];
nod*next;
};
classstack
{
nod*top;
public:
stack()
{
top=NULL;
}
voidpush()
{
nod*temp=newnod;
cout<<"Enter the valuesto push....."<<endl;
cout<<"Enter yourrollno...."<<endl;
cin>>temp->rno;
cout<<"Enter Name:";
gets(temp->sname);
temp->next=top;
top=temp;
}
voidpop()
{
nod*temp=newnod;
if(top==NULL)
{
}
else
{
temp=top;
top=top->next;
delete temp;
}
}
voiddisplay()
{
nod*temp=top;
while(temp!=NULL)
{
cout<<temp->rno<<endl;
cout<<temp->sname<<endl;
temp=temp->next;
}
}
};
voidmain()
30 | P a g e
{
stack m;
intch;
char y;
clrscr();
cout<<"1.PUSH:-"<<endl;
cout<<"2.POP:-"<<endl;
cout<<"3.DISPLAY:-"<<endl;
cout<<"4.EXIT:-"<<endl;
do{
cout<<"CHOICE ASYOUR WISH:-";
cin>>ch;
switch(ch)
{case 1:
m.push();
break;
case 2:
m.pop();
break;
case 3:
m.display();
break;
case 4:
exit(0);
break;
default:
cout<<"not a validchoice!!!!!!!!!!!!!!!!!!"<<endl;
}
cout<<"entery to continue:"<<endl;
cin>>y;
}
while(y=='y'||y=='Y') ;
getch();
}
31 | P a g e
Program 5:
Dynamic queue
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<stdio.h>
struct node
{
intcust_no;
char cust_name[20];
floatbill_amt;
node *next;
};
classqueue
{
node *front,*rear;
public:
queue()
{
front=rear=NULL;
}
voidInsertNode()
{ node *temp=newnode;
cout<<"Enter Customerno:";
cin>>temp->cust_no;
cout<<"Enter CustomerName:";
gets(temp->cust_name);
cout<<"Enter Bill Amount:";
cin>>temp->bill_amt;
if(rear==NULL)
{
rear=temp;
front=temp;
}
else
{
rear->next=temp;
rear=temp;
}
}
voidDeleteNode()
{if(front==NULL)
{
cout<<"Queue isUnderflow......"<<endl;
}
else
{
node *temp=front;
cout<<"Cutstomerno:"<<temp->cust_no<<endl;
cout<<"Cutstomername:"<<temp->cust_name<<endl;
cout<<"Cutstomerno:"<<temp->bill_amt<<endl;
32 | P a g e
cout<<"SucesfullyDeleted"<<endl;
front=front->next;
delete temp;
if(front==NULL)
{
rear==NULL;
}
}
}
voidDisplayQueue()
{
node *temp=front;
if(temp==NULL)
{
cout<<"Queue isUnderflow......"<<endl;
}
else{
while(temp!=NULL)
{cout<<"Cutstomerno:"<<temp->cust_no<<endl;
cout<<"Cutstomername:"<<temp->cust_name<<endl;
cout<<"Cutstomerno:"<<temp->bill_amt<<endl;
temp=temp->next;
}
}
}
~queue()
{node *temp=front;
if(front!=NULL);
{
front=temp;
temp=front->next;
delete temp;
}
}
}q1;
voidmain()
{ clrscr();
intn;
while(1)
{ cout<<"Enter Your Choice"<<endl;
cout<<"1. Insertnode"<<endl;
cout<<"2. Delete node"<<endl;
cout<<"3. DisplayQueue"<<endl;
cout<<"4. Exit"<<endl;
cin>>n;
switch(n)
{ case 1:
q1.InsertNode();
break;
case 2:
q1.DeleteNode();
break;
case 3:
q1.DisplayQueue();
break;
33 | P a g e
case 4:
exit(0);
break;
default:
cout<<"Invalidchoice";
} }
getch();
}
Program 6:Merege sort,Buble sort,Selection sort.
#include<iostream.h>
#include<conio.h>
#include<process.h>
# define MAX10
staticint merge_arr[MAX+MAX],sort_arr[MAX+MAX];
classMergesort{
intarr1[MAX],arr2[MAX],n1,n2,n3;
public:
voidgetdata();
voidshowdata(int);
voidmergeLogic();
voidsortLogic();
};
voidmergesort::getdata(){
inti;
cout<<"n--DataMust be EnteredinSortedOrderfor each Array--nn";
cout<<"How manyelementsyourequire 1st -> Array:";
cin>>n1;
for(i=0;i<n1;i++)
cin>>arr1[i];
cout<<"How manyelementsyourequire 2nd ->Array: ";
cin>>n2;
for(i=0;i<n2;i++)
cin>>arr2[i];
n3=n1+n2;
}
voidmergesort::showdata(intselect){
inti;
if(select==1){
cout<<"nn--Array1--n";
for(i=0;i<n1;i++)
cout<<arr1[i]<<" ";
}
else if(select==2){
cout<<"nn--Array2--n";
for(i=0;i<n2;i++)
cout<<arr2[i]<<" ";
}
else if(select==3){
cout<<"nn--SortedArray--n";
for(i=0;i<n3;i++)
cout<<sort_arr[i]<<" ";
}
}
voidmergesort::mergeLogic(){
34 | P a g e
inti,j,c;
for(i=0;i<n1;i++)
merge_arr[i] =arr1[i];
for(j=i,c=0;j<n3;j++,c++)
merge_arr[j] =arr2[c];
}
voidmergesort::sortLogic(){
//before sortcall mergeLogic
mergeLogic();
inti,j,first=0,second=n1,third=n3;
i=first;
j=second;
staticint c=0;
while(i<second&&j<third){
if(merge_arr[i] <merge_arr[j]){
sort_arr[c]=merge_arr[i];
i++;
}
else{
sort_arr[c]=merge_arr[j];
j++;
}
c++;
}
if(i<second){
while(i<second){
sort_arr[c]=merge_arr[i];
i++;
c++;
}
}
if(j<third){
while(j<third){
sort_arr[c]=merge_arr[j];
j++;
c++;
}
}
}
voidSelectsort()
{
intn,min,loc,a[40],temp;
cout<<"Enter the numberof elements:";
cin>>n;
for(inti=0;i<n;i++)
{
cout<<"Element["<<i+1<<"]:";
cin>>a[i];
}
for(i=0;i<n;i++)
{
cout<<"Your Element["<<i+1<<"]:"<<a[i]<<endl;
}
for(i=0;i<n;i++)
{
35 | P a g e
min=a[i];loc=i;
for(intj=i+1;j<n;j++)
{
if(min>a[j])
{
min=a[j];
loc=j;
}
}
temp=a[i];
a[i]=a[loc];
a[loc]=temp;
cout<<"Pass["<<i+1<<"]:";
for(j=0;j<n;j++)
{
cout<<a[j]<<" ";
}
cout<<endl;
}
}
voidBubblesort()
{
intn,a[40],j,temp;
cout<<"Enter the numberof elements:";
cin>>n;
for(inti=0;i<n;i++)
{
cout<<"Element["<<i+1<<"]:";
cin>>a[i];
}
for(i=0;i<n;i++)
{
cout<<"Your Element["<<i+1<<"]:"<<a[i]<<endl;
}
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(a[j]<a[j+1])
{
temp=a[i];
a[i]=a[j+1];
a[j+1]=temp;
}
}
cout<<"Pass{"<<i+1<<"}:";
for(j=0;j<n;j++)
{
cout<<a[j]<<" ";
}
cout<<endl;
}
}
36 | P a g e
voidmain()
{
mergesortobj;
intn;
char ch;
do
{
clrscr();
cout<<"1.Merge sort:"<<endl;
cout<<"2.Selectionsort:"<<endl;
cout<<"3.Bubble Sort:"<<endl;
cout<<"4.Exit:"<<endl;
cout<<"Enter Your Choice:";
cin>>n;
switch(n)
{
case 1:
clrscr();
obj.getdata();
obj.sortLogic();
obj.showdata(1);
obj.showdata(2);
obj.showdata(3);
break;
case 2:
clrscr();
Selectsort();
break;
case 3:
clrscr();
Bubblesort();
break;
case 4:
exit(0);
break;
default:
cout<<"Invalidoption....."<<endl;
}
cout<<"Enter Y to continue:";
cin>>ch;
}
while(ch=='Y'||ch=='y');
getch();
}
37 | P a g e
My SQL Query
1. Display the dept information from department table
Ans: select * from dept;
2. Display the name and job for all employees
Ans: select ENAME, JOB from emp;
3. Display the names of all employees who are working in department number 10
Ans: select * from emp where DEPTNO like ‘10%’;
4. Display the names of employees working in department number 10 or 20 or 40
or employees working as clerks,
salesman or analyst
Ans: select ENAME from emp where deptno in (10, 20, 40) and job in
(‘clerk’,’salesman,’analyst,’);
5. Display the names of employees in descending order of salary
Ans: select ENAME from emp order by sal desc;
6. Display name, salary, Hra, pf, da, TotalSalary for each employee.
Ans: select ENAME, sal*0.15”HRA”, (sal*0.10)”DA”, (sal*0.05)”PF”,
((sal+sal*015+sal*0.10))-sal*0.50)”Total salary” from emp;
38 | P a g e
7. Display department numbers and Maximum Salary from each Department?
Ans: select max (sal), deptno from emp group by deptno;
8. Display the department Number with more than three employees in each
department?
Ans: select deptno, count (EMPNO) from emp group by deptno having count (empno)>3;
9. Display various jobs along with total salary for each of the job where total salary
is greater than 40000?
Ans: select job, sum (sal) from emp group by job having sum (sal)>40000;
10. Display the various jobs along with total number of employees in each job.The
Output should contain only those jobs with more than three employees?
Ans: select job, count (ENAME) from emp groupby job having count (ENAME)>3;
11.To insert a new row in the ARRIVALS table with the following data;
14,”Velvet Touch”,”Double Bed”.{25/03/03},25000,30
Ans.insert into ARRIVALS values
(14,”Velvet Touch”,”Double Bed”.{25/03/03},25000,30);
12.To display the BOOK_ID,BOOK_NAME and Quantity_issued for all the books
which have been issued.
Ans.select BOOK.BOOK_ID,BOOK_NAME,QUANTITY_ISSUED
From BOOKS,ISSUED
Where BOOK.BOOKS_ID=ISSUED.BOOK_ID;
13.To display minimum rate of items for each Supplier individually as per Scode
from the table store.
Ans.select Scode,Min(rate)
From store group by Scode;
14.To increase the price of all products by 10.
Ans.update PRODUCT
SET price=Price+10;
39 | P a g e
15.To add a new column name “MARKS”
Ans.Alter table student
Add marks float(6,2);

More Related Content

What's hot

Computer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commandsComputer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commands
Vishvjeet Yadav
 
Computer Science investigatory project class 12
Computer Science investigatory project class 12Computer Science investigatory project class 12
Computer Science investigatory project class 12
Raunak Yadav
 
Oops practical file
Oops practical fileOops practical file
Oops practical fileAnkit Dixit
 
Computer science project work
Computer science project workComputer science project work
Computer science project work
rahulchamp2345
 
RAILWAY RESERWATION PROJECT PROGRAM
RAILWAY RESERWATION PROJECT PROGRAMRAILWAY RESERWATION PROJECT PROGRAM
RAILWAY RESERWATION PROJECT PROGRAM
Krishna Raj
 
Computer science Investigatory Project Class 12 C++
Computer science Investigatory Project Class 12 C++Computer science Investigatory Project Class 12 C++
Computer science Investigatory Project Class 12 C++
Rushil Aggarwal
 
project report in C++ programming and SQL
project report in C++ programming and SQLproject report in C++ programming and SQL
project report in C++ programming and SQL
vikram mahendra
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
premrings
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd marchRajeev Sharan
 
Basic Programs of C++
Basic Programs of C++Basic Programs of C++
Basic Programs of C++
Bharat Kalia
 
Ccc
CccCcc
Declaring friend function with inline code
Declaring friend function with inline codeDeclaring friend function with inline code
Declaring friend function with inline codeRajeev Sharan
 
computer project code ''payroll'' (based on datafile handling)
computer project code ''payroll'' (based on datafile handling)computer project code ''payroll'' (based on datafile handling)
computer project code ''payroll'' (based on datafile handling)
Nitish Yadav
 
Useful c programs
Useful c programsUseful c programs
Useful c programs
MD SHAH FAHAD
 
C questions
C questionsC questions
C questions
mohamed sikander
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
Farhan Ab Rahman
 
Travel management
Travel managementTravel management
Travel management1Parimal2
 
Implementing string
Implementing stringImplementing string
Implementing string
mohamed sikander
 
Student Data Base Using C/C++ Final Project
Student Data Base Using C/C++ Final ProjectStudent Data Base Using C/C++ Final Project
Student Data Base Using C/C++ Final Project
Haqnawaz Ch
 
Computer Science class 12
Computer Science  class 12Computer Science  class 12
Computer Science class 12
Abhishek Sinha
 

What's hot (20)

Computer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commandsComputer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commands
 
Computer Science investigatory project class 12
Computer Science investigatory project class 12Computer Science investigatory project class 12
Computer Science investigatory project class 12
 
Oops practical file
Oops practical fileOops practical file
Oops practical file
 
Computer science project work
Computer science project workComputer science project work
Computer science project work
 
RAILWAY RESERWATION PROJECT PROGRAM
RAILWAY RESERWATION PROJECT PROGRAMRAILWAY RESERWATION PROJECT PROGRAM
RAILWAY RESERWATION PROJECT PROGRAM
 
Computer science Investigatory Project Class 12 C++
Computer science Investigatory Project Class 12 C++Computer science Investigatory Project Class 12 C++
Computer science Investigatory Project Class 12 C++
 
project report in C++ programming and SQL
project report in C++ programming and SQLproject report in C++ programming and SQL
project report in C++ programming and SQL
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd march
 
Basic Programs of C++
Basic Programs of C++Basic Programs of C++
Basic Programs of C++
 
Ccc
CccCcc
Ccc
 
Declaring friend function with inline code
Declaring friend function with inline codeDeclaring friend function with inline code
Declaring friend function with inline code
 
computer project code ''payroll'' (based on datafile handling)
computer project code ''payroll'' (based on datafile handling)computer project code ''payroll'' (based on datafile handling)
computer project code ''payroll'' (based on datafile handling)
 
Useful c programs
Useful c programsUseful c programs
Useful c programs
 
C questions
C questionsC questions
C questions
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
 
Travel management
Travel managementTravel management
Travel management
 
Implementing string
Implementing stringImplementing string
Implementing string
 
Student Data Base Using C/C++ Final Project
Student Data Base Using C/C++ Final ProjectStudent Data Base Using C/C++ Final Project
Student Data Base Using C/C++ Final Project
 
Computer Science class 12
Computer Science  class 12Computer Science  class 12
Computer Science class 12
 

Similar to Cs pritical file

Managing console
Managing consoleManaging console
Managing console
Shiva Saxena
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
Ashwin Francis
 
Computer science-2010-cbse-question-paper
Computer science-2010-cbse-question-paperComputer science-2010-cbse-question-paper
Computer science-2010-cbse-question-paperDeepak Singh
 
C++ practical
C++ practicalC++ practical
C++ practical
Rahul juneja
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_paper
vandna123
 
CBSE Question Paper Computer Science with C++ 2011
CBSE Question Paper Computer Science with C++ 2011CBSE Question Paper Computer Science with C++ 2011
CBSE Question Paper Computer Science with C++ 2011
Deepak Singh
 
Railway reservation
Railway reservationRailway reservation
Railway reservation
Swarup Boro
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
Koshy Geoji
 
Computer Science Sample Paper 2015
Computer Science Sample Paper 2015Computer Science Sample Paper 2015
Computer Science Sample Paper 2015
Poonam Chopra
 
Ch 4
Ch 4Ch 4
Ch 4
AMIT JAIN
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
Dr.M.Karthika parthasarathy
 
C++ file
C++ fileC++ file
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in cgkgaur1987
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
HIMANSUKUMAR12
 
CBSE Class XI Programming in C++
CBSE Class XI Programming in C++CBSE Class XI Programming in C++
CBSE Class XI Programming in C++
Pranav Ghildiyal
 
oodp elab.pdf
oodp elab.pdfoodp elab.pdf
oodp elab.pdf
SWATIKUMARIRA2111030
 
programming in C++ report
programming in C++ reportprogramming in C++ report
programming in C++ report
vikram mahendra
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
kinan keshkeh
 
OOP-Lecture-05 (Constructor_Destructor).pptx
OOP-Lecture-05 (Constructor_Destructor).pptxOOP-Lecture-05 (Constructor_Destructor).pptx
OOP-Lecture-05 (Constructor_Destructor).pptx
SirRafiLectures
 
Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2
zindadili
 

Similar to Cs pritical file (20)

Managing console
Managing consoleManaging console
Managing console
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
 
Computer science-2010-cbse-question-paper
Computer science-2010-cbse-question-paperComputer science-2010-cbse-question-paper
Computer science-2010-cbse-question-paper
 
C++ practical
C++ practicalC++ practical
C++ practical
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_paper
 
CBSE Question Paper Computer Science with C++ 2011
CBSE Question Paper Computer Science with C++ 2011CBSE Question Paper Computer Science with C++ 2011
CBSE Question Paper Computer Science with C++ 2011
 
Railway reservation
Railway reservationRailway reservation
Railway reservation
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 
Computer Science Sample Paper 2015
Computer Science Sample Paper 2015Computer Science Sample Paper 2015
Computer Science Sample Paper 2015
 
Ch 4
Ch 4Ch 4
Ch 4
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
C++ file
C++ fileC++ file
C++ file
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
 
CBSE Class XI Programming in C++
CBSE Class XI Programming in C++CBSE Class XI Programming in C++
CBSE Class XI Programming in C++
 
oodp elab.pdf
oodp elab.pdfoodp elab.pdf
oodp elab.pdf
 
programming in C++ report
programming in C++ reportprogramming in C++ report
programming in C++ report
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
OOP-Lecture-05 (Constructor_Destructor).pptx
OOP-Lecture-05 (Constructor_Destructor).pptxOOP-Lecture-05 (Constructor_Destructor).pptx
OOP-Lecture-05 (Constructor_Destructor).pptx
 
Operator overloading2
Operator overloading2Operator overloading2
Operator overloading2
 

Recently uploaded

road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
SupreethSP4
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 

Recently uploaded (20)

road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 

Cs pritical file

  • 1. 1 | P a g e C++ Tour 1. Write C++ program that uses various functions to sum following series: (i) (1) + (1+2) + (1+2+3) + (1+2+3+4) +…………… upto N terms (ii) (22) + (22+42) +(22+42+62) +(22+42+62+82) up to N terms (iii) 1 + 1/3+ 1/5+ 1/7 + 1/9+….. Up to N terms. PROGRAM(i): #include<iostream.h> #include<conio.h> void main() { int k=0, m=0; clrscr(); cout<<"Enterthe limit of the series: "; cin>>m; for(inti=1;i<=m;i++) { for(intj=1;j<=i;j++) k+=j; } cout<<"Sum of the given series is: "<<k; getch(); } Program (ii) #include<iostream.h> #include<conio.h> void main() { int k=0, m=0, s=0; clrscr(); cout<<"Enter the limit of the series: "; cin>>m; for(int i=2;i<=m;i=i+2) { for(int j=2;j<=i;j=j+2) { s=j*j; k+=s; } } cout<<"Sum of the given series is: "<<k; getch(); } Program (iii) #include<iostream.h> #include<conio.h> void main() { float k, s=1; int m=0; clrscr(); cout<<"Enterthe limit of the series: "; cin>>m; for(intj=3;j<=m;j=j+2) { k=(float)1/j;s+=k; } cout<<endl; cout<<"Sum of the given series is: "<<s; getch();
  • 2. 2 | P a g e } 2. Write a program to record score of a cricket match. One array stores information of batting team such as bat'sman name, runs scored, indication if out, mode by which out along with total runs, overs played, total overs and extras. The other array stores information about bowling team such as bowler's name, over's bowled, maiden overs, runs given, and wicked taken. The program reads in the above information and depending upon the user'schoice, it displays either the batting team's information or the bowling team's information. #include<iostream.h> #include<conio.h> #include<stdio.h> struct batting {char batsman[20]; int run, out, tot_run, overs, total_over,extra; }; struct bowling {char bowler[20]; int overs, maiden_overs, runs, wicket; }; void main() {int b,f; clrscr(); batting bat_team[12]; bowling bo_team[12]; cout<<"n Enter records of batting team :nn"<<endl; cout<<"Enterthe no of bat's man:"; cin>>b; for(inti = 0; i < b ; i++) {cout<<"n Enter bat's man name :"; gets(bat_team[i].batsman); cout<<"n Enter run scored :"; cin>>bat_team[i].run; cout<<"n Type 0 NOT-OUT,Type 1 if OUT:"; cin>>bat_team[i].out; cout<<"n Enter total run :"; cin>>bat_team[i].tot_run; cout<<"n Enter no. of overs played :"; cin>>bat_team[i].overs; cout<<"n Enter total over:"; cin>>bat_team[i].total_over; cout<<"n Extra ?"; cin>>bat_team[i].extra; } cout<<"n Enter records of bowling team :nn"<<endl; cout<<"enter the no of Bowlers:"; cin>>f; for(i = 0; i < f ; i++) {cout<<"n Enter bowler'sname :"; gets(bo_team[i].bowler);
  • 3. 3 | P a g e cout<<"n Enter overs bowled :"; cin>>bo_team[i].overs; cout<<"n Enter maiden overs :"; cin>>bo_team[i].maiden_overs; cout<<"n Enter runs :"; cin>>bo_team[i].runs; cout<<"n Enter wickedtaken:"; cin>>bo_team[i].wicket;} char ch; int n; do {clrscr(); cout<<"n Enter 1 to view batting team information:"; cout<<"n Enter 2 to view bowlingteam information:"; cout<<"n Enter your choice:"; cin>>n; switch(n) {case 1: cout<<"n ************* BATTINGTEAM *************n"; cout<<"n Name t RUN-Scored Out Total-run Over's-playedTotal-OversExtra "; for(i = 0; i < b; i++) {cout<<"n"<<bat_team[i].batsman <<"t"<<bat_team[i].run<<" "; if(bat_team[i].out) cout<<"OUT"; else cout<<"NOT-OUT"; cout<< " " <<bat_team[i].tot_run<< " " <<bat_team[i].overs << " " <<bat_team[i].total_over << " "<<bat_team[i].extra;} break; case 2: cout<< "n ************* BOWLINGTEAM*************n"; cout<< "n Name t Overs_bowledMaiden-Overs Runs-Given Wicket-Taken"; for(i = 0; i < f ; i++) {cout<<"n"<<bo_team[i].bowler<< "t"<<bo_team[i].overs<< " "; cout<< " "<<bo_team[i].maiden_overs<< " "<<bo_team[i].runs<< " "<<bo_team[i].wicket<<"";} break; default: cout<< "n Wrong choice."; } cout<<"n Do youcontinue (y/n)";cin>>ch; }while(ch=='y'||ch=='Y'); getch(); }
  • 4. 4 | P a g e Classes and objects 1. Define a class Applicant in C++ with the following description: Private Members: 1. A data member ANo (Admission Number) of type long ,A data member Name of type string 2. A data member Agg (Aggregate Marks) of type float ,A data member Grade of type char 3. A member function GradeMe() to find the Grade as per the Aggregate Marks obtained by a student. Equivalent Aggregate Marks range and the respective Grades are shown as follows: Aggregate Marks Grade >=80 A less than 80 and >=65 B less than 65 ad >=50 C less than 50 D Public Members: 1. A function ENTER() to allow user to enter values for Ao, Name, Agg and call function GradeMe() to find the Grade. 2. A fuctionRESULT() to allow user to view the content of all the data members. Program:- #include<iostream.h> #include<conio.h> #include<stdio.h> class Applicant { long ANO; char NAME[25], Grade; float Agg; void GradeMe() { if(Agg>=80) Grade='A'; else if(Agg>=65 && Agg<80) Grade='B'; else if(Agg>=50 && Agg<65) Grade='C'; else if(Agg<50) Grade='D'; } public: void ENTER() {
  • 5. 5 | P a g e cout<<"EnterAdmission No:"; cin>>ANO; cout<<"EnterName of the Applicant :"; gets(NAME); cout<<"EnterAggregare Marks obtained by the Candidate out of 100:"; cin>>Agg; GradeMe(); } void RESULT() { cout<<"*******Applicat Details***********"<<endl; cout<<"Admission No: "<<ANO<<endl; cout<<"Name of the Applicant: "<<NAME<<endl; cout<<”Aggregare Marks obtained by the Candidate out of 100:"<<Agg<<endl; cout<<"Grade Obtained: "<<Grade<<endl; } }; void main() { clrscr(); Applicant a1; a1.ENTER(); a1.RESULT(); getch(); }
  • 6. 6 | P a g e 2. Write a C++ program to perform various operations on a string class without using language supported built-in string functions. The operations on a class are: a) Read a string b) Display the string c) Reverse the string d) Copy the string into an empty string e) Concatenate two strings Program: #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> #include<process.h> class string {char str1[20]; char str2[20]; public: void read() {cout<<"nEnter string :=> "; cin>>str1; } void Display() {cout<<endl<<"The entered string is: "<<str1; } void reverse(); void copy(); void concatenate();}; void string::reverse() {inti,l,j=0; cout<<"nEnter string :=> "; cin>>str1; l=strlen(str1); for(i=l-1;i>=0;i--) {str2[j]=str1[i]; j++; } str2[j]='0'; cout<<"Reverse is: "<<str2; } void string::copy() {int i; cout<<"nEnter string :=> "; cin>>str1; for(i=0;i<=strlen(str1);i++) { str2[i]=str1[i]; }
  • 7. 7 | P a g e str2[i]='0'; cout<<"Copy is: "<<str2; } void string::concatenate() {inti,l; cout<<"nEnter string1 :=> "; cin>>str1; cout<<"nEnter string2 :=> "; cin>>str2; l=strlen(str1); for(i=0;i<=l;i++) {str1[l+i]=str2[i]; } cout<<"Copy is: "<<str1; } void main() { clrscr(); int choice; string s1; l1: cout<<"n1.Read the string"<<endl; cout<<"2.Display the string "<<endl; cout<<"3.Reverse the string"<<endl; cout<<"4.Copy the string"<<endl; cout<<"5.Concatenate two strings"<<endl; cout<<"6.Exit"<<endl; cout<<"Enteryour choice:"; cin>>choice; switch(choice) {case 1: s1.read(); goto l1; break; case 2: s1.Display(); goto l1; break; case 3: s1.reverse(); goto l1; break; case 4: s1.copy(); goto l1; break; case 5: s1.concatenate(); goto l1; break; case 6: exit(0); break; } getch();
  • 8. 8 | P a g e } 3. Define a class named HOUSING in C++ with the following description: Private Members: REG_NO integer (Ranges 10 - 2000) NAME Array of characters (String) TYPE Character COST Float Public Members: 1. Function Read_Data() to read an object of HOUSING type. Function Display() to display the details of an object. 2. Function Draw-Nos() to choose and display the details of 2 houses selected randomly from an array of 10 objects of type HOUSING. Use randomfunction to generate the registration nos. to match with REG_NO from the array. Program: #include<iostream.h> #include<conio.h> #include<stdio.h> #include<stdlib.h> classHOUSING {private: intREG_NO; char NAME[50]; char TYPE[20]; floatCOST; public: voidRead_Data(); voidDisplay(); voidDraw_Nos(); }; voidHOUSING::Read_Data() {cout<<"Enter RegNo(10 - 1000): "; cin>>REG_NO; cout<<"Name:"; gets(NAME); cout<<"Type:"; gets(TYPE); cout<<"Cost: "; cin>>COST; } voidHOUSING::Display() {cout<<"RegNo:"<<REG_NO<<endl; cout<<"Name:"<<NAME<<endl; cout<<"Type:"<<TYPE<<endl; cout<<"Cost: "<<COST<<endl; } voidHOUSING::Draw_Nos() {intArr[5]; intno1,no2,i; randomize(); no1=random(991)+10; cout<<"Randomno- 1:"<<no1<<endl<<"Randomno- 2:"<<no2<<endl; for(i=0;i<100;i++) { if((Arr[i]==no1)||(Arr[i]==no2)) Display(); } } voidmain() { clrscr(); HOUSING a1; a1.Read_Data(); a1.Display(); a1.Draw_Nos(); getch(); }
  • 9. 9 | P a g e Constructor and destructor 1. Define a class Tour C++ with the description given below: Private Members: TCodeof type string NoofAdults of type integer NoofKids of type integer Kilometres of type integer TotalFare of type float Public Members: 1. A constructor to assign initial values as follows: TCode with the word "NULL" NoofAdults as 0 NoofKids as 0 Kilometres as 0 TotalFare as 0 2. A function AssignFare() which calculates and assign the value of the date member TotalFare as follows: For each Adult Fare(Rs) ForKilometres 500 >=1000 300 <1000 &>=500 200 <500 For each Kid the above Fare will be 50% of the Fare mentioned in the above table. For example: If Distance is 850, NoofAdults=2 and NoofKids =3 ,ThenTotalFare should be calculated as NoofAdults*30 + NoofKids *150 i.e., 2*300+3*150=1050 3. A function EnterTour() to input the values of the data members TCode, Noofadults, NoofKids and Kilometres; and invoke the AssignFare() function 4. A Function ShowTour() which display the content of all the data members for a Tour. Program:- #include<iostream.h> #include<conio.h> #include<string.h> class Tour { char TCode[5]; int NoofAdults,NoofKids, Kilometeres,TotalFare; public: Tour () {
  • 10. 10 | P a g e strcpy(TCode,"NULL"); NoofAdults=0; NoofKids =0; Kilometeres =0; TotalFare=0; } void AssignFare() { int I,j; TotalFare=0; for(inti=0;i<NoofAdults;i++) { if(Kilometeres>=1000) TotalFare+=500; else if(Kilometeres>=500) TotalFare+=300; else TotalFare+=200; } for(j=0;j<NoofKids;j++) { if(Kilometeres>=1000) TotalFare+=500/2; else if(Kilometeres>=500) TotalFare+=300/2; else TotalFare+=200/2; } } void EnterTour() { cout<<"Entervalue of travel code:"; cin>>TCode; cout<<"EnterNo. of Adults:"; cin>>NoofAdults; cout<<"EnterNo. of Children:"; cin>>NoofKids; cout<<"EnterDistance:"; cin>>Kilometeres; AssignFare(); } void ShowTour() { cout<<"Travelcode:"<<TCode<<endl; cout<<"Noof Adults:"<<NoofAdults<<endl; cout<<"Noof Children:"<<NoofKids<<endl; cout<<"Distance:"<< Kilometeres <<endl; cout<<"TotalFare:"<<TotalFare<<endl; } }t; void main() { clrscr(); t.EnterTour(); t.ShowTour(); getch(); }
  • 11. 11 | P a g e Inheritance 1. Assume that a bank maintains two kinds of accounts for customers, one called as savings account and the other as current account. The saving account provides compound interest and withdrawal facilities but not cheque book facility. The current account provides cheque book facility but no interest. Current account holders should also maintains a minimum balance and if the balance falls below this level, a service charge is imposed. Create a class Account that stores customer name, account number and opening balance. From this derive the classes Current and saving to make them more specific to their requirements. Include necessary member functions in order to achieve the following tasks: (i) Deposit an amount for a customer and update the balance (ii) Display the account details (iii) Compute and deposit interest (iv)Withdraw amount for a customer after checking the balance and update the balance. (v) Check for the minimum balance (for current account holders), impose penalty, if necessary, and update the balance. Implement these without using any constructor. Program:- #include<process.h> #include<iostream.h> #include<conio.h> #include<math.h> int const min_bal=500; class account { int ac_no; char cu_name[20]; protected: int o_bal; public: void in(); void out(); }; void account::in() { cout<<"Enterthe accountnumber of Customer:"; cin>>ac_no; cout<<"Enterthe name of Customer:"; cin>>cu_name; cout<<"Enterthe Opening Balance:"; cin>>o_bal; } void account::out() { cout<<"===============================Customer Info========================"<<endl;
  • 12. 12 | P a g e cout<<"Accountno of Customer:"<<ac_no<<endl; cout<<"Customer Name:"<<cu_name<<endl; cout<<"Current Opening Balance:"<<o_bal<<endl; } class current:public account { float dep,wit; public: void depo(); void with(); void pena(); }c; void current::pena() { if(o_bal<min_bal) { o_bal=o_bal-150; } cout<<"YourTotal Amount after Penalty:"<<o_bal<<endl; } void current::depo() { if(o_bal>min_bal) { cout<<"Enteryour deposit Amount:"; cin>>dep; o_bal+=dep; account::out(); cout<<"YourTotal Amount after Deposit:"<<o_bal<<endl; } else { cout<<"YourBalance is not sufficientto open Account:"<<endl; } } void current::with() { if(o_bal>min_bal) { cout<<"EnterYour amount to Withdraw:"; cin>>wit; if(wit<o_bal-min_bal) { o_bal-=wit; account::out(); cout<<"YourTotal Amount after withdraw is:"<<o_bal<<endl; if(o_bal<min_bal) { pena(); } } else { account::out(); cout<<"Withdraw not Possible:"<<endl; } }
  • 13. 13 | P a g e else { account::out(); cout<<"YourBalance is not sufficientto open account:"<<endl; pena(); } } class savings:public account { float dep,wit,c_int,r,t; public: void depo() { cout<<"Enteryour deposit Amount:"; cin>>dep; o_bal+=dep; account::out(); cout<<"YourTotal Amount after deposit is:"<<o_bal<<endl; } void with() { cout<<"EnterYour amount to Withdraw:"; cin>>wit; if(wit<o_bal-min_bal) { o_bal-=wit; account::out(); cout<<"YourTotal Amount after withdraw is:"<<o_bal<<endl; } else { account::out(); cout<<"Withdraw not Possible:"<<endl; } } void c_in() { cout<<o_bal<<endl; cout<<"Enteryour rate:"; cin>>r; cout<<"Enteryour time:"; cin>>t; c_int=o_bal*pow(1+r/100,t)-o_bal; o_bal+=c_int; account::out(); cout<<"YourCompound interest is:"<<c_int<<endl; cout<<"The Main Balance is:"<<o_bal<<endl; } }s; void main() { int n,cu,sa; char ch; do { clrscr(); cout<<"1.CURRENT:"<<endl;
  • 14. 14 | P a g e cout<<"2.SAVINGS:"<<endl; cout<<"3.Exit:"<<endl; cout<<"Enteryour choice:"; cin>>n; switch(n) { clrscr(); case 1: c.in(); cout<<"1.Deposit:"<<endl; cout<<"2.Withdraw:"<<endl; cout<<"3.Exit:"<<endl; cout<<"Enteryour choice:"; cin>>cu; switch(cu) { case 1: c.depo(); break; case 2: c.with(); break; case 3: exit(0); break; } break; case 2: clrscr(); s.in(); cout<<"1.Deposit:"<<endl; cout<<"2.Withdraw:"<<endl; cout<<"3.Compound interest:"<<endl; cout<<"4.Exit:"<<endl; cout<<"Enteryour choice:"; cin>>sa; switch(sa) { case 1: s.depo(); break; case 2: s.with(); break; case 3: s.c_in(); break; case 4: exit(0); break; } break; case 3: exit(0); break; } cout<<"EnterY or y to continue:";
  • 15. 15 | P a g e cin>>ch; } while(ch=='Y' ||ch=='y'); getch(); } 2. Write a declaration for a class Person which has the following: 1. data members name, phone 2. set and get functions for every data member 3. a display function 4. a destructor (i) For the Person class above, write each of the constructor, the assignment operator, and the getName member function. Use member initialization lists as often as possible. (ii) Given the Person class above, write the declaration for a class Spouse that inherits from Person and does the following: 1. has an extra data member spouseName 2. redefines the display member function. (iii) For the Spouse class above, write each of the constructors and the display member function. Use member initialization lists as often as possible. Program:- #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> classPerson { public: longphone; char name[20]; voidset() { strcpy(name,"NULL"); phone=7878963522; } voidget() { cout<<"Enter name:"; gets(name); cout<<"Enter phone:"; cin>>phone; } voiddisplay()
  • 16. 16 | P a g e { cout<<"Name:"<<name<<endl; cout<<"Phone:"<<phone<<endl; } Person() { strcpy(name,"Rahul"); phone=9965869922; } Person(charna[20],longph) { name[20]=na[20]; phone=ph;} voidgetName() { cout<<"Enter name:"; gets(name); } }; classSpouse:publicPerson { char spouseName[20]; public: voidgetName() { cout<<"Enter name:"; gets(spouseName); } voiddisplay() {cout<<"Name:"<<spouseName<<endl; cout<<"Phone:"<<phone<<endl; cout<<"spouse name:"<<spouseName<<endl; } Spouse() {strcpy(spouseName,"NULL"); }}; voidmain() { clrscr(); Personp; Spouse s; p.set(); p.get(); p.display(); s.getName(); s.display(); getch(); }; 3. Create the following class hierarchy in C++.
  • 17. 17 | P a g e Data file handling 1. Write a program to read text file “Article.txt” and do the following a) Find to & the. b) Count vowels. c) Count number of words. d) Count Upper letters. e) Count Digit & Special character. Program:- #include<iostream.h> #include<conio.h> #include<process.h> #include<fstream.h> #include<ctype.h> #include<string.h> classDFH { public: voidopen() { ofstreamfi; fi.open("Article.txt"); fi<<"See the magicof C++"<<endl; fi.close(); } voidTt() { open();
  • 18. 18 | P a g e char n[80]; inta=0,d=0; clrscr(); ifstreamf("Article.txt"); while(!f.eof()) { f>>n; for(inti=0;n[i]!=NULL;i++) { n[i]=tolower(n[i]); } if(strcmp(n,"to")==0) a++; else if(strcmp(n,"the")==0) d++; } cout<<"Occurence of to in file is{"<<a<<"}Times"<<endl; cout<<"Occurence of the infile is{"<<d<<"}Times"<<endl; getch(); } voidCv() { open(); char c; intv=0; clrscr(); ifstreamf("Article.txt"); while(!f.eof()) { f.get(c); if(c=='a'||c=='A'||c=='e'||c=='E'||c=='i'||c=='I'||c=='o'||c=='O'||c=='u'||c=='U') { v++; } } cout<<"Total numbersvowels="<<v<<endl; } voidNow() { open(); char word[80]; intcount=0; clrscr(); ifstreamf("Article.txt"); while(!f.eof()) { f>>word; count++; } cout<<"Numberof wordsinthe file:"<<count-1<<endl; } voidUp() { open(); char c[80];
  • 19. 19 | P a g e intl=0; clrscr(); ifstreamf("Article.txt"); while(!f.eof()) { f>>c; for(inti=0;c[i]!=NULL;i++) { if(isupper(c[i])) { l++; } } } cout<<"Total numbersof Upperletters="<<l<<endl; } voidDsc() { open(); char j[80]; intn=0; clrscr(); ifstreamf("Article.txt"); while(!f.eof()) { f>>j; for(inti=0;j[i]!=NULL;i++) { if(isdigit(j[i])) { n++; } } } cout<<"Total numbersof digits="<<n<<endl; } }N; voidmain() { intn; char ch; do { clrscr(); cout<<"1.Findto & the"<<endl; cout<<"2.CountVowels"<<endl; cout<<"3.Countno of words"<<endl; cout<<"4.CountUpper letters"<<endl; cout<<"5.Digit& special character"<<endl; cout<<"6.Exit"<<endl; cout<<"Enter yourchoice fromabove:"; cin>>n; switch(n) { case 1:
  • 20. 20 | P a g e N.Tt(); break; case 2: N.Cv(); break; case 3: N.Now(); break; case 4: N.Up(); break; case 5: N.Dsc(); break; case 6: exit(0); break; default: cout<<"Wrong Choice..........!!!!!!!!!!!!!"<<endl; } cout<<"Enter Y or y to continue:"; cin>>ch; }while(ch=='Y'|| ch=='y'); getch(); } Array Program 1: Write a functionin C++ to print the product ofeach column of a two dimensional integerarray passedas the argument of the function. Explain:If the two dimensional array contains Then the output shouldappear: Product of Column1=24 Product of Column2=30 Product of Column3=240 #include<iostream.h> #include<conio.h> voidColProd(intA[4][3],intr,intc) 1 2 4 3 5 6 4 3 2 2 1 5
  • 21. 21 | P a g e { intProd[50],i,j; for(j=0;j<c;j++) { Prod[j]=1; for(i=0;i<r;i++) Prod[j]*=A[i][j]; cout<<"Productof Column"<<j+1<<"="<<Prod[j]<<endl;} } voidmain() { intArr[4][3]={{1,2,4},{3,5,6},{4,3,2},{2,1,5}}; clrscr(); ColProd(Arr,4,3); getch(); } Program 2: Write a function in C++ which accepts a 2D array of integers and its size as arguments and display the elements which lie on diagonals. [Assuming the 2D Array to be a square matrix with odd dimension i.e., 3 x 3, 5 x 5, 7 x 7 etc….] Example, if the array content is 5 4 3 6 7 8 1 2 9 Output through the function should be: Diagonal One: 5 7 9 Diagonal Two: 3 7 1 #include<iostream.h> #include<conio.h> #define max 100 void diagnol(int a[max][max],int n=3,int m=3) { int i,j; cout<<"nn"; cout<<"diagonal 1"; cout<<"nn";
  • 22. 22 | P a g e for(i=0;i<3;i++) { for(j=0;j<3;j++) {if(i==j) { cout<<a[i][j]<<"t"; } }} cout<<"nn"; cout<<"diagonal 2"; cout<<"nn"; for(i=0;i<n;i++) { for(j=0;j<m;j++) {if(i+j==m-1) { cout<<a[i][j]<<"t"; } } } } void main() { clrscr(); int a[max][max],i,j,m,n; cout<<"enter the no. of row:"; cin>>n; cout<<"enter the no. of column:"; cin>>m; for(i=0;i<n;i++) { for(j=0;j<m;j++) { cout<<"enter elements a["<<i+1<<"]["<<j+1<<"];"; // cout<<"n"; cin>>a[i][j]; } } diagnol(a,n,m); getch(); } Program 3: Insert or Delete an element in array. #include<iostream.h> #include<conio.h> #include<process.h> classID { public: voidInsert() { inta[60],n,item,pos; clrscr(); cout<<"Enter the no.of Elements:"; cin>>n; for(inti=0;i<n;i++)
  • 23. 23 | P a g e { cout<<"Element["<<i+1<<"]:"; cin>>a[i]; } cout<<"Enter the itemtobe inserted:"; cin>>item; cout<<"Enter the position:"; cin>>pos; for(i=n;i>=pos;i--) { a[i+1]=a[i]; } a[pos]=item; n=n+1; cout<<"The modifiedarrayis:"<<endl; for(i=0;i<n;i++) { cout<<"Element["<<i+1<<"]:"<<a[i]<<endl; } getch(); } voidDelete() { clrscr(); inta[50],x,n,i,j,b[50]; cout<<"Enter the no of Elements:"; cin>>n; for(i=0;i<n;++i) { cout<<"Element["<<i+1<<"]:"; cin>>a[i]; } cout<<"Enter elementtodelete:"; cin>>x; for(i=0,j=0;i<n;++i) { if(a[i]!=x) { b[j++]=a[i]; } } if(j==n) { cout<<"Soory!!!Elementisnotinthe Array"; exit(0); } else { cout<<"NewArrayis "; for(i=0;i<j;i++) { cout<<"Element["<<"]:"<<b[i]<<endl; } }
  • 24. 24 | P a g e getch(); } }f; voidmain() { intn; char ch; do { clrscr(); cout<<"1.Insert"<<endl; cout<<"2.Delete"<<endl; cout<<"3.Exit"<<endl; cout<<"Enter the numberfromabove:"; cin>>n ; switch(n) { case 1: f.Insert(); break; case 2: f.Delete(); break; case 3: exit(0); break; default: cout<<"Wrong Choice!!!!!!!!!!!!!!!!!!"<<endl; } cout<<"Enter Y or y to continue"; cin>>ch; }while(ch=='y'||ch=='Y'); getch(); } Program 4: Stack #include<iostream.h> #include<conio.h> #include<process.h> #define max 5 inttop=-1; classstack { int x,s[max],si; public:
  • 25. 25 | P a g e voidpush(); voidpop(); voidpeep(); voiddisplay(); }s1; voidstack::push() { cout<<"Enter the Elementtoinsert:"; cin>>x; if(top==max-1) { cout<<"Stack isoverflow:"<<endl; } else { top++; s[top]=x; cout<<"ElementPushedinstack............:"<<endl; } } voidstack::pop() { if(top==-1) { cout<<"stack isUnderflow......"<<endl; } else { cout<<"Element["<<s[top]<<"] isPoped:"<<endl; top--; } } voidstack::peep() { cout<<"Your Elementis:"<<s[top]<<endl; } voidstack::display() {for(inti=top;i>=0;i--) { cout<<s[i]<<endl;} } voidmain() {intn; char ch; clrscr(); cout<<"1.Push"<<endl; cout<<"2.Pop"<<endl; cout<<"3.Peep"<<endl; cout<<"4.Display"<<endl; cout<<"5.Exit"<<endl; do {cout<<"Enteryour choice fromabove:"; cin>>n; switch(n) {case 1:
  • 26. 26 | P a g e s1.push(); break; case 2: s1.pop(); break; case 3: s1.peep(); break; case 4: s1.display(); break; case 5: exit(0); break; default: cout<<"Invalidchoice:"<<endl; } cout<<"Enter Y to continue:"; cin>>ch; } while(ch=='Y'||ch=='y'); getch(); } Program 3: Queue #include<iostream.h> #include<conio.h> #include<process.h> classqueue
  • 27. 27 | P a g e {intx,f,r,q[5]; public: queue() {f=r=0; } voidinsert(); voidDelete(); voiddisplay(); }q; voidqueue::insert() {cout<<"Enteryour Element:"; cin>>x; if(r<5) {r++; q[r]=x; } else {cout<<"Queue isOverflow:"<<endl; } if(f==0) {f=1; } } voidqueue::Delete() {if(f==0) {cout<<"Quque isUnderflow:"<<endl; } else {x=q[f]; cout<<"Elementisdeleted********"<<endl; } if(f==r) {f=r=0; } else {f+=1; } } voidqueue::display() {if(f==0|| r==0) { cout<<"Queue isUnderflow:"<<endl; } else {for(inti=f;i<=r;i++) {cout<<q[i]<<""; } } } voidmain() {intn; char ch; clrscr(); cout<<"1.Insert"<<endl; cout<<"2.Delete"<<endl;
  • 28. 28 | P a g e cout<<"3.Display"<<endl; cout<<"4.Exit"<<endl; do { cout<<"Enter Your choice:"; cin>>n; switch(n) { case 1: q.insert(); break; case 2: q.Delete(); break; case 3: q.display(); break; case 4: exit(0); break; default: cout<<"Invalidoption...."<<endl; } cout<<"Enetr y to Continue:"; cin>>ch; } while(ch=='Y'||ch=='y'); getch(); } Program 4:
  • 29. 29 | P a g e Dynamic stack #include<process.h> #include<iostream.h> #include<conio.h> #include<stdio.h> struct nod { intrno; char sname[20]; nod*next; }; classstack { nod*top; public: stack() { top=NULL; } voidpush() { nod*temp=newnod; cout<<"Enter the valuesto push....."<<endl; cout<<"Enter yourrollno...."<<endl; cin>>temp->rno; cout<<"Enter Name:"; gets(temp->sname); temp->next=top; top=temp; } voidpop() { nod*temp=newnod; if(top==NULL) { } else { temp=top; top=top->next; delete temp; } } voiddisplay() { nod*temp=top; while(temp!=NULL) { cout<<temp->rno<<endl; cout<<temp->sname<<endl; temp=temp->next; } } }; voidmain()
  • 30. 30 | P a g e { stack m; intch; char y; clrscr(); cout<<"1.PUSH:-"<<endl; cout<<"2.POP:-"<<endl; cout<<"3.DISPLAY:-"<<endl; cout<<"4.EXIT:-"<<endl; do{ cout<<"CHOICE ASYOUR WISH:-"; cin>>ch; switch(ch) {case 1: m.push(); break; case 2: m.pop(); break; case 3: m.display(); break; case 4: exit(0); break; default: cout<<"not a validchoice!!!!!!!!!!!!!!!!!!"<<endl; } cout<<"entery to continue:"<<endl; cin>>y; } while(y=='y'||y=='Y') ; getch(); }
  • 31. 31 | P a g e Program 5: Dynamic queue #include<iostream.h> #include<conio.h> #include<process.h> #include<stdio.h> struct node { intcust_no; char cust_name[20]; floatbill_amt; node *next; }; classqueue { node *front,*rear; public: queue() { front=rear=NULL; } voidInsertNode() { node *temp=newnode; cout<<"Enter Customerno:"; cin>>temp->cust_no; cout<<"Enter CustomerName:"; gets(temp->cust_name); cout<<"Enter Bill Amount:"; cin>>temp->bill_amt; if(rear==NULL) { rear=temp; front=temp; } else { rear->next=temp; rear=temp; } } voidDeleteNode() {if(front==NULL) { cout<<"Queue isUnderflow......"<<endl; } else { node *temp=front; cout<<"Cutstomerno:"<<temp->cust_no<<endl; cout<<"Cutstomername:"<<temp->cust_name<<endl; cout<<"Cutstomerno:"<<temp->bill_amt<<endl;
  • 32. 32 | P a g e cout<<"SucesfullyDeleted"<<endl; front=front->next; delete temp; if(front==NULL) { rear==NULL; } } } voidDisplayQueue() { node *temp=front; if(temp==NULL) { cout<<"Queue isUnderflow......"<<endl; } else{ while(temp!=NULL) {cout<<"Cutstomerno:"<<temp->cust_no<<endl; cout<<"Cutstomername:"<<temp->cust_name<<endl; cout<<"Cutstomerno:"<<temp->bill_amt<<endl; temp=temp->next; } } } ~queue() {node *temp=front; if(front!=NULL); { front=temp; temp=front->next; delete temp; } } }q1; voidmain() { clrscr(); intn; while(1) { cout<<"Enter Your Choice"<<endl; cout<<"1. Insertnode"<<endl; cout<<"2. Delete node"<<endl; cout<<"3. DisplayQueue"<<endl; cout<<"4. Exit"<<endl; cin>>n; switch(n) { case 1: q1.InsertNode(); break; case 2: q1.DeleteNode(); break; case 3: q1.DisplayQueue(); break;
  • 33. 33 | P a g e case 4: exit(0); break; default: cout<<"Invalidchoice"; } } getch(); } Program 6:Merege sort,Buble sort,Selection sort. #include<iostream.h> #include<conio.h> #include<process.h> # define MAX10 staticint merge_arr[MAX+MAX],sort_arr[MAX+MAX]; classMergesort{ intarr1[MAX],arr2[MAX],n1,n2,n3; public: voidgetdata(); voidshowdata(int); voidmergeLogic(); voidsortLogic(); }; voidmergesort::getdata(){ inti; cout<<"n--DataMust be EnteredinSortedOrderfor each Array--nn"; cout<<"How manyelementsyourequire 1st -> Array:"; cin>>n1; for(i=0;i<n1;i++) cin>>arr1[i]; cout<<"How manyelementsyourequire 2nd ->Array: "; cin>>n2; for(i=0;i<n2;i++) cin>>arr2[i]; n3=n1+n2; } voidmergesort::showdata(intselect){ inti; if(select==1){ cout<<"nn--Array1--n"; for(i=0;i<n1;i++) cout<<arr1[i]<<" "; } else if(select==2){ cout<<"nn--Array2--n"; for(i=0;i<n2;i++) cout<<arr2[i]<<" "; } else if(select==3){ cout<<"nn--SortedArray--n"; for(i=0;i<n3;i++) cout<<sort_arr[i]<<" "; } } voidmergesort::mergeLogic(){
  • 34. 34 | P a g e inti,j,c; for(i=0;i<n1;i++) merge_arr[i] =arr1[i]; for(j=i,c=0;j<n3;j++,c++) merge_arr[j] =arr2[c]; } voidmergesort::sortLogic(){ //before sortcall mergeLogic mergeLogic(); inti,j,first=0,second=n1,third=n3; i=first; j=second; staticint c=0; while(i<second&&j<third){ if(merge_arr[i] <merge_arr[j]){ sort_arr[c]=merge_arr[i]; i++; } else{ sort_arr[c]=merge_arr[j]; j++; } c++; } if(i<second){ while(i<second){ sort_arr[c]=merge_arr[i]; i++; c++; } } if(j<third){ while(j<third){ sort_arr[c]=merge_arr[j]; j++; c++; } } } voidSelectsort() { intn,min,loc,a[40],temp; cout<<"Enter the numberof elements:"; cin>>n; for(inti=0;i<n;i++) { cout<<"Element["<<i+1<<"]:"; cin>>a[i]; } for(i=0;i<n;i++) { cout<<"Your Element["<<i+1<<"]:"<<a[i]<<endl; } for(i=0;i<n;i++) {
  • 35. 35 | P a g e min=a[i];loc=i; for(intj=i+1;j<n;j++) { if(min>a[j]) { min=a[j]; loc=j; } } temp=a[i]; a[i]=a[loc]; a[loc]=temp; cout<<"Pass["<<i+1<<"]:"; for(j=0;j<n;j++) { cout<<a[j]<<" "; } cout<<endl; } } voidBubblesort() { intn,a[40],j,temp; cout<<"Enter the numberof elements:"; cin>>n; for(inti=0;i<n;i++) { cout<<"Element["<<i+1<<"]:"; cin>>a[i]; } for(i=0;i<n;i++) { cout<<"Your Element["<<i+1<<"]:"<<a[i]<<endl; } for(i=0;i<n;i++) { for(j=0;j<n-1;j++) { if(a[j]<a[j+1]) { temp=a[i]; a[i]=a[j+1]; a[j+1]=temp; } } cout<<"Pass{"<<i+1<<"}:"; for(j=0;j<n;j++) { cout<<a[j]<<" "; } cout<<endl; } }
  • 36. 36 | P a g e voidmain() { mergesortobj; intn; char ch; do { clrscr(); cout<<"1.Merge sort:"<<endl; cout<<"2.Selectionsort:"<<endl; cout<<"3.Bubble Sort:"<<endl; cout<<"4.Exit:"<<endl; cout<<"Enter Your Choice:"; cin>>n; switch(n) { case 1: clrscr(); obj.getdata(); obj.sortLogic(); obj.showdata(1); obj.showdata(2); obj.showdata(3); break; case 2: clrscr(); Selectsort(); break; case 3: clrscr(); Bubblesort(); break; case 4: exit(0); break; default: cout<<"Invalidoption....."<<endl; } cout<<"Enter Y to continue:"; cin>>ch; } while(ch=='Y'||ch=='y'); getch(); }
  • 37. 37 | P a g e My SQL Query 1. Display the dept information from department table Ans: select * from dept; 2. Display the name and job for all employees Ans: select ENAME, JOB from emp; 3. Display the names of all employees who are working in department number 10 Ans: select * from emp where DEPTNO like ‘10%’; 4. Display the names of employees working in department number 10 or 20 or 40 or employees working as clerks, salesman or analyst Ans: select ENAME from emp where deptno in (10, 20, 40) and job in (‘clerk’,’salesman,’analyst,’); 5. Display the names of employees in descending order of salary Ans: select ENAME from emp order by sal desc; 6. Display name, salary, Hra, pf, da, TotalSalary for each employee. Ans: select ENAME, sal*0.15”HRA”, (sal*0.10)”DA”, (sal*0.05)”PF”, ((sal+sal*015+sal*0.10))-sal*0.50)”Total salary” from emp;
  • 38. 38 | P a g e 7. Display department numbers and Maximum Salary from each Department? Ans: select max (sal), deptno from emp group by deptno; 8. Display the department Number with more than three employees in each department? Ans: select deptno, count (EMPNO) from emp group by deptno having count (empno)>3; 9. Display various jobs along with total salary for each of the job where total salary is greater than 40000? Ans: select job, sum (sal) from emp group by job having sum (sal)>40000; 10. Display the various jobs along with total number of employees in each job.The Output should contain only those jobs with more than three employees? Ans: select job, count (ENAME) from emp groupby job having count (ENAME)>3; 11.To insert a new row in the ARRIVALS table with the following data; 14,”Velvet Touch”,”Double Bed”.{25/03/03},25000,30 Ans.insert into ARRIVALS values (14,”Velvet Touch”,”Double Bed”.{25/03/03},25000,30); 12.To display the BOOK_ID,BOOK_NAME and Quantity_issued for all the books which have been issued. Ans.select BOOK.BOOK_ID,BOOK_NAME,QUANTITY_ISSUED From BOOKS,ISSUED Where BOOK.BOOKS_ID=ISSUED.BOOK_ID; 13.To display minimum rate of items for each Supplier individually as per Scode from the table store. Ans.select Scode,Min(rate) From store group by Scode; 14.To increase the price of all products by 10. Ans.update PRODUCT SET price=Price+10;
  • 39. 39 | P a g e 15.To add a new column name “MARKS” Ans.Alter table student Add marks float(6,2);