Vous êtes sur la page 1sur 102

ARRAY

Q1.write a c++ program to find the location of an element in an array using search process considering the element in ascending order using binary search method. DATE: 1oct,2010 FILE NAME: arr #include<iostream.h> #include<conio.h> void main() { clrscr(); int arr[100]; int first,middle,last; int i,n,pos,x; cout<<"\nenter the size of array\n"; cin>>n; for(i=0;i<n;i++) { cout<<"\nenter the element\n"; cin>>arr[i]; }first=0; pos=-1; last=n-1; cout<<"\nenter the value to be searched"; cin>>x; while((first<=last)&&(pos==-1)) { middle=(first+last)/2; if(arr[middle]==x) pos=middle; else if(arr[middle]<x) first=middle+1; else last=middle-1; } if(pos>-1) cout<<"\nthe position of the element="<<pos; else cout<<"\unseccessful search"; } INPUT: Enter the size of array: 4

Enter Enter Enter Enter Enter

the the the the the

element: element: element: element: value to

3 4 5 6 be searched: 3

OUTPUT: The position of the element:1 Q2. Program to sort the element in ascending order using bubble sort DATE: 3oct,2010 FILE NAME: arr #include<iostream.h> #include<conio.h> void main() { clrscr(); int list[]={2,13,6,9,8,1,10}; int i=0; int n,j,temp; n=sizeof(list)/2; cout<<"\nthe given list is"; for(i=0;i<n;i++) { cout<<list[i]<<""; } i=0; while(i<n-1) { i++; for(j=0;j<n-1;j++) { if(list[j]<list[j+1]) { temp=list[j]; list[j]=list[j+1]; list[j+1]=temp; } } } cout<<"\nthe sorted list is"; for(i=0;i<n;i++) { cout<<list[i]<<""; getch();

} } INPUT: The given list is 2 13 6 9 8 1 10 OUTPUT: Three sorted list is 13 10 9 8 6 2 1 Q3. Program to delete an element from an array. DATE: 3oct,2010 FILE NAME: arr #include<iostream.h> #include<conio.h> void main() { clrscr(); int reg[50]; int i,loc,x,n,back; cout<<"enter the size of the list"; cin>>n; for(i=0;i<n;i++) { cout<<"\nenter the data element"; cin>>reg[i]; } cout<<"\nenter the location from zero location"; cin>>loc; x=reg[loc]; back=loc; while(back<n) { reg[back]=reg[back+1]; back++; } n--; cout<<"\nthe deleted data item="<<x; cout<<"\nthe new list after deletion"; for(i=0;i<n;i++) { cout<<"\ndata element="<<reg[i]; } } INPUT: Enter the size of the list 4

Enter the data element 2 Enter the data element 3 Enter the data element 4 Enter the data element 5 Enter the location from zero location 2 OUTPUT-: The deleted data item=4 The new list after deletion Data element=2 Data element=3 Data element=5 Q4. Program to sort the element of an array in ascending order using insertion sort. DATE: 4oct,2010 FILE NAME: arr #include<fstream.h> #include<conio.h> void main() { clrscr(); int list[30]; int i,j,n,temp; cout<<"enter the size of the array"; cin>>n; for(i=0;i<n;i++) { cout<<"enter the element"; cin>>list[i]; } for(i=1;i<n;i++) { temp=list[i]; j=i-1; while((temp<list[j])&&(j>=0)) { list[j+1]=list[j]; j=j-1; } list[j+1]=temp; } cout<<"\n the sorted list is:"; for(i=0;i<n;i++) { cout<<"\t"<<list[i]; }

} INPUT: Enter the size of array 4 Enter the element 5 Enter the element 1 Enter the element 9 Enter the element 3 OUTPUT: The sorted list is 1 3 5 9

Q5. Program to insert an element in to an array in kth position. DATE: 6oct,2010 FILE NAME: arr #include<iostream.h> #include<conio.h> void main() { int reg[50]; int i,n,x,loc,back; cout<<"\nEnter the size of the list:"; cin>>n; for(i=0;i<n;i++) { cout<<"\nEnter the list of Array:"; cin>>reg[i]; } cout<<"\nEnter the value to be inserted:"; cin>>x; cout<<"Enter the location from zero location:"; cin>>loc; back=n; while(back>loc) { reg[back]=reg[back-1]; back--; } reg[back]=x; cout<<"\nThe final list after insertion...."; for(i=0;i<=n;i++) { cout<<"\n Element"<<i<<"="<<reg[i]; } }

INPUT: Enter the size of array 5 Enter the list of array 3 Enter the list of array 5 Enter the list of array 8 Enter the list of array 2 Enter the list of array 9 Enter the value to be inserted: 6 Enter the location from zero location: 3 OUTPUT: The final list after insertion... Element 0=3 Element 1=5 Element 2=8 Element 3=6 Element 4=2 Element 5=9

Q6. Program to search from gigen srting by linear search. DATE: 7oct,2010 FILE NAME: arr #include<iostream.h> #include<conio.h> int lsearch(int[],int,int); void main() { int ar[50],item,n,index; cout<<"\nenter desired array size"; cin>>n; cout<<"\nenter array element"; for(int i=0;i<n;i++) { cin>>ar[i]; cout<<"\nenter element to bre searched for"; cin>>item; index=lsearch(ar,n,item); if(index==-1) cout<<"\nsorry!!given element could noy be found\n"; else cout<<"\nelement found at index:"<<index<<",position:"<<index+1<<endl; } int lsearch(int ar[],int size,int item)

{ for(int i=0;i<size;i++) { if(ar[i]==item) return i; } return-1; } } Q7.Suppose A,B,C are arrayof integer of size M,N and M+N respectively. The numbers in array A and B appear in ascending order. Give the necessary declaration for array A, B and C in c++. Write a program in c++ to produce third array C by merging array A and B in ascending order. DATE: 8oct,2010 FILE NAME: arr #include<iostream.h> #include<conio.h> void main() { clrscr(); int A[20],B[20],C[50]; int i,n,m; int a,b,c; cout<<"\n enter the size of the arrays"; cin>>n>>m; for(i=0;i<n;i++) {cout<<"\n enter the list1:"; cin>>A[i]; } for(i=0;i<m;i++) { cout<<"\n enter the list2:"; cin>>B[i]; } a=b=c=0; while(a<n&&b<m) { if(A[a]<B[b]) C[c++]=A[a++]; else C[c++]=B[b++]; } while(a<n) C[c++]=A[a++]; while(b<m) C[c++]=B[b++]; cout<<"the final list is ..........";

for(i=0;i<m+n;i++) {cout<<"\n the data element is.."<<C[i]; } getch(); } INPUT: Enter the size of the array 4 3 Enter the list1: 4 Enter the list1: 5 Enter the list1: 8 Enter the list1: 7 Enter the list2: 1 Enter the list2: 3 Enter the list1: 9 OUTPUT: The final list is.... The data element is..1 The data element is..3 The data element is..4 The data element is..5 The data element is..7 The data element is..8 The data element is..9

Q8. Program to sort the elements of an array in descending order using selection sort. DATE: 8oct,2010 FILE NAME: arr #include<iostream.h> #include<conio.h> void main() { clrscr(); int list[30]; int i,n,pos,temp,small,j; cout<<"\nenter the size of array"; cin>>n; for(i=0;i<n;i++) { cout<<"\nenter the element of array"; cin>>list[i]; }

for(i=0;i<n-1;i++) { small=list[i]; pos=i; for(j=i+1;j<n;j++) { if(small>list[j]) { small=list[j]; pos=j; } } temp=list[i]; list[i]=list[pos]; list[pos]=temp; } cout<<"\nthe sorted list is as follows"; for(i=0;i<n;i++) { cout<<"\ndata element"<<list[i]; } } INPUT: Enter the size of the array 4 Enter the element of array 6 Enter the element of array 9 Enter the element of array 3 Enter the element of array 5 OUTPUT: The sorted list is as follows: Data element 3 Data element 5 Data element 6 Data element7

CLASSES AND OBJECT


Q9.Program of the employee class for implicit call constructor, which passes five values into the employee class constructor. DATE: 1april,2010 FILE NAME: class #include<iostream.h> #include<conio.h>

#include<string.h> class employee { private: char emp_name[25];s char address[25]; char city[15]; char state[2]; double salary; public: employee(char e_name[25],char add[25],char cty[15],double sal); void print_data(void); void cal_da(void); void cal_hra(void); void cal_gross(void); }; employee::employee(char e_name[25],char add[25],char cty[15],char st[2],double sal) { strcpy(emp_name,e_name); strcpy(address,add); strcpy(city,cty); strcpy(state,st); salary=sal; } void employee::print_data(void) { cout<<"\nEmployee name :"<<emp_name; cout<<"\nAddress :"<<address; cout<<"\nCity :"<<city; cout<<"\nState :"<<state; cout<<"\nBasic salary :"<<salary; } void employee::cal_da(void) { cout<<"\nDearness allowance is :"<<1.20*salary; } void employee::cal_hra(void) { cout<<"\nHouse rent allowance is :"<<0.15*salary; } void employee::cal_gross(void) { double gross; gross=salary+(1.20*salary)+0.15*salary; cout<<"\nGross salary is :"<<gross;

} void main() { employee emp("Mr.Master","Central Market","Delhi","DH",3000); emp.print_data(); emp.cal_da(); emp.cal_hra(); emp.cal_gross(); } OUTPUT: Employee name: Mr.Master Address: Central Market City: Delhi State: DH Basic salary: 3000 Dearness allowance is: 3600 House rent allowance is: 450 Gross salary is: 7050

Q10. Program that uses for multilevel inheritance to employee and customer classes with the address part and the calculation part. DATE: 2april,2010 FILE NAME: class #include<iostream.h> #include<conio.h> class employee { char emp_name[25]; char eaddress[25]; char ecity[15]; char estate[2]; double esalary; public: void emp_input(void); void emp_print(void); }; class customer:public employee {

char cust_name[25]; char address[25]; char city[15]; char state[2]; double balance; public: void cust_input(void); void cust_print(void); }; class emp_cust:private customer { public: void get_data(); void show_data(); }; void emp_cust::get_data(void) { emp_input(); cust_input(); } void emp_cust::show_data() { emp_print(); cust_print(); } void employee::emp_print() { cout<<"\nEmployee name "<<emp_name; cout<<"\nAddress "<<eaddress; cout<<"\nCity "<<ecity; cout<<"\nState "<<estate; cout<<"\nSalary "<<esalary; } void customer::cust_print(void) { cout<<"\n\nCustomer name "<<cust_name; cout<<"\nAddress "<<address; cout<<"\nCity "<<city; cout<<"\nState "<<state; cout<<"\nBalance "<<balance; } void employee::emp_input(void) { cout<<"\nEnter the employee name "; cin>>emp_name; cout<<"\nEnter the employee address "; cin>>eaddress;

cout<<"\nEnter the city "; cin>>ecity; cout<<"\nEnter the state "; cin>>estate; cout<<"\nEnter the salary "; cin>>esalary; } void customer::cust_input(void) { cout<<"\n\nEnter the customer name "; cin>>cust_name; cout<<"\nEnter the customer address "; cin>>address; cout<<"\nEnter the city "; cin>>city; cout<<"\nEnter the state "; cin>>state; cout<<"\nEnter the balance "; cin>>balance; } void main() { clrscr(); emp_cust empcust; empcust.get_data(); empcust.show_data(); } OUTPUT: Enter the employee name: SAINA Enter the employee address: PWD Enter the city: JODHPUR Enter the state: RAJASTHAN Enter the salary: 45678 Enter the customer name: GITA Enter the customer address: SHIMINPUR Enter the city: KOTA Enter the state: RAJASTHAN Enter the balance: 4543446 Employee name: SAINA Address: PWD City: JODHPUR State: RAJASTHAN Salary: 45678 Customer name: GITA Address: SHIMINPUR City: KOTA

State: RAJASTHAN Balance: 4543446 Q11.Program demonstrates a sample example on class inheritance with a factorial. DATE: 4april,2010 FILE NAME: class #include<iostream.h> #include<conio.h> class base { private: int counter; public: base() { counter=0; } void newset(int n) { counter=n; } void factorial(void); }; class derived:public base { public: derived(): base() { }; void changecounter(int n) { newset(n); factorial(); } }; void base::factorial(void) { int i; long double fact=1.0; for(i=1;i<=counter;i++) fact=fact*i; cout<<"The factorial value is "<<fact; } void main()

{ clrscr(); int num; derived tderived; cout<<"Enter the value for factorial "; cin>>num; tderived.changecounter(num); } OUTPUT: Enter the value for factorial 3 The factorial is 3 Q12. Program demonstrates a sample example on class inheritance with a factorial. DATE: 5april,2010 FILE NAME: class #include<iostream.h> #include<conio.h> class base { private: int counter; public: base() { counter=0; } void newset(int n) { counter=n; } void factorial(void); }; class derived:public base { public: derived(): base() { }; void changecounter(int n) { newset(n); factorial(); }

}; void base::factorial(void) { int i; long double fact=1.0; for(i=1;i<=counter;i++) fact=fact*i; cout<<"The factorial value is :"<<fact; } void main() { clrscr(); int num; derived tderived; cout<<"Enter the value for factorial :"; cin>>num; tderived.changecounter(num); } OUTPUT: Enter the value for factorial: 3 The factorial value is: 6 Q14. A program to find the sum of odd and even numbers. use constructors to initialize data member and destructor to release memory. DATE:6april,2010 FILE NAME:clas #include<iostream.h> #include<conio.h> class sum { int sumodd; int sumeven; int i; int n; public: sum() { cout<<"\nEnter the value for n"; cin>>n; sumodd=0; sumeven=0; i=1;

} void addition(); ~sum() { } }; void sum::addition() { for(;i<=n;i++) { if(i%2==0) sumeven=sumeven+i; else sumodd=sumodd+i; } cout<<"\nSum of the even numbers is"<<sumeven; cout<<"\nSum of the odd numbers is"<<sumodd; } void main() { clrscr(); sum x; x.addition(); } OUTPUT Enter the value for n 4 Sum of the even numbers is 6 Sum of the odd numbers is 4

Q14. Write a program using class to accept the details of a bank a\c holder to determine the balance and other details DATE:7april,2010 FILE NAME:class #include<iostream.h> #include<conio.h> class bank_acc { int account;

float balance; public: float dep,t; void setvalue(); void deposit(); void withdrawl(); }; void bank_acc::setvalue() {cout<<"Enter the current account number:"; cin>>account; cout<<"\nEnter the current balance:"; cin>>balance; } void bank_acc::deposit() { cout<<"\n\n\nEnter the money deposited"; cin>>dep; balance=balance+dep; cout<<"The account number "<<account; cout<<" has balance : "<<balance; } void bank_acc::withdrawl() {cout<<"\n\nThe money you withdrawn is:"; cin>>t; balance=balance-t; cout<<"\n\nYour account number: "<<account; cout<<"\nThe balance is: "<<balance; } void main() { clrscr(); bank_acc a; a.setvalue(); a.deposit(); a.withdrawl(); getch(); } INPUT-: Enter the current account number:17 Enter the current balance:100000 Enter the money deposited:1000 OUTPUT-: The account number 17 has balance : 101000 The money you withdrawn is:100 Your account number: 17 The balance is: 100900

Q15.Programm to calculate the volume of a rectangular solid length, width and height is given in meters,by using the class named as rect_solid ,which has the following members: PRIVATE DATA MEMBERS: 1.length 2.width 3.height PUBLIC DATA MEMBERS: 1.get_values to obtain values of the lenght ,width and height. 2.calculate to calculate volume by the formula. 3.show_data to display the value of length,width, heigth and volume. DATE:8april,2010 FILE NAME:class #include<iostream.h> #include<conio.h> class rect_solid { private: float len,wid,height; public: void get_values(); float calculate(); void show_data(); }; void rect_solid::get_values() { cout<<"\n enter the length of rectangular solid is : "; cin>>len; cout<<"\n enter the width of rectangular solid is : "; cin>>wid; cout<<"\n enter the height of rectangular solid is : "; cin>>height; } float rect_solid::calculate() { float vol;

vol=len*wid*height; return(vol); } void rect_solid::show_data() { float x; x=calculate(); cout<<"\n the length of rectangular solid is : "; cout<<len<<"\n"; cout<<"\n the width of rectangular solid is : "; cout<<wid<<"\n"; cout<<"\n the height of rectangular solid is : "; cout<<height<<"\n"; cout<<"\n the volume of rectangular solid is : "; cout<<x<<"\n"; } void main() { clrscr(); rect_solid y; y.get_values(); y.show_data(); getch(); } INPUT-: enter the length of rectangular solid is :2 enter the width of rectangular solid is : 3 enter the height of rectangular solid is :4 OUTPUT-: the length of rectangular solid is :2 the width of rectangular solid is :3 the height of rectangular solid is :4 the volume of rectangular solid is :24 Q16. Write an object oriented program in c++ to grade a marksheet of university examination system with the following items read from the keyboard:a)student name b)roll number c)subject name d)subject code e)scored marks f)total marks Design the base consisting of the data members such as name of the student,roll number and subject name.The derived

class contains the data member namely subject code and scored marks The program should be able to display all the details of the student. DATE:9april,2010 FILE NAME:class #include<iostream.h> #include<conio.h> #include<stdio.h> class b_university { protected: char name[20]; int rollno; char sub_name[5][20]; }; class d_university:private b_university { int sub_code[5]; int total; int marks[5]; public: void initdata(); void display(); }; void d_university :: initdata() { cout<<"\nEnter the name of the student: ";gets(name); cout<<"\nEnter the rollnumber of the student: ";cin>>rollno; for(int i=0;i<1;++i) { cout<<"\nEnter the name of the subject: ";gets(sub_name[i]); cout<<"\nEnter the subject code: ";cin>>sub_code[i]; cout<<"\nEnter the marks scored by the student: ";cin>>marks[i]; } } void d_university :: display() { cout<<"\n*****************OXFORD UNIVERSITY MARK SHEET**************"; cout<<"\nPersonal record of "<<name<<" :-"; cout<<"\n\nName->"<<name; cout<<"\nRoll number->"<<rollno; cout<<"\n\n\nProgress record of "<<name<<" :-"; for(int i=0;i<1;i++) {

cout<<"\n\nName of the subject----->"<<sub_name[i]; cout<<"\nSubject code------>"<<sub_code[i]; cout<<"\nMarks scored by the student----->"<<marks[i]; } } void main() { clrscr(); d_university s; clrscr(); s.initdata(); clrscr(); s.display(); getch(); } INPUT-: *****************OXFORD UNIVERSITY MARK SHEET************** Personal record of anha:Name:anha Roll number:-1 Progress record of anha Name of the subject:-mathematics Subject code:-02 Marks scored by the student:100 Q16. Assuming the class EMPLOYEE given below,write functions in C++ to perform the following: 1. Write the objects of EMPLOYEE to a binary file. 2. Reads the objects of EMPLOYEE from binary file and display them on screen. DATE:10april,2010 FILE NAME:class #include<fstream.h> #include<conio.h> class employee { int eno; char ename[10];public: void getit(); void showit(); }; void employee::getit() { cout<<"ENTER EMPLOYEE NO.:"; cin>>eno;

cout<<"ENTER EMPLOYEE NAME:"; cin>>ename; } void employee::showit() { cout<<"\n\n\t\tWORKER NO.:"<<eno<<endl; cout<<"\t\tWORKER NAME:"<<ename;} void main() { clrscr(); employee obj; fstream infile; char fname; infile.open("fname",ios::in|ios::out|ios::binary); obj.getit(); infile.write((char*)&obj,sizeof(obj)); infile.close(); infile.open("fname",ios::in); cout<<"\nREADING FROM FILE: "; infile.read((char*)&obj,sizeof(obj)); cout<<endl; obj.showit(); infile.close(); getch(); } OUTPUT-: ENTER EMPLOYEE NO. : 120 ENTER EMPLOYEE NAME : AZAD READING FROM FILE: WORKER NO. : 120 WORKER NAME : AZAD

DATA FILE HANDLING


Q17.Program to write and read a structure using write() and read()function using a binary file. DATE:1July,2010 FILE NAME:dfh #include<fstream.h>

#include<string.h> #include<conio.h> struct customer{ char name[51]; float balance; }; void main() { clrscr(); customer savac; strcpy(savac.name,"shrestha kalla "); savac.balance=9876543.21; ofstream fout; fout.open("saving",ios::out|ios::binary); if(!fout) { cout<<"file cannot be opened\n"; } fout.write((char*)&savac,sizeof(savac)); fout.close(); ifstream fin; fin.open("saving",ios::in|ios::binary); fin.read((char*)&savac,sizeof(savac)); cout<<savac.name; cout<<"has the balance amount of rs."<<savac.balance<<"\n"; fin.close(); } OUTPUT-: Shrestha kalla has the balance amount of rs.9876543 Q18.Program for reading and writing class objects. DATE:2July,2010 FILE NAME:dfh #include<fstream.h> #include<conio.h> class student{ char name[40]; char grade; float marks; public: void getdata(); void display(); }; void student::getdata() {char ch; cin.get(ch); cout<<"\nenter the name\n";

cin.getline(name,40); cout<<"\nenter the grade\n"; cin>>grade; cout<<"\nenter the marks\n"; cin>>marks; cout<<"\n"; } void student::display() {cout<<"name:"<<name<<"\n"; cout<<"grade:"<<grade<<"\n"; cout<<"marks:"<<marks<<"\n"; } void main() { clrscr(); student arts[3]; fstream fin; fin.open("stu.dat",ios::in); if(!fin) { cout<<"cannot open file!!\n"; } cout<<"\nenter the detail of 3 student\n"; for(int i=0;i<3;i++) { arts[i].getdata(); fin.write((char*)&arts[i],sizeof (arts[i])); } fin.seekg(0); cout<<"the content of stu.dat are shown below.\n"; for(i=0;i<3;i++) { fin.read((char*)&arts[i],sizeof (arts[i])); arts[i].display(); } fin.close(); getch(); } INPUT: Enter the Enter the Enter the Enter the Enter the Enter the Enter the Enter the Enter the detail of 3 student name shini grade A marks 76 name Farah grade B marks 87 name gita grade C

Enter the marks 98 OUTPUT: The content of syu.dat are shown below-: Name: shini Grade: A Marks: 76 Name: Farah Grade: B Marks: 87 Name: gita Grade: C Marks: 98

Q19.Program to search in a file record maintained through classes DATE: 12july,2010 FILE NAME: dfh #include<fstream.h> #include<conio.h> #include<stdio.h> struct stu{ int rollno; char name[25]; char clas[4]; float marks; char grade; }s1; void main() { clrscr(); //int rollno; //float marks; //char grade; cout<<"enter the rollno\n"; cin>>s1.rollno; cout<<"\nenter name"; gets(s1.name); cout<<"\nclas"; gets(s1.clas); cout<<"\nmarks"; cin>>s1.marks; if(s1.marks>=75) s1.grade='a';

else if(s1.marks>=60) s1.grade='b'; else if(s1.marks>=50) s1.grade='c'; else if(s1.marks>=40) s1.grade='d'; else s1.grade='f'; int rn; char found='n'; ofstream fo("stu.dat",ios::out|ios::binary); fo.write((char*)&s1,sizeof(s1)); ifstream fi("stu.dat",ios::in|ios::binary); cout<<"enter the rollno to be searched for:"; cin>>rn; while(!fi.eof()) { fi.read((char*)&s1,sizeof(s1)); if(s1.rollno==rn) { cout<<s1.name<<",rollno"<<rn<<"has"<<s1.marks<<"% marks and" <<s1.grade<<"grade"<<endl; found='y'; break; } } if(found=='n') cout<<"rollno not found in file!!"<<endl; fi.close(); } INPUT: ENTER THE ROLL NO. TO SEARCH FOR: 108 OUTPUT: VENKAT, ROLL NO 108 HAS 87% MARKS AND A GRADE

Q20. Program to create a single file ant then display its content. DATE: 13july,2010 FILE NAME: dfh #include<fstream.h> #include<conio.h> void main() { clrscr();

ofstream fout("student"); char name[30],ch; float marks=0.0; for(int i=0;i<5;i++) { cout<<"student:"<<(i+1)<<"\tname"; cin.get(name,30); cout<<"\t\tmarks:"; cin>>marks; cin.get(ch); fout<<name<<'\n'<<marks<<'\n'; } fout.close(); ifstream fin("student"); fin.seekg(0); cout<<"\n"; for(i=0;i<5;i++) { fin.get(name,30); fin.get(ch); fin>>marks; fin.get(ch); cout<<"student name:"<<name; cout<<"\tmarks:"<<marks<<"\n"; } fin.close(); getch(); } INPUT: Name: sumita Marks: 34 name: raveena Marks:78 name: gunjan marks:87 OUTPUT: Student name: sumita marks:34 student name: raveena marks:78 student name: gunjan marks:87 Q21.A file named marks.dat alraedy stores some students detail like rollno and marks. Write a program that reads more such detail &append them to this file.Make sure that previous content of file are not lost. DATE: 14july,2010 FILE NAME: dfh

#include<fstream.h> #include<conio.h> void main() { clrscr(); ofstream fout; fout.open("marks.dat",ios::app); char ans='y'; int rollno; float marks; while(ans=='y'||ans=='Y') { cout<<"\nenter rollno.:"; cin>>rollno; cout<<"\nenter marks:"; cin>>marks; fout<<rollno<<'\n'<<marks<<'\n'; cout<<"\nwant to enter more record?(y/n)"; cin>>ans; } cout.close(); getch(); } OUTPUT: Enter roll number: 34 Enter marks: 28 Do you want to enter more records?(y/n)=n Q22. Program to use multiple file simultaneously. DATE: 14july,2010 FILE NAME: dfh #include<fstream.h> #include<conio.h> void main() { clrscr(); ifstream fin1,fin2; fin1.open("stunames"); fin2.open("stumarks"); char line[80]; cout<<"\nthe content of stunames and stumarks are given below\n"; fin1.getline(line,80);

cout<<line<<"\n"; fin2.getline(line,80); cout<<line<<"\n"; fin1.getline(line,80); cout<<line<<"\n"; fin2.getline(line,80); cout<<line<<"\n"; fin1.getline(line,80); cout<<line<<"\n"; fin2.getline(line,80); cout<<line<<"\n"; fin1.close(); fin2.close(); } OUTPUT: Devyani: 78.92 Monica Patrick: 72.17 Q23. Program to display content of a file using get() function. DATE: 16july,2010 FILE NAME: dfh #include<fstream.h> #include<conio.h> void main() { clrscr(); char ch; ifstream fin; fin.open("marks.dat",ios::in); if(!fin) { cout<<"\ncannot open file!!!!!\n"; } while(fin) {fin.get(ch); cout<<ch; } fin.close(); getch(); } OUTPUT: Cannot open file!!!

Q24. Program to create a file using put(). DATE: 17july,2010 FILE NAME: dfh #include<fstream.h> #include<conio.h> void main() { clrscr(); ofstream fout; fout.open("aschars",ios::app); if(!fout) { cout<<"\nthe file cannot be created\n"; } char ch; int line=0; for(int i=33;i<128;i++) { fout.put((char)i); } fout.close(); ifstream fin; fin.open("ankit",ios::in); fin.seekg(0); for(i=33;i<128;i++) {fin.get(ch); cout<<" "<<i<<"="; cout.put((char)i); if(!(i%8)) {cout<<endl; line++; } if(line>22) {getch(); line=0; } } } OUTPUT: 33=! 34=" 35=# 36=$ 37=/ 38=&............ ......122=z 123= {126=~

DATA STRUCTURE
Q25.Program to perform all the basic operatoin on stack. The stack contain data of integer type. DATE: 15oct,2010 FILE NAME: dst #include<iostream.h> #include<conio.h> #include<stdio.h> #include<stdlib.h> #include<ctype.h> #include<process.h> struct node { int data; node *link; }; node *push(node *top,int val); node *pop(node *top,int &val); void show_stack(node *top); void main() { clrscr(); node *top; int choice,opt,val; top=NULL; do { cout<<"\n\nmain menu"; cout<<"\n1.Addition of stack\n"; cout<<"\n2.Deletion of stack\n"; cout<<"\n3.Traverse of stack\n"; cout<<"\n4.Exit\n"; cout<<"\nenter the choice from above\n"; cin>>choice; switch(choice) { case 1: do { cout<<"\nenter the value to be added in the stack\n"; cin>>val; top=push(top,val); cout<<"\ndo you want to enter any more element<y/n>?"; cin>>opt; }

while (toupper(opt)=='Y'); break; case 2:opt='Y'; do { top=pop(top,val); if(val!=-1) cout<<"\nthe value deleted from the stack is--"<<val; cout<<"\ndo you want to delete more element<y/n>?"; cin>>opt; } while (toupper(opt)=='y'); break; case 3: show_stack(top); break; case 4: exit(0); } } while(choice!=4); } node *push(node *top,int val) { node *temp; temp=new node; temp->data=val; temp->link=NULL; if(top==NULL) top=temp; else {temp->link=top; top=temp; } return(top); } node *pop(node *top,int &val) { node *temp; if(top==NULL) { cout<<"\nempty stack"; val=-1; } else { temp=top;

top=top->link; val=temp->data; temp->link=NULL; delete temp; } return (top); } void show_stack(node *top) { node *temp; temp=top; clrscr(); cout<<"\nthe values are\n"; while(temp!=NULL) {cout<<"\n"<<temp->data; temp=temp->link; } getch(); } INPUT: Main menu 1. Addition of stack. 2. Deletion of stack. 3. Traverse of stack. 4. Exit. Enter the choice from above 1 OUTPUT: Enter the value to be added in stack 23 Do you want to enter any more element(y/n)? n

Q25. Program to create a linked and search a perticular data value of integer. DATE: 18oct,2010 FILE NAME: dst #include<iostream.h> #include<conio.h> struct node { int data; node *link; }; void main() { clrscr();

node *f,*l,*t; int i,n,flag,item; cout<<"Enter the size="; cin>>n; f=new node; cout<<"Enter the data="; cin>>f->data; f->link=NULL; t=f; for(i=1;i<n;i++) { l=new node; cout<<"\nEnter the value"<<i+1<<":"; cin>>l->data; l->link=NULL; t->link=l; t=l; } t=f; cout<<"\nThe values are:"; while(t!=NULL) { cout<<"\n"<<t->data; t=t->link; } cout<<"\nEnter the value to be searched:"; cin>>item; t=f; while(t!=NULL) (if(t->data==item) {flag=1; break; } t=t->link; } if(flag==1) cout<<"\nSuccessful search"; else cout<<"\nUnccessful search"; getch(); } INPUT: ENTER THE SIZE=8 ENTER VALUE 1=4 ENTER VALUE 2=1 ENTER VALUE 3=2 ENTER VALUE 4=8

ENTER VALUE 5=3 ENTER VALUE 6=7 ENTER VALUE 7=9 ENTER VALUE 8=0 THE VALUES ARE: 4 1 2 8 3 7 9 0 ENTER THE VALUE TO BE SEARCHED=3 SUCCESSFUL SEARCH

Q26. Program to create and traverse the linked list. The linked list contains data of type integer. DATE: 19oct,2010 FILE NAME: dst #include<iostream.h> #include<conio.h> struct node { int data; node *link; }; void main() { clrscr(); int i,n; node *first,*last,*temp; cout<<"Enter how many nodes you want="; cin>>n; first=new node; cout<<"\nEnter the data element="; cin>>first->data; first->link=NULL; temp=first; for(i=1;i<n;i++) { last=new node; cout<<"Enter the data element"<<i+1<<":"; cin>>last->data; last->link=NULL; temp->link=last; temp=last; } temp=first; cout<<"\n\nThe values are...."; while(temp!=NULL) { cout<<"\n"<<temp->data;

temp=temp->link; } getch(); } INPUT: Enter how many nodes do you want=2 Enter data element 1=23 Enter data element 2=26 OUTPUT-: The values are..... 23 Q27.Pogramto create a linked and search a particular data value of integer data type. Date: 20oct,2010 File Name: dst #include<iostream.h> #include<conio.h> #include<stdio.h> #include<stdlib.h> struct node { int data; node *link; }; void main() {clrscr(); node *first,*temp,*last; int n,i,item,flag; cout<<"\n\nEnter how many nodes to create in the linked list->"; cin>>n; first=new node; cout<<"\n\tEnter the data value of node1->"; cin>>first->data; first->link=NULL; temp=first; for(i=1;i<n;i++) { last=new node; cout<<"\n\tEnter the data value of node"<<i+1<<"-->"; cin>>last->data; last->link=NULL; temp->link=last; temp=last; } temp=first; clrscr();

cout<<"The linked list value are\n"; while(temp!=NULL) { cout<<"\n"<<temp->data; temp=temp->link; } flag=0; cout<<"\n\n\tEnter the data value to be searched-->"; cin>>item; temp=first; while(temp!=NULL) {if(temp->data==item) {flag=1; break; } temp=temp->link; } if(flag==1) cout<<"\n\n\tSearch is sucessful"; else cout<<"\n\n\tSearch is unsucessful"; getch(); } INPUT: Enter how many nodes to create in the linked list->4 Enter the Data value of node1->25 Enter the Data value of node2->20 Enter the Data value of node3->35 Enter the Data value of node4->10 OUTPUT: The linked list values are: 25 20 35 10 Enter the data value to be searched25 Search is successful Q28Program to create a linked list and insert elements at first. Date:21oct,2010 File Name: dst #include<iostream.h> #include<stdlib.h>

#include<conio.h> #include<stdio.h> struct node { int data; node *link; }; node *addfirst(node *first,int value); void main() { node *first; node *temp; node *last; int n; int i; int value; clrscr(); cout<<"\nEnter how many nodes in the linked list->"; cin>>n; first=new node; cout<<"\nEnter thedata value of the node->"; cin>>first->data; first->link=NULL; temp=first; for(i=1;i<n;i++) { last=new node; cout<<"\nEnter the data value of the node->"; cin>>last->data; last->link=NULL; temp->link=last; temp=last; } cout<<"\nFor inserting at first "; cout<<"\nEnter data value to be inserted "; cin>>value; first=addfirst(first,value); } node *addfirst(node *first,int value) { node *temp; temp=new node; temp->data=value; temp->link=first; first=temp; return(first);

} INPUT: Enter how many nodes in the linked list:3 Enter thedata value of the node:4 Enter the data value of the node-:10 Enter the data value of the node5 OUTPUT: For inserting at first Enter data value to be inserted 5 The linked list values are: 5 4 10 5 Q29Programto create a linked list and insert elements in between. Date:22oct,2010 File Name: dst #include<iostream.h> #include<stdlib.h> #include<conio.h> #include<stdio.h> struct node { int data; node *link; }; node *addbetween(node *first,int value,int val); void main() { node *first; node *temp; node *last; int val; int n; int i; int value; clrscr(); cout<<"\nEnter how many nodes in the linked list->"; cin>>n; first=new node; cout<<"\nEnter the data value of the node->"; cin>>first->data; first->link=NULL;

temp=first; for(i=1;i<n;i++) { last=new node; cout<<"\nEnter the data value of the node->"; cin>>last->data; last->link=NULL; temp->link=last; temp=last; } cout<<"\nFor inserting in between: "; cout<<"\nEnter data value to be inserted: "; cin>>value; cout<<"\nEnter the value of node after which insertion is made: "; cin>>val; first=addbetween(first,value,val); } node *addbetween(node *first,int value,int val) { node *temp; node *temp1; temp=new node; temp->data=value; temp1=first; while(temp1!=NULL) { if(temp1->data==val) { temp->link=temp1->link; temp1->link=temp; } temp1=temp1->link; } return(first); } INPUT: Enter how many nodes in the linked list->3 Enter the data value of the node->34 Enter the data value of the node->45 Enter the data value of the node->10 Enter the data value of the node->8 OUTPUT: For inserting in between: Enter data value to be inserted: 5 Enter the value of node after which insertion is made: 2

The linked list values are: 34 45 5 8

Q30WAP to write the word in descending order ? DATE:2aug,2010 FILE NAME:point #include <iostream.h> #include <conio.h> #include <ctype.h> #include <string.h> #include <stdio.h> void main() {char *s = "GOODLUCK"; for (int x =strlen(s) -1 ; x>=0; x--) { for ( int y=0; y<=x; y++) cout<<s[y]; cout<<endl; } } /**********output************* GOODLUCK GOODLUC GOODLU GOODL GOOD GOO GO G ***************/ Q31Program to convert the uppercase in lower case & lowercase in uppercase. DATE:4oct,2010 FILE NAME:point #include #include #include #include <iostream.h> <conio.h> <ctype.h> <string.h>

#include <stdio.h> void main() { clrscr(); char *s = "HUMAN"; int L = strlen(s); for (int c =0;c<L;c++) if (islower(s[c])) s[c] = toupper(s[c]); else if (c%2 ==0) s[c] = 'E'; else s[c] = tolower(s[c]); cout<<"New Message :"<<s<<"\n"; } /*************output************** new message:EuEaE

Q32. Program to find the length of the string . DATE: 5oct,2010 FILE NAME: point #include<iostream.h> #include<string.h> #include<conio.h> #include <stdio.h> //CLASS DECLARATION class strn { char *a; int i; public: void read(); //MEMBER FUNCTIONS void calculate(); }; //END OF CLASS void strn::read() { cout << "\n\t"; cout << "\n\tEnter your name "; gets(a); //TO READ THE STRING } void strn::calculate() {

i = 0; while (*(a+i) != '\0') i++; cout << "\n\tThe length of your name is : " << i;; } void main() { strn x; clrscr(); cout<< "\n\n\n\t "; x.read(); //CALLING MEMBER FUNCTIONS x.calculate(); getch(); } //E N D O F M A I N /*****************output**************** enter your name: naha the length in your name is 4 ***************/ Q33. Program to check weather the two strings are equal or not. DATE: 18oct,2010 FIL:E NAME: point #include<iostream.h> #include<string.h> #include<conio.h> #include <stdio.h> class strn { char *a, *b, flag; int i, j, k; public: void read(); void compare(); strn() { flag = 'y'; } }; //END OF CLASS void strn::read() { cout << "\n\t"; cout << "\n\tEnter the first string "; gets(a);

cout << "\n\tEnter the second string "; gets(b); } void strn::compare() { i = 0; j = 0; while (*(a+i) != '\0') i++; while(*(b+j) != '\0') j++; if (i != j) { cout << "\n\t Strings are not equal "; return; } i = 0; while ((*(a+i) != '\0') && (*(b+i) != '\0')) { if(*(a + i) != *( b + i)) { flag = 'n'; break; } i++; } if(flag == 'n') cout << "\n\tStrings are not equal "; else cout << "\n\tStrings are equal "; } void main() { strn x; clrscr(); cout << "\n\n\n\t "; x.read(); x.compare(); cout << "\n\n\t\t bye!"; getch(); } /**************output*********** enter the first string is ram enter the second string is tam strings are equal. **********/

Q34. Program to reverse the string using pointer. DATE: 20oct,2010 FILE NAME: point */ #include<iostream.h> #include<string.h> #include<conio.h> #include <stdio.h> class strn {char *str, flag; int i, j, l; public: void read(); void rev(); strn() { flag = 'y'; } }; void strn::read() { cout << "\n\tEnter the string "; gets(str); } void strn::rev() { l = strlen(str),j = l-1; char t; for(i=0;i<=j; i++, j--) { t = str[i]; str[i] = str[j]; str[j] = t; } cout << " The reversed string is " << str; } void main() { strn x; x.read(); x.rev(); } /********************output*************

enter the string : radar the reversed string is radar Q35. Program to check whether the string is palindrome or not. DATE:6oct,2010 FILE NAME:point #include<iostream.h> #include<string.h> #include<conio.h> class strn { char *a, flag; int i, j, k; public: void read(); void ch_pal(); strn() { flag = 'y'; } }; void strn::read() { cout << "\n\t"; cout << "\n\tEnter the string "; cin >> a; } void strn::ch_pal() { cout << "\n\tThe entered string "; for(i=0; *(a+i)!='\0'; i++) cout << *(a+i); for(j=0, i-=1; i>j; j++, i--) { if(*(a + i) != *(a+j)) { flag = 'n'; break; } } if(flag == 'n') cout << " is not a palindrome "; else cout << " is a palindrome ";

} void main() { strn x; clrscr(); cout << "\n\n\n\t "; x.read(); x.ch_pal(); cout << "\n\n\t\t bye!"; getch(); } /*************output*********** enter the string: ridhi the entire string ridhi palindrome

COMPUTATIONAL PROGRAM
Q36. Write a program to display ASCII code of a character and vice versa. DATE:7oct,2010 FILE NAME:comp #include<iostream.h> #include<conio.h> void main() { clrscr(); char ch='A'; int num=ch; cout<<"The ASCII code for"<<ch<<"is"<<num<<"\n"; cout<<"Adding one to the charactrer code:\n"; ch=ch+1; num=ch; cout<<"The ASCIIcode for"<<ch<<"is"<<num<<"\n"; getch(); } OUTPUT: The ASCIII code for A is 66 Adding 1 to the character code: The ASCII Code for B is 66 */ Q37Write a program (using a function) to accept a number and print its cube. Date: 12/02/2010 File Name: COMPUTATIONAL

#include<iostream.h> #include<conio.h> float cube(float); int main() { clrscr(); float num; cout<<"Enter a number"; cin>>num; cout<<"\n"<<"The cube of"<<num<<"is"<<cube(num)<<"\n"; return 0; } float cube(float a) { return a*a*a; } INPUT: Enter a number 19 OUTPUT: The cube of is 729 Q39. Write a C++ program to compute the area of a square. Make assumptions on your own. DATE:8oct,2010 FILE NAME:comp #include<iostream.h> #include<conio.h> void main() { clrscr(); float side,area; cout<<"Enter side of the square:"; cin>>side; cout<<"\n The Area of the square is:" <<side*side<<"sq-units"<<endl; getch(); } INPUT: Enter side of square: 5 OUTPUT; The area of square is: 25 sq-units Q40Write a C++ program to convert a given number of days into years, weeks and days. DATE:7oct,2010 FILE NAME:comp

#include<iostream.h> #include<conio.h> void main() { clrscr(); int totdays,years,weeks,days,num1; cout<<"Enter total no. of days:"; cin>>totdays; years=totdays/365; num1=totdays%365; weeks=num1/7; days=num1%7; cout<<"\n"; cout<<"Years=\n"<<years<<"," <<"Weeks=\n"<<weeks<<"," <<"Days=\n"<<days<<"\n"; getch(); } INPUT: Enter total no. of days: 100 OUTPUT: Years=0 Weeks=14 Days=2 Q41Write a C++ program that accepts a character between a to j and prints next 4 characters. DATE:10oct,2010 FILE NAME:comp #include<iostream.h> #include<conio.h> void main() { clrscr (); char ch; cout<<"Enter a character between a to j"; cin>>ch; int num=ch; cout<<"\n Next four character"; cout<<"\n"<<(char)(ch+1)<<"\n"<<(char)(ch+2)<<"\n"<<(char) (ch+3)<<"\n"<<(char)(ch+4); getch(); } INPUT: Enter a character between a to j: H

OUTPUT: Next four character: I J K L Q42. Write a program to read a number n and print n^2,n^3,n^4 and n^5. DATE:11oct,2010 FILE NAME:comp #include<iostream.h> #include<conio.h> #include<math.h> void main() { clrscr(); int n,n2,n3,n4,n5; cout<<"Enter the number="; cin>>n; n2=pow(n,2); cout<<"\nThe square of the number="<<n2; n3=pow(n,3); cout<<"\nThe cube of the number="<<n3; n4=pow(n,4); cout<<"\nThe n raise to the power 4="<<n4; n5=pow(n,5); cout<<"\nThe n raise to the power 5="<<n5; getch(); } INPUT: Enter the number=3 OUTPUT: The square of number=9 The cube of number=27 The n raise to the power 4=9 The n raise to the power =81 Q43. Program using function overloading to calculate the area of rectangle, area of triangle using Herons formula and area of circle. DATE:12oct,2010 FILE NAME:comp #include <iostream.h> #include <conio.h>

#include <iomanip.h> #include <math.h> float area(float a, float b , float c); float area(float l, float w); float area(float r); void main() { char ch; float len, wid, n1, n2, n3, ar; float radius; int choice1; clrscr(); cout << "\n1. For area of triangle "; cout << "\n2. For area of rectangle "; cout << "\n3. For area of circle "; cout << "\nEnter choice : "; cin >> choice1; if (choice1 == 1) { cout << "\nEnter the three sides of triangle : "; cin >> n1 >> n2 >> n3; ar = area(n1, n2, n3); cout << "\nArea of triangle is : " << ar; } if (choice1 == 2) { cout << "\nEnter the length : "; cin >> len; cout << "\nEnter the width : "; cin >> wid; cout << "\nArea of rectangle is: " << area(len, wid);} if (choice1 == 3) { cout << "\nEnter the radius : "; cin >> radius; cout << "\nArea of circle : " << area(radius); } } float area(float a, float b , float c) { float s; float a1; s = (a + b + c) / 2; a1 = sqrt(s * (s-a) * (s-b) * (s-c)); return(a1); }

float area(float l, float w) { return(l*w); } float area( float radius) { return(3.14 * radius * radius); } INPUT: 1. for area of triangle 2. for area of rectangle 3. for area of circle Enter choice: 2 Enter the length: 5 Enter the width: 5 OUTPUT: Area of rectangle is: 25

CLASS AND OBJECTS


Q44Defineclass library for the following specifications:Private members of the library are Name array of characters of size 20. English_books,hindi_books,others and total_books integers Compute that calculates the total number of books and return the total. Total_books are the sum ofenglish_books,hindi_books,hindi_books and others. Public members of the library are Readdata() accepts the data and involves the compute functions Printdata() prints the data. Date:3April,2010 FILE NAME: class #include<iostream.h> #include<conio.h> #include<stdio.h> class library { private: int english_books,hindi_books,others,total_books; char name[20];

void compute(); public: void readdata(); void printdata(); }; void library::readdata() { cout<<"\n enter name:"; gets(name); cout<<"\n enter no. of english books"; cin>>english_books; cout<<"\n enter no. of hindi books"; cin>>hindi_books; cout<<"\n enter other books"; cin>>others; } void library::compute() { total_books=english_books+hindi_books+others; } void library::printdata() { cout<<"\n english books=<<english_books"; cout<<"\n hindi books="<<hindi_books; cout<<"\n other books="<<others; cout<<"\n name="; puts(name); cout<<"\n total no. of books="<<total_books; } void main() { clrscr(); library A; A.readdata(); A.printdata(); } INPUT: Enter name: PIYUSH JOSHI Enter no. of English books:2 Enter no. of hindi books:3 Enter other books: 4 OUTPUT: Total_books=9

Q45Define a class batsman with the following specifications:Private members Bcode (4-digitcode code number) Bname (20 characters) Innings,notout,runs(integer type) Batavg (it is calculated according the formula that is given belowBatavg=runs/(innings-notout) ) Public members Readdata() (function to accept values for bcode,bname, innings,notout, Runs and invoke the function calcavg() ) Displaydata() (function to display the data members on screen ) You should give thefunction definitions.DATE:12April,2010 FILE NAME:class #include<iostream.h> #include<conio.h> #include<stdio.h> class batsman { int bcode,runs,innings,notout; char name[20]; float batavg; void calcavg(); public: void readdata(); void displaydata(); }; void batsman::readdata() { cout<<"\n enter code"; cin>>bcode; cout<<"\n enter name"; gets(name); cout<<"\n enter runs"; cin>>runs; cout<<"\n enter innings"; cin>>innings; cout<<"notout"; cin>>notout; } void batsman::calcavg()

{ batavg=runs/(innings-notout); } void batsman::displaydata() { calcavg(); cout<<"\n"<<bcode; cout<<"\n"<<name; puts(name); cout<<"\n"<<innings; cout<<"\n"<<batavg; } void main() { clrscr(); batsman A; A.readdata(); A.displaydata(); } INPUT: Enter bcode:1 Enter bname:shini Enter innings:3 Enter notout:1 Enter runs:100 OUTPUT: 1 shini 3 batavg=50 Q46Program to declare a class student with students roll no., name,class & marks in private section of the class whereas 2 functions like intput & disply are defined in the public sections of class to accept required data through the function input & display the same by using function display(the data). DATE:7 April,2010 FILE NAME:class #include<iostream.h> #include<conio.h> #include<stdio.h> class student { private:

int rollno,clas,marks; char name[10]; public: void input(); void display(); }; void student::input() { cout<<"\n enter rollno"; cin>>rollno; cout<<"\n enter student class"; cin>>clas; cout<<"\n enter marks"; cin>>marks; cout<<"\n enter name of the student"; gets(name); } void student::display() { cout<<"\n rollno="<<rollno; cout<<"\n class="<<clas; cout<<"\n marks="<<marks; cout<<"\n enter name of the student"; puts(name); } void main() { clrscr(); student A; A.input(); A.display(); } INPUT; Enter rollno: 12 Enter class: 10 Enter marks: 98 Enter name: pooja OUTPUT: 10 98 pooja Q47Program using a class to store price list of 50 items & to print the largest price as well as the sum of all prices. DATE:15April,2010 FILE NAME:class

#include<iostream.h> class item { int itemcode[50]; float it_price[50]; public: void initialize(void); float largest(void); float sum(void); void display_items(void); }; void item::initialize(void) { for(int i=0;i<50;i++) { cout<<"item no"; cout<<"enter item code"; cin>>itemcode[i]; cout<<"enter item price"; cin>>it_price[i]; } } float item::largest(void) { float large=it_price[0]; for(int i=1;i<50;i++) { if(large<it_price[i]) large=it_price[i]; } return large; } float item::sum(void) { float sum=0; for(int i=0;i<50;i++) sum+= it_price[i]; return sum; } void item::display_items(void) { cout<<"code price"; for(int i=0;i<50;i++) { cout<<itemcode[i]; cout<<it_price[i]; }

} void main() { item order; order.initialize(); float total,biggest; int ch=0; do { cout<<"\n main menu"; cout<<"\n 1. display largest prize"; cout<<"\n 2.display sum of prizes"; cout<<"\n 3. display item list"; cout<<"\n enter your choice(1-3)"; cin>>ch; switch(ch) { case 1:biggest=order.largest(); cout<<"the largest prize is"<<biggest; break; case 2:total=order.sum(); cout<<"\n sum of prizes is"<<total; break; case 3:order.display_items(); break; } } while(ch>=1&&ch<=3); } INPUT: Main menu 1. display largest prize 2. display sum of prizes 3. display item list Enter your choice(1-3) 3 Enter itemcode:1 Enter itemno:2 Enter itemprice:100 OUTPUT: 1 2 100 Q48. Define a class stock in C++ with the following description Private members:

Icode of type int(item code) Item of type string(item name) Price of type float(price of each item) Qty of type integer(quantity in stock) Discount of type float(discount percentage on the item) A member function. Find disc() to calculate discount as per the following rule if qty<=50,discont is 0 If 50<qty<=100,discount is 5 If qty>100,discount is 10 Public members A function buy() to allow user to enter value for icode,item,price,qty,& call function .Find disc() to calculate the discount. A function showall() to allow user to view the content of all the data members. DATE:19April,2010 FILE NAME:class #include<iostream.h> #include<conio.h> #include<string.h> class stock { int icode,qty; char item[5]; float price,discount; void disc(); public: void buy(); void showall(); }; void stock::buy() { cout<<"\n enter item code"; cin>>icode; cout<<"\n enter quantity"; cin>>qty; cout<<"\n enter price of the item"; cin>>price; cout<<"\n enter item name"; cin.getline(item,5); } void stock::disc() { if(qty<=50) {

discount=0; } else if((qty>50)&&(qty<=100)) discount=5; } else if(qty>100) { discount=10; } { discount=discount*qty; } void stock::showall() { disc(); cout<<icode; cout<<qty; cout<<price; cout<<"item name="; cout.write(item,5); } void main() { clrscr(); stock A; A.buy(); A.showall(); } INPUT: Enter item code:2 Enter quantity:20 Enter price:50 Enter item name:rin OUTPUT: 2 20 50 Rin Discount=0 Q49Define a class student for the following specifications:Private members12 of the student are rollno(integer)

Names(array of characters of size 20) class_st(array of characters of size 8) marks(array of integers of size 5) percentage(float) calculate()-that calculates overall percentagemarks and return the percentage Public members of the students are readmarks()-read marks and invoke the calculate function displaymarks()-prints the data DATE:14April,2010 FILE NAME:class #include<iostream.h> #include<conio.h> #include<stdio.h> class student { private: int rollno,marks[5]; char name[20],clas_st[8]; float percenmtage; void calculate(); public: void readmarks(); void displaymarks(); }; void student::readmarks() { cout<<"\n enter rollno"; cin>>rollno; cout<<"\n enter name"; gets(name); cout<<"\n enter class of the student"; gets(clas_st); for(int i=0;i<5;i++) { cout<<"\n marks for 5 subjects"; cin>>marks[i]; } void student::calculate() { float total; total=marks[0]+marks[1]+marks[2]+marks[3]+marks[4]; percentage=(total/5)*100; } void student::displaymarks() {

calculate(); cout<<"\n rollno of the student"; cout<<"\n name of the student"; puts(name); cout<<"\n class of the student"; puts(class_st); cout<<"\n marks in subject1"<<marks[0]; cout<<"\n marks in subject2"<<marks[1]; cout<<"\n marks in subject3"<<marks[2]; cout<<"\n marks in subject4"<<marks[3]; cout<<"\n marks in subject5"<<marks[4]; cout<<"\n percentage marks:"<<percentage; } void main() { clrscr(); student A; A.readmarks(); A.displaymarks(); } INPUT: Enter rollno:12 Enter name:sneha Enter class of the student:IV Enter marks of subject1:90 Enter marks of subject2:90 Enter marks of subject3:90 Enter marks of subject4:100 Enter marks of subject5:100 OUTPUT: Rollno:12 Name:sneha Class:IV Marks ofsubject1:90 Marks of subject2:90 Marks of subject3:90 Marks of subject4:100 Marks of subject5:100 Percentage= 94%

Q50. NUMBERS S001 S002 S003 S004 S005 S006 S007 NAME RAMU TINU NEHA NITU TOSHIKA ANUPAMA VEDIKA

SQL CITY DELHI BANGLORE DELHI BOMBAY BOMBAY MADRAS DELHI ITEMNO 1201 1202 1203 1204 1205 1206 1207 SUPPLIEDQTY 100 200 150 190 20 180 300 RATE 40 30 40 20 50 40 30

(a) Display names of supplies whose names start with the letter T. SQL>select name from supplier where like T.

NAMES -----------------TINU TOSHIKA (b)Display details of suppliers residing in Delhi. SQL>select*from supplier Where city=Delhi; SNUM NAME SUPPPLIEDQTY CITY RATE --------------1201 1203 100 150 ITEMNO

--------------------------------------------------------------S001 40 S003 40 RAMU NEHA DELHI DELHI

S007 VEDIKA 30

DELHI

1207

300

(C)

Display supplier name, item and supplied quantity for quantity>150. SQL>select name,itemno,supplied from supplier Where suppliedqty>150; NAME ITEMNO SUPPLIEDQTY ------------ --------------------------------------------------TINU 1202 200 NITU 1204 190 ANUPAMA 1206 180 VEDIKA 1207 300

(d)Create a view with one of the colomns as rate*10. SQL>create view rate As select rate*10 From supplier; (e) List the suppliers name in the descending order of supplied quantity. SQL>select name from supplier Order by supply desc;

NAME -------------VEDIKA TINU NITU ANUPAMA NEHA TOSHIKA

7 ROWS SELECTED.

(f) List the different cities contained in supplier tables. SQL>select city from supplier Group by city;

CITY --------BANGLORE BOMBAY DELHI MADRAS G. Give the output of the following SQL commands on the basis of table supplier. i) SQL>select min(rate)from supplier; MIN(rate) --------------20 (ii)SQL>select count(distinct(city)) from supplier Where suppliedqty>150; COUNT(DISTINCT(CITY)) ------------4 (III) SQL>select name itemno,suppliedqty from supplier Where suppliedqty>150; NAME ----------------ITEMNO --------------SUPPLIEDQTY -------------------

TINU NITU ANUPAMA VEDIKA

1202 1204 1206 1207

200 190 180 300

(iv)SQL>select (rate*sullliedqty) from supplier Where suppliedqty>200; (RATE*SUPPLIEDQTY) ---------------------------------9000

COMPUTER FUNDAMENTALS
Q51. Program to find no. of vowels in a given line of text. DATE:1July,2009 FILE NAME:Arr #include<iostream.h> #include<stdio.h> #include<conio.h> void main() { clrscr(); char line[80]; int vow_ctr=0; cout<<"Enter the line:"<<endl; gets(line); for(int i=0;line[i]!='\0';++i) { switch(line[i]) { case'a': case'A': case'e': case'E': case'i': case'I':

case'o': case'O': case'u': case'U':++vow_ctr; } } cout<<" the total number of vowels in the given line is "<<vow_ctr<<endl; } INPUT:Enter line God is great OUTPUT: Total no.of vowels in the given line is 4 Q52. Program to replace every space in a string with a hyphen. DATE:2July,2010 FILE NAME:Arr #include<iostream.h> #include<conio.h> #include<string.h> int main() { clrscr(); char string[50]; cout<<"\n enter string(max. 49 characters)\n"; cin.getline(string,50); int x1=strlen(string); for(int i=0;string[i]!='\0';i++) if(string[i]==' ') string[i]='-'; cout<<"\n the changed string is"; cout.write(string,x1); return 0; } INPUT: Enter string Sita is great OUTPUT: The changed string is Stia-is-great Q53. Program to check if a string is palindrome or not. DATE:3July,2009

FILE NAME:Arr #include<iostream.h> #include<conio.h> #include<string.h> int main() { clrscr(); char string[20]; cout<<"\n enter string(max. 19 characters):"; cin.getline(string,20); for(int len=0;string[len]!='\0';len++); int i,j,flag=1; for(i=0,j=len-1;i<len/2;i++,j--) { if(string[i]!=string[j]){ flag=0; break; } } if(flag) cout<<"\n it is a palindrome.\n"; else cout<<"It is not a palindrome.\n"; return 0; } INPUT: Enter string:radar OUTPUT: It is a palindrome. INPUT: Enter string:computer OUTPUT: It is not a palindrome.

Q54.Program to reverse all the strings stored in a array. DATE:4July,2009 FILE NAME:arr #include<iostream.h> #include<conio.h> #include<string.h> int main() { clrscr(); char string[3][31],ch;

int i,j,len,k; cout<<"Enter the 3 strings\n"; for(i=0;i<3;i++) cin.getline(string[i],31); cout<<"\nThe list of original string follows:"; for(i=0;i<3;i++) cout<<"\n"<<string[i]; for(i=0;i<3;i++) { len=strlen(string[i]); for(j=0,k=len-1;j<len/2;j++,k--) { ch=string[i][j]; string[i][j]=string[i][k]; string[i][k]=ch; } } cout<<"\n\nthe list of reversed strings follows:"; for(i=0;i<3;i++) cout<<"\n"<<string[i]; return 0; } INPUT: Enter 3 strings India Is Great OUTPUT: The list of original string follows: India Is Great The list of reversed string follows: Aidni Si Taerg

Q55.Program to reverse all the strings stored in a array. DATE:5july,2009 FILE NAME:arr #include<iostream.h> #include<conio.h> #include<string.h>

int main() { clrscr(); char string[3][31],ch; int i,j,len,k; cout<<"Enter the 3 strings\n"; for(i=0;i<3;i++) cin.getline(string[i],31); cout<<"\nThe list of original string follows:"; for(i=0;i<3;i++) cout<<"\n"<<string[i]; for(i=0;i<3;i++) { len=strlen(string[i]); for(j=0,k=len-1;j<len/2;j++,k--) { ch=string[i][j]; string[i][j]=string[i][k]; string[i][k]=ch; } } cout<<"\n\nthe list of reversed strings follows:"; for(i=0;i<3;i++) cout<<"\n"<<string[i]; return 0; } INPUT: Enter 3 strings India Is Great OUTPUT: The list of original string follows: India Is Great The list of reversed string follows: Aidni Si Taerg Q56.Program to check the equality of two matrices. DATE:6july,2009 FILE NAME:arr

#include<iostream.h> #include<conio.h> void main() { clrscr(); int A[3][3],B[3][3],r,c; cout<<"\n enter first matrix row wise"; for(r=0;r<3;r++) { for(c=0;c<3;c++) { cin>>A[r][c]; } } cout<<"\n enter second matrix row wise"; for(r=0;r<3;r++) { for(c=0;c<3;c++) { cin>>B[r][c]; } } int flag=0; for(r=0;r<3;r++) { for(c=0;c<3;c++) { if(A[r][c]!=B[r][c]) { flag=1; break; } } if(flag==1)break; } if(flag) cout<<"\n matrices are unequal"; else cout<<"\n matrlces are equal"; } INPUT: Enter first matrix row wise: 1 2 3 4 5 6 7 8 9 Enter second matrix row wise:

1 2 3 4 5 6 7 8 9 OUTPUT: Matrices are equal. Q57.Program to count the no. of employees earning more than Rupees 1Lakh per annum.The monthly salaries of employees are given. DATE:7july,2009 FILE NAME:Array #include<iostream.h> #include<conio.h> void main() { clrscr(); const int size=5; float Sal[size], an_sal; int count=0; for(int i=0;i<size;i++) { cout<<"Enter the monthly salary for employee"<<i+1<<":"; cin>>Sal[i]; } for(i=0;i<size;i++) { an_sal=Sal[i]*12; if(an_sal>100000) count++; } cout<<count<<"employees out of"<<size<<"employees are earning more than Rs 1 Lakh per annum."; } INPUT: Enter monthly Enter monthly Enter monthly Enter monthly Enter monthly

salary salary salary salary salary

for for for for for

employee1:12000 employee2:10000 employee3:5000 employee4:8000 employee5:15000

OUTPUT: 3 employees out of 5 employees are earning more than Rs.1 lakh per annum.

Q58.Program to count the no. of employees earning more than Rupees 1Lakh per annum.The monthly salaries of employees are given. DATE:7july,2009 FILE NAME:Arr #include<iostream.h> #include<conio.h> void main() { clrscr(); const int size=5; float Sal[size], an_sal; int count=0; for(int i=0;i<size;i++) { cout<<"Enter the monthly salary for employee"<<i+1<<":"; cin>>Sal[i]; } for(i=0;i<size;i++) { an_sal=Sal[i]*12; if(an_sal>100000) count++; } cout<<count<<"employees out of"<<size<<"employees are earning more than Rs 1 Lakh per annum."; } INPUT: Enter monthly salary Enter monthly salary Enter monthly salary Enter monthly salary Enter monthly salary OUTPUT: 3 employees out of 5 lakh per annum. for for for for for employee1:12000 employee2:10000 employee3:5000 employee4:8000 employee5:15000

employees are earning more than Rs.1

Q58.Program to calculate grades of 4 students from 3 test scores DATE:8july,2009 FILE NAME:arr #include<iostream.h>

#include<conio.h> int main() { clrscr(); float marks[4][3],sum,avg; char grade[4]; int i,j; for(i=0;i<4;i++) { sum=avg=0; cout<<"\n enter 3 scores of student"<<i+1<<":"; for(j=0;j<3;j++) { cin>>marks[i][j]; sum+=marks[i][j]; } avg=sum/3; if(avg<45.0) grade[i]='D'; else if(avg<60.0) grade[i]='C'; else if(avg<75.0) grade[i]='B'; else grade[i]='A'; } for(i=0;i<4;i++) { cout<<"student"<<i+1<<"\t total marks="<<marks[i][0]+ marks[i][1]+ marks[i][2] <<"\t grade="<<grade[i]<<"\n"; } return 0; } INPUT: enter 3 Enter 3 Enter 3 Enter 3 scores scores scores scores of of of of student student student student 1:78 2:56 3:90 4:45 65 65 89 56 46 66 92 43

OUTPUT: Student1:NEHA Student2:VEENU Student3:PIYUSH

total marks=189 grade=B total marks=187 grade=B total marks=271 grade=A

Student4:RANU

total marks=144

grade=C

Q59.Program to read sales of 2 salesman in 4 months and to print total sales made by each salesman DATE:9july,2009 FILE NAME: Arr #include<iostream.h> #include<conio.h> int main() { clrscr(); int sales[2][4]; int i,j; unsigned long total; for(i=0;i<2;i++) { total=0; cout<<"\n enter sales for salesman"<<i+1<<"\n"; for(j=0;j<4;j++) { cout<<"\n month"<<j+1<<" "; cin>>sales[i][j]; total+=sales[i][j]; } cout<<"\n"; cout<<"\n total sales of salesman"<<i+1<<"="<<total<<"\n"; } return 0; } INPUT: Enter sales for salesman1: Month 1:2000 Month 2:3000 Month 3:4000 Month 4:5000 OUTPUT: Total sales: 14000 INPUT: Enter sales for salesman2: Month 1:1000 Month 2:2000 Month 3:3000

Month 4:4000 OUTPUT: total sales: 10000

FLOW OF CONTROL
Q60. Temperature conversion program that gives the user the option of converting farenheit to Celsius or Celsius to farenheit and depending upon users choice carry out the conversion. DATE:11july,2009 FILE NAME: foc #include<iostream.h> int main() { int choice; double temp, conv_temp; cout<<"Temperature conversion menu"<<"\n"; cout<<"1. Fahrenheit to celsius"<<"\n"; cout<<"2. celsius to Farenheit"<<"\n"; cout<<"Enter your choice(1-2):"; cin>>choice; if(choice==1) { cout<<"\n"<<"enter temperature in farenheit:"; cin>>temp; conv_temp=(temp-32)/1.8; cout<<"The temperature in celsius is"<<conv_temp<<"\n"; } else { cout<<"\n"<<"enter the temperature in celsius:"; cin>>temp; conv_temp=(1.8*temp)+32; cout<<"The temperature in farenheit is"<<conv_temp<<"\n"; } return 0; } INPUT: Temperature conversion menu 1.farenheit to Celsius 2.Celsius to farenheit Enter your choice (1-2):1 Enter temperature in farenheit:98.4

OUTPUT: 36.888889 Q61.Program to input no. of weeks days(1-7) & tanslate to its equivalent name of the day of week. DATE:12oct,2009 FILE NAME: Foc #include<iostream.h> int main() int dow; cout<<"Enter number of week's day(1-7):"; cin>>dow; switch(dow) { case 1: cout<<"\n"<<"Sunday"; break; case 2: cout<<"\n"<<"Monday"; break; case 3: cout<<"\n"<<"Tuesday"; break; case 4: cout<<"\n"<<"Wednesday"; break; case 5: cout<<"\n"<<"Thursday"; break; case 6: cout<<"\n"<<"Friday"; break; case 7: cout<<"\n"<<"Saturday"; break; default : cout<<"\n"<<"Wrong number of day"; break; } return 0; } INPUT: Enter no. of weeks days(1-7): 5 OUTPUT:Thursday Q62. Temperature conversion program that gives the user the option of converting farenheit to Celsius or Celsius to farenheit and depending upon users choice carry out the conversion. DATE:12oct,2010

FILE NAME: foc #include<iostream.h> int main() { int choice; double temp, conv_temp; cout<<"Temperature conversion menu"<<"\n"; cout<<"1. Fahrenheit to celsius"<<"\n"; cout<<"2. celsius to Farenheit"<<"\n"; cout<<"Enter your choice(1-2):"; cin>>choice; if(choice==1) { cout<<"\n"<<"enter temperature in farenheit:"; cin>>temp; conv_temp=(temp-32)/1.8; cout<<"The temperature in celsius is"<<conv_temp<<"\n"; } else { cout<<"\n"<<"enter the temperature in celsius:"; cin>>temp; conv_temp=(1.8*temp)+32; cout<<"The temperature in farenheit is"<<conv_temp<<"\n"; } return 0; } INPUT: Temperature conversion menu 1.farenheit to Celsius 2.Celsius to farenheit Enter your choice (1-2):1 Enter temperature in farenheit:98.4 OUTPUT: 36.888889 Q63. Program to calculate and print roots of a quadratic equation ax^2+bx+c=0. DATE:13oct,2009 FILE NAME:foc #include<iostream.h> #include<math.h>

void main() { float a,b,c,root1,root2,delta; cout<<"Enter the three numbers a,b& c of"<<"ax^2+bx+c:\n"; cin>>a>>b>>c; if(!a) cout<<"Value of \'a\' should not be zero"<<"\n Aborting!!!!!!!"<<"\n"; else { delta=b*b-4*a*c; if(delta>0) { root1=(-b+sqrt(delta))/(2*a); root2=(-b-sqrt(delta))/(2*a); cout<<"Roots are REAL and UNEQUAL"<<"\n"; cout<<"Root1="<<root1<<"Root2="<<root2<<"\n"; } else if (delta==0) { root1=-b/(2*a); cout<<"Roots are REAL and EQUAL"<<"\n"; cout<<"Root1="<<root1; cout<<"Root2="<<root2<<"\n"; } else cout<<"Root are COMPLEX and IMAGINARY"<<"\n"; } } INPUT: Enter three no.:a b &c of ax^2+bx+c:2 3 4 OUTPUT: Roots are complex and imaginary. Q64.Program to find whether a year is a leap year or not. DATE:14oct,2009 FILE NAME:foc #include<iostream.h> #include<conio.h> int main() { clrscr(); int year; cout<<"enter year in 4-digits\n";cin>>year;

if(year%100==0) { if(year%400==0) cout<<"\n leap year"; } else if(year%4==0) cout<<"\n leap year"; else cout<<"not a leap year"; return 0; } INPUT: Enter year in 4 digits: 2010 OUTPUT: Not a leap year Q65.Program to display a menu regarding rectangle operations DATE:15oct,2009 FILE NAME: Foc #include<iostream.h> #include<math.h> #include<process.h> void main() { char ch, ch1; float l,b,peri,area,diag; cout<<"\n Rectangle Menu"; cout<<"\n 1. Area"; cout<<"\n 2. Perimeter"; cout<<"\n 3. Diagonal"; cout<<"\n 4. Exit"<<"\n"; cout<<"Enter your choice:"; do { cin>>ch; if(ch=='1'||ch=='2'||ch=='3') { cout<<"Enter the length and breadth:"; cin>>l>>b; } switch(ch) { case'1':area=l*b;

cout<<"Area="<<area; break; case'2':peri=2*(l+b); cout<<"Perimeter="<<peri; break; case'3':diag=sqrt((l*l)+(b*b)); cout<<"Diagonal="<<diag; break;. case'4':cout<<"Breaking"; exit(0); default:cout<<"Wrong choice!!!!!!"; cout<<"Enter a valid one"; break; } cout<<"\n Want to enter more(y/n)?"; cin>>ch1; if(ch1=='y'||ch1=='Y') cout<<"Again enter the choice(1-4):"; } while(ch1=='y'||ch1=='Y'); } INPUT: rectangle menu 1.area 2.perimeter 3.diagonal 4.exit enter choice:1 enter length & breadth:3,5 OUTPUT: Area=15 INPUT: Want to enter more?:N

FU NCTIONS
Q66. Program to illustrate the call by value method of function invoking. DATE:16dec,2009 FILE NAME:Fun

#include<iostream.h> #include<conio.h> void main() { clrscr(); int change(int); int org=10; cout<<"\n the original value is"<<org; cout<<"\n return value of function change()is"<<change(org)<<"\n"; cout<<"\n the value after function change() is over"<<org<<"\n"; } int change(int a) { a=20; return a; } INPUT: Original value: 10 Return value of function change is: 20 OUTPUT: Value after function change: 10 Q67.Program to convert distance in feet or inches using a call by reference method. DATE:17dec,2009 FILE NAME: Fun #include<iostream.h> #include<conio.h> #include<process.h> int main() { clrscr(); void convert(float &,char &,char); float distance; char choice,type='F'; cout<<"\n enter distance in feet"; cin>>distance;

cout<<"\n want distances in feets or inchea?(f/I):\n"; cin>>choice; switch(choice) { case 'F': convert(distance,type,'F'); break; case 'I':convert(distance,type,'I'); break; default:cout<<"\n entered a wrong choice"; exit(0); } cout<<"\n distance="<<distance<<" "<<type<<"\n"; getch(); return 0; } void convert(float & d,char & t,char ch) { switch(ch) { case 'F':if(t=='I') { d=d/12; t='F'; } break; case 'I':if(t=='F') { d=d*12; t='I'; } break; } return; } INPUT: enter distance in feet:15 You want distance in feets or inches?(F/I): I OUTPUT: Distance=180 I Q68.Program to convert distance in feet or inches using a call by reference method. DATE:18dec,2009

FILE NAME:Fun #include<iostream.h> #include<conio.h> #include<process.h> int main() { clrscr(); void convert(float &,char &,char); float distance; char choice,type='F'; cout<<"\n enter distance in feet"; cin>>distance; cout<<"\n want distances in feets or inchea?(f/I):\n"; cin>>choice; switch(choice) { case 'F': convert(distance,type,'F'); break; case 'I':convert(distance,type,'I'); break; default:cout<<"\n entered a wrong choice"; exit(0); } cout<<"\n distance="<<distance<<" "<<type<<"\n"; getch(); return 0; } void convert(float & d,char & t,char ch) { switch(ch) { case 'F':if(t=='I') { d=d/12; t='F'; } break; case 'I':if(t=='F') { d=d*12; t='I'; } break; } return; }

INPUT: enter distance in feet:15 You want distance in feets or inches?(F/I): I OUTPUT: Distance=180 I Q69. Program to check whether a given character is contained in a string or not and find its position. DATE:18dec,2009 FILE NAME: Fun #include<iostream.h> #include<conio.h> int main() { clrscr(); int findpos(char s[ ],char c); char string[30],ch; int y=0; cout<<"\n enter main string"; cin.getline(string,30); cout<<"\n enter character to be searched for:"; cin.get(ch); y=findpos(string,ch); if(y==-1) cout<<"\n sorry! character is not in the string"; getch(); return 0; } int findpos(char s[ ],char c) { int flag=-1; for(int i=0;s[i]!=0;i++) { if(s[i]==c) { flag=0; cout<<"\n character is in the string at position"<<i+1; } } return(flag); }

INPUT: Enter a string: India is great Enter character to be searched:i OUTPUT: The character is in the string at the position 4 The character is in the string at the position 7 Q70. Program to print largest element of an array. DATE:19dec,2009 FILE NAME: Fun #include<iostream.h> #include<conio.h> int Large(int[],int); void main() { clrscr(); int A[50],i,n,MAX; cout<<"\n Enter the size of the array:"; cin>>n; cout<<"\n Enter the elemaents of the array:\n"; for(i=0;i<n;i++) cin>>A[i]; MAX=Large(A,n); cout<<"\n Largest element of the given array is:"<<MAX; getch(); } int Large(int B[],int n) { int max,i; max=B[0]; for(i=1;i<n;i++) { if(max < B[i]) max=B[i]; } return max; } INPUT: Enter size of array: 3

Enter the elements of the array: 4 5 6 OUTPUT: Largest element=6 Q72.The program to calculate the volume of sugar cube, cylindrical drum and the room(cuboid) by using the concept of function overloading? DATE:15dec,2009 FILE NAME:fun #include<iostream.h> #include<conio.h> void volume(float a); void volume(float a,float b); void volume(float a,float b,float c); void main() { int choice; int a; int b; int c; cout<<"\nThe volume of sugar cube...........1 "; cout<<"\nThe volume of cylindrical drum............2 "; cout<<"\nThe volume of room(cuboid).............................3 "; cout<<"\nEnter your choice: "; cin>>choice; if(choice==1) { cout<<"\nEnter the side of a cube "; cin>>a; volume(a); } if(choice==2) { cout<<"\nEnter radius and height of cylinder "; cin>>a>>b; volume(a,b); } if(choice==3) { cout<<"\nEnter the length,breadth and height of room "; cin>>a>>b>>c; volume(a,b,c);

} } void volume(float a) { float volume; volume=a*a*a; cout<<"\nThe volume of the sugar cube is "<<volume; } void volume(float a,float b) { float volume; volume=3.14*a*a*b; cout<<"\nThe volume of the cylindrical drum is "<<volume; } void volume(float a,float b,float c) { float volume; volume=a*b*c; cout<<"\nThe volume of the room(cuboid) is "<<volume; } INPUT:Te volume of sugar cube........1 The volume of cylindrical drum........2 The volume of room (cuboid)........3 Enter your choice.......2 Enter the radius and height of cylindrical drum 4, OUTPUT: The volume of cylindrical drum is 301.44 Q73.Program that finds the sum of the series: 1+(1+2)+(1+2+3)+(1+2+3+4)+............upto n terms. DATE:19dec,2010 FILE NAME:fun #include<iostream.h> #include<conio.h> void series(int n); void main() { clrscr(); int x; cout<<"Enter number of terms"; cin>>x; series(x); }

void series(int n) { int i,j,sum=0; for(i=1;i<=n;i++) { for(j=1;j<=i;j++) sum=sum+j; } cout<<"The sum of the series"<<sum; } OUTPUT Enter the numbers of terms: 3 The sum of the series is 10.

STRINGS
Q74. Program to enter a string & acharacter & print whether character is contained in string or not. DATE:1oct,2009 FILE NAME:strg #include<iostream.h> #include<string.h> int main() { char ch, string[36], flag; cout<<"\nEnter a string\n"; cin.getline(string,36); int x1=strlen(string); cout<<"Enter a character\n"; cin.get(ch); flag='n'; for(int i=0; string[i]!=x1;i++) { if(ch==string[i]) { flag='y'; break; } } if(flag=='y') cout.put(ch); cout.write("is contained in string",25); cout.write(string,x1);

return 0; } INPUT; Enter string; India is great Enter a character : G OUTPUT:character is contained in string Q75. Program to input 3-digit characters & form a no. from them. DATE:2oct,2009 FILE NAME: strg #include<iostream.h> #include<conio.h> int main() { clrscr(); char ch; int dig1,dig2,dig3,num; cout<<"Enter the three digit character:\n"; for(int i=0;i<3;i++) { ch=cin.get(); if(i==0) dig1=(ch-'0'); else if(i==1) dig2=(ch-'0'); else if(i==2) dig3=(ch-'0'); } num=dig3*100+dig2*10+dig1; cout<<"The number formed is"<<num; return 0; }

INPUT: Enter 3-digit character:the

OUTPUT: The no. formed is 5928 Q76.Program to input characters & change their case. DATE:3oct,2009 FILE NAME: Strg #include<iostream.h> #include<conio.h> #include<stdio.h> int main() { clrscr(); char ch; do { cout<<"\n enter a character"; cin>>ch; if(ch=='\n') { ch=getchar(); cout<<endl; } else if(ch>=65&&ch<=90) ch=ch+32; else if(ch>=97&&ch<=122) ch=ch-32; putchar(ch); } while(ch!='0'); return 0; } INPUT: Enter a character: r OUTPUT: R Q78. Program to count no. of words present in a line.

DATE:4oct,2009 FILE NAME: Strg #include<iostream.h> #include<conio.h> #include<stdio.h> void main() { clrscr(); char str[30]; int i,count=1; cout<<"\n enter any string"; gets(str); for(i=0;str[i]!='\0';++i) { if(str[i]==' ') { count++; while(str[i]==' ') i++; if(str[i]=='\0') i--; } cout<<"\n number of words in a string"<<count; getch(); } } INPUT: Enter any string:India is great. OUTPUT: 14 Q79.PROGRAM TO REVERSE ALL THE STRINGS STORED IN AN ARRAY. DATE:5oct,2009 FILE NAME:strg #include<iostream.h> #include<conio.h> #include<string.h> void main() { clrscr(); char string[3][31],ch; int i,j,len,k; cout<<"Enter the 3 strings\n";

for(i=0;i<3;i++) cin.getline(string[i],31); cout<<"\nThe list of original string follows\t"; for(i=0;i<3;i++) cout<<"\n"<<string[i]; for(i=0;i<3;i++) { len=strlen(string[i]); for(j=0,k=len-1;j<len/2;j++,k--) {ch=string[i][j]; string[i][j]=string[i][k]; string[i][k]=ch; } } cout<<"\n\nThe list of reversed strings follows:"; for(i=0;i<3;i++) cout<<"\n"<<string[i]; getch(); } INPUT: Enter 3 strings India Is Great OUTPUT: The original string is as follows India Is Great The list of reversed string is as follows aidni si taerg

STRUCTURE
Q80.Program for passing structure to functions through call by value and call by reference. DATE:1feb,2010 FILE NAME: Struct #include<iostream.h> #include<stdio.h> struct emp

{ int empno; char name[20]; double salary; }; void Reademp(emp & e) { cout<<"\n enter employee no."; cin>>e.empno; cout<<"\nenter employee name:"; gets(e.name); cout<<"\n enter employee salary:"; cin>>e.salary; } void Showemp(emp e) { cout<<"\nemployee details:"; cout<<"\n Empno:"<<e.empno; cout<<"\n name:"<<e.name; cout<<"\n salary:"<<e.salary; } void main() { emp e1; Reademp(e1); Showemp(e1); } INPUT: Enter employee no.:1 Enter employee name: ram Enter employee salary;45000 OUTPUT: employee details: Empno:1 Name:ram Salary:45000 Q81. Program for passing structures to functions through call by value and call by reference. DATE:7oct,2010 FILE NAME: Struct #include<iostream.h> #include<stdio.h> struct emp { int empno; char name[20]; double salary; }; void Reademp(emp & e) { cout<<"\n enter employee no."; cin>>e.empno;

cout<<"\nenter employee name:"; gets(e.name); cout<<"\n enter employee salary:"; cin>>e.salary; } void Showemp(emp e) { cout<<"\nemployee details:"; cout<<"\n Empno:"<<e.empno; cout<<"\n name:"<<e.name; cout<<"\n salary:"<<e.salary; } void main() { emp e1; Reademp(e1); Showemp(e1); } INPUT: Enter empno:1 Enter name:ram Enter salary:45000 OUTPUT: 1 Ram 45000 Q82.Program for passing structure to functions through call by value and call by reference. DATE:3feb,2010 FILE NAME: Struct #include<iostream.h> #include<stdio.h> struct emp { int empno; char name[20]; double salary; }; void Reademp(emp & e) { cout<<"\n enter employee no."; cin>>e.empno; cout<<"\nenter employee name:"; gets(e.name); cout<<"\n enter employee salary:"; cin>>e.salary; }

void Showemp(emp e) { cout<<"\nemployee details:"; cout<<"\n Empno:"<<e.empno; cout<<"\n name:"<<e.name; cout<<"\n salary:"<<e.salary; } void main() { emp e1; Reademp(e1); Showemp(e1); } INPUT: Enter employee no.:1 Enter employee name: ram Enter employee salary;45000 OUTPUT: employee details: Empno:1 Name:ram Salary:45000 Q83. Program for passing structures to functions through call by value and call by reference. DATE:4feb,2010 FILE NAME: Struct #include<iostream.h> #include<stdio.h> struct emp { int empno; char name[20]; double salary; }; void Reademp(emp & e) { cout<<"\n enter employee no."; cin>>e.empno; cout<<"\nenter employee name:"; gets(e.name); cout<<"\n enter employee salary:"; cin>>e.salary; } void Showemp(emp e) { cout<<"\nemployee details:"; cout<<"\n Empno:"<<e.empno; cout<<"\n name:"<<e.name; cout<<"\n salary:"<<e.salary; } void main()

{ emp e1; Reademp(e1); Showemp(e1); } INPUT: Enter empno:1 Enter name:ram Enter salary:45000 OUTPUT: 1 Ram 45000 Q84.Program for passing structure to functions through call by value and call by reference. DATE:4feb,2010 FILE NAME: Struct #include<iostream.h> #include<stdio.h> struct emp { int empno; char name[20]; double salary; }; void Reademp(emp & e) { cout<<"\n enter employee no."; cin>>e.empno; cout<<"\nenter employee name:"; gets(e.name); cout<<"\n enter employee salary:"; cin>>e.salary; } void Showemp(emp e) { cout<<"\nemployee details:"; cout<<"\n Empno:"<<e.empno; cout<<"\n name:"<<e.name; cout<<"\n salary:"<<e.salary; } void main() { emp e1; Reademp(e1); Showemp(e1); } INPUT: Enter employee no.:1 Enter employee name:

ram

Enter employee salary;45000 OUTPUT: employee details: Empno:1 Name:ram Salary:45000 Q85. Program for passing structures to functions through call by value and call by reference. DATE:7feb,2010 FILE NAME: Struct #include<iostream.h> #include<stdio.h> struct emp { int empno; char name[20]; double salary; }; void Reademp(emp & e) { cout<<"\n enter employee no."; cin>>e.empno; cout<<"\nenter employee name:"; gets(e.name); cout<<"\n enter employee salary:"; cin>>e.salary; } void Showemp(emp e) { cout<<"\nemployee details:"; cout<<"\n Empno:"<<e.empno; cout<<"\n name:"<<e.name; cout<<"\n salary:"<<e.salary; } void main() { emp e1; Reademp(e1); Showemp(e1); } INPUT: Enter empno:1 Enter name:ram Enter salary:45000 OUTPUT: 1 Ram 45000