122
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;

computer science c++ project

Embed Size (px)

DESCRIPTION

it is for class 12th students . Its a practical file for students.

Citation preview

Page 1: computer science c++ project

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,2010FILE 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;elseif(arr[middle]<x)first=middle+1;elselast=middle-1;}if(pos>-1)cout<<"\nthe position of the element="<<pos;elsecout<<"\unseccessful search";}

INPUT:Enter the size of array: 4

Page 2: computer science c++ project

Enter the element: 3Enter the element: 4Enter the element: 5Enter the element: 6Enter the value to be searched: 3

OUTPUT:The position of the element:1

Q2. Program to sort the element in ascending order using bubble sortDATE: 3oct,2010FILE 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();

Page 3: computer science c++ project

}}

INPUT:The given list is 2 13 6 9 8 1 10OUTPUT:Three sorted list is 13 10 9 8 6 2 1

Q3. Program to delete an element from an array. DATE: 3oct,2010FILE 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

Page 4: computer science c++ project

Enter the data element 2Enter the data element 3Enter the data element 4Enter the data element 5Enter the location from zero location 2OUTPUT-:The deleted data item=4The new list after deletionData element=2Data element=3Data element=5

Q4. Program to sort the element of an array in ascending order using insertion sort.DATE: 4oct,2010FILE 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];}

Page 5: computer science c++ project

}

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

Q5. Program to insert an element in to an array in kth position.DATE: 6oct,2010FILE 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];}}

Page 6: computer science c++ project

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

Q6. Program to search from gigen srting by linear search.DATE: 7oct,2010FILE 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";elsecout<<"\nelement found at index:"<<index<<",position:"<<index+1<<endl;}int lsearch(int ar[],int size,int item)

Page 7: computer science c++ project

{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,2010FILE 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++];elseC[c++]=B[b++];}while(a<n)C[c++]=A[a++];while(b<m)C[c++]=B[b++];cout<<"the final list is ..........";

Page 8: computer science c++ project

for(i=0;i<m+n;i++){cout<<"\n the data element is.."<<C[i];}getch();}

INPUT:Enter the size of the array 4 3Enter the list1: 4Enter the list1: 5Enter the list1: 8Enter the list1: 7Enter the list2: 1Enter the list2: 3Enter the list1: 9OUTPUT:The final list is....The data element is..1The data element is..3The data element is..4The data element is..5The data element is..7The data element is..8The data element is..9

Q8. Program to sort the elements of an array in descending order using selection sort.DATE: 8oct,2010FILE 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];}

Page 9: computer science c++ project

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 4Enter the element of array 6Enter the element of array 9Enter the element of array 3Enter the element of array 5OUTPUT:The sorted list is as follows:Data element 3Data element 5Data element 6Data 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,2010FILE NAME: class

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

Page 10: computer science c++ project

#include<string.h>class employee{private:char emp_name[25];schar 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;

Page 11: computer science c++ project

}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.MasterAddress: Central MarketCity: DelhiState: DHBasic salary: 3000

Dearness allowance is: 3600House rent allowance is: 450Gross 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,2010FILE 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{

Page 12: computer science c++ project

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;

Page 13: computer science c++ project

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: SAINAEnter the employee address: PWD Enter the city: JODHPUREnter the state: RAJASTHANEnter the salary: 45678Enter the customer name: GITAEnter the customer address: SHIMINPUREnter the city: KOTAEnter the state: RAJASTHANEnter the balance: 4543446Employee name: SAINAAddress: PWDCity: JODHPURState: RAJASTHANSalary: 45678Customer name: GITAAddress: SHIMINPURCity: KOTA

Page 14: computer science c++ project

State: RAJASTHANBalance: 4543446

Q11.Program demonstrates a sample example on class inheritance with a factorial.DATE: 4april,2010FILE 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()

Page 15: computer science c++ project

{clrscr();int num;derived tderived;cout<<"Enter the value for factorial ";cin>>num;tderived.changecounter(num);}

OUTPUT:Enter the value for factorial 3The factorial is 3

Q12. Program demonstrates a sample example on class inheritance with a factorial.DATE: 5april,2010FILE 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(); }

Page 16: computer science c++ project

}; 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: 3The 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,2010FILE 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;

Page 17: computer science c++ project

}void addition();~sum(){}};void sum::addition(){for(;i<=n;i++){if(i%2==0)sumeven=sumeven+i;elsesumodd=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();}

OUTPUTEnter the value for n 4Sum of the even numbers is 6Sum 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 detailsDATE:7april,2010FILE NAME:class#include<iostream.h>#include<conio.h>class bank_acc{ int account;

Page 18: computer science c++ project

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:17Enter the current balance:100000Enter the money deposited:1000OUTPUT-:The account number 17 has balance : 101000The money you withdrawn is:100Your account number: 17The balance is: 100900

Page 19: computer science c++ project

Q15.Programm to calculate the volume of a rectangularsolid length, width and height is given in meters,byusing the class named as rect_solid ,which hasthe following members:PRIVATE DATA MEMBERS:1.length2.width3.heightPUBLIC 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,2010FILE 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;

Page 20: computer science c++ project

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 : 3enter the height of rectangular solid is :4

OUTPUT-:the length of rectangular solid is :2the width of rectangular solid is :3the height of rectangular solid is :4the 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 nameb)roll numberc)subject named)subject codee)scored marksf)total marksDesign the base consisting of the data members such as name of the student,roll number and subject name.The derived

Page 21: computer science c++ project

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,2010FILE 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++){

Page 22: computer science c++ project

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:anhaRoll number:-1Progress record of anhaName of the subject:-mathematicsSubject code:-02Marks scored by the student:100

Q16. Assuming the class EMPLOYEE given below,write functionsin 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,2010FILE 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;

Page 23: computer science c++ project

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. : 120ENTER EMPLOYEE NAME : AZADREADING FROM FILE:WORKER NO. : 120WORKER NAME : AZAD

DATA FILE HANDLING Q17.Program to write and read a structure using write() and read()function using a binary file.DATE:1July,2010FILE NAME:dfh

#include<fstream.h>

Page 24: computer science c++ project

#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,2010FILE 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";

Page 25: computer science c++ project

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 detail of 3 studentEnter the name shiniEnter the grade AEnter the marks 76Enter the name FarahEnter the grade BEnter the marks 87 Enter the name gitaEnter the grade C

Page 26: computer science c++ project

Enter the marks 98

OUTPUT:The content of syu.dat are shown below-:Name: shiniGrade: AMarks: 76Name: FarahGrade: BMarks: 87Name: gitaGrade: CMarks: 98

Q19.Program to search in a file record maintained through classes DATE: 12july,2010FILE 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';

Page 27: computer science c++ project

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: 108OUTPUT:VENKAT, ROLL NO 108 HAS 87% MARKS AND A GRADE

Q20. Program to create a single file ant then display its content.DATE: 13july,2010FILE NAME: dfh

#include<fstream.h>#include<conio.h>void main(){clrscr();

Page 28: computer science c++ project

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: sumitaMarks: 34name: raveenaMarks:78name: gunjanmarks:87

OUTPUT:Student name: sumita marks:34student name: raveena marks:78student 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,2010FILE NAME: dfh

Page 29: computer science c++ project

#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: 34Enter marks: 28Do you want to enter more records?(y/n)=n

Q22. Program to use multiple file simultaneously.DATE: 14july,2010FILE 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);

Page 30: computer science c++ project

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.92Monica Patrick: 72.17

Q23. Program to display content of a file using get() function.DATE: 16july,2010FILE 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!!!

Page 31: computer science c++ project

Q24. Program to create a file using put().DATE: 17july,2010FILE 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=~

Page 32: computer science c++ project

DATA STRUCTUREQ25.Program to perform all the basic operatoin on stack. The stack contain data of integer type.DATE: 15oct,2010FILE 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; }

Page 33: computer science c++ project

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;

Page 34: computer science c++ project

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 menu1. Addition of stack.2. Deletion of stack.3. Traverse of stack.4. Exit.Enter the choice from above 1OUTPUT:Enter the value to be added in stack 23Do 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,2010FILE NAME: dst

#include<iostream.h>#include<conio.h>struct node{ int data;node *link;};

void main(){ clrscr();

Page 35: computer science c++ project

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";elsecout<<"\nUnccessful search";getch();}

INPUT:ENTER THE SIZE=8ENTER VALUE 1=4ENTER VALUE 2=1ENTER VALUE 3=2ENTER VALUE 4=8

Page 36: computer science c++ project

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

Q26. Program to create and traverse the linked list. The linkedlist contains data of type integer.DATE: 19oct,2010FILE 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;

Page 37: computer science c++ project

temp=temp->link;}getch();}

INPUT:Enter how many nodes do you want=2Enter data element 1=23Enter data element 2=26OUTPUT-:The values are.....23Q27.Pogramto create a linked and search a particular data value of integer data type.

Date: 20oct,2010File 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();

Page 38: computer science c++ project

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";elsecout<<"\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->10OUTPUT:The linked list values are:25203510Enter the data value to be searchedà25 Search is successful

Q28Program to create a linked list and insert elements at first.Date:21oct,2010File Name: dst

#include<iostream.h>#include<stdlib.h>

Page 39: computer science c++ project

#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);

Page 40: computer science c++ project

}

INPUT:Enter how many nodes in the linked list:3Enter thedata value of the node:4Enter the data value of the node-:10Enter the data value of the node5OUTPUT:For inserting at firstEnter data value to be inserted 5The linked list values are:54105

Q29Programto create a linked list and insert elements in between. Date:22oct,2010File 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;

Page 41: computer science c++ project

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->3Enter the data value of the node->34Enter the data value of the node->45Enter the data value of the node->10Enter the data value of the node->8OUTPUT:For inserting in between:Enter data value to be inserted: 5Enter the value of node after which insertion is made: 2

Page 42: computer science c++ project

The linked list values are:344558

Q30WAP to write the word in descending order ?DATE:2aug,2010FILE 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*************GOODLUCKGOODLUCGOODLUGOODLGOODGOOGO G ***************/

Q31Program to convert the uppercase in lower case & lowercase in uppercase.DATE:4oct,2010FILE NAME:point

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

Page 43: computer science c++ project

#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]);elseif (c%2 ==0)s[c] = 'E';elses[c] = tolower(s[c]);cout<<"New Message :"<<s<<"\n";}/*************output**************new message:EuEaE

Q32. Program to find the length of the string .DATE: 5oct,2010FILE NAME: point

#include<iostream.h>#include<string.h>#include<conio.h>#include <stdio.h>//CLASS DECLARATIONclass strn{char *a;int i;public:void read(); //MEMBER FUNCTIONSvoid calculate();}; //END OF CLASSvoid strn::read(){cout << "\n\t";cout << "\n\tEnter your name ";gets(a); //TO READ THE STRING}void strn::calculate(){

Page 44: computer science c++ project

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 FUNCTIONSx.calculate();getch();} //E N D O F M A I N/*****************output****************enter your name: nahathe length in your name is 4***************/

Q33. Program to check weather the two strings are equal or not.DATE: 18oct,2010FIL: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 CLASSvoid strn::read(){cout << "\n\t";cout << "\n\tEnter the first string ";gets(a);

Page 45: computer science c++ project

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 ";elsecout << "\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 ramenter the second string is tamstrings are equal.**********/

Page 46: computer science c++ project

Q34. Program to reverse the string using pointer.DATE: 20oct,2010FILE 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*************

Page 47: computer science c++ project

enter the string : radarthe reversed string is radar

Q35. Program to check whether the string is palindrome or not.DATE:6oct,2010FILE 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 ";elsecout << " is a palindrome ";

Page 48: computer science c++ project

}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: ridhithe entire string ridhi palindrome

COMPUTATIONAL PROGRAMQ36. Write a program to display ASCII code of a character and vice versa. DATE:7oct,2010FILE 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 66Adding 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/2010File Name: COMPUTATIONAL

Page 49: computer science c++ project

#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 19OUTPUT:The cube of is 729

Q39. Write a C++ program to compute the area of a square. Make assumptions on your own.DATE:8oct,2010FILE 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: 5OUTPUT;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,2010FILE NAME:comp

Page 50: computer science c++ project

#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: 100OUTPUT:Years=0Weeks=14Days=2

Q41Write a C++ program that accepts a character between a to j and prints next 4 characters.DATE:10oct,2010FILE 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();

Page 51: computer science c++ project

}INPUT:Enter a character between a to j: HOUTPUT:Next four character:IJKL

Q42. Write a program to read a number n and print n^2,n^3,n^4 and n^5.DATE:11oct,2010FILE 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=3OUTPUT:The square of number=9The cube of number=27The n raise to the power 4=9The n raise to the power =81

Q43. Program using function overloading to calculate the area of rectangle, area of triangle using Heron’s formula and area of circle.DATE:12oct,2010FILE NAME:comp

Page 52: computer science c++ project

#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;

Page 53: computer science c++ project

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 triangle2. for area of rectangle3. for area of circleEnter choice: 2Enter the length: 5Enter the width: 5OUTPUT: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 integersCompute that calculates the total number of books and return thetotal. Total_books are the sum ofenglish_books,hindi_books,hindi_books and others.Public members of the library areReaddata() accepts the data and involves the compute functionsPrintdata() prints the data. Date:3April,2010FILE NAME: class

#include<iostream.h>#include<conio.h>#include<stdio.h>class library{

Page 54: computer science c++ project

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 JOSHIEnter no. of English books:2Enter no. of hindi books:3Enter other books: 4

OUTPUT:

Page 55: computer science c++ project

Total_books=9

Q45Define a class batsman with the following specifications:-Private membersBcode (4-digitcode code number)Bname (20 characters)Innings,notout,runs(integer type)Batavg (it is calculated according the formula that is given below-Batavg=runs/(innings-notout) )

Public membersReaddata() (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,2010FILE 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;

Page 56: computer science c++ project

}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:1Enter bname:shiniEnter innings:3Enter notout:1Enter runs:100OUTPUT:1shini3batavg=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,2010FILE NAME:class

#include<iostream.h>#include<conio.h>#include<stdio.h>class student

Page 57: computer science c++ project

{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: 12Enter class: 10Enter marks: 98Enter name: poojaOUTPUT:1098pooja

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

Page 58: computer science c++ project

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];

Page 59: computer science c++ project

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 prize2. display sum of prizes3. display item list

Enter your choice(1-3)3Enter itemcode:1Enter itemno:2Enter itemprice:100OUTPUT:12100

Page 60: computer science c++ project

Q48. Define a class stock in C++ with the following descriptionPrivate 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 0If 50<qty<=100,discount is 5If qty>100,discount is 10

Public membersA 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,2010FILE 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()

Page 61: computer science c++ project

{if(qty<=50){discount=0;}elseif((qty>50)&&(qty<=100))discount=5;}elseif(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:2Enter quantity:20Enter price:50Enter item name:rinOUTPUT:22050RinDiscount=0

Q49Define a class student for the following specifications:-

Page 62: computer science c++ project

Private members12of the student arerollno(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 percentagePublic members of the students arereadmarks()-read marks and invoke the calculate function displaymarks()-prints the dataDATE:14April,2010FILE 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;

Page 63: computer science c++ project

}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:12Enter name:snehaEnter class of the student:IVEnter marks of subject1:90Enter marks of subject2:90Enter marks of subject3:90Enter marks of subject4:100Enter marks of subject5:100OUTPUT:Rollno:12Name:snehaClass:IVMarks ofsubject1:90Marks of subject2:90Marks of subject3:90Marks of subject4:100Marks of subject5:100Percentage= 94%

Page 64: computer science c++ project

Q50. SQL NUMBERS NAME CITY ITEMNO SUPPLIEDQTY RATES001 RAMU DELHI 1201 100 40S002 TINU BANGLORE 1202 200 30S003 NEHA DELHI 1203 150 40S004 NITU BOMBAY 1204 190 20S005 TOSHIKA BOMBAY 1205 20 50S006 ANUPAMA MADRAS 1206 180 40S007 VEDIKA DELHI 1207 300 30

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

NAMES------------------TINUTOSHIKA

(b) Display details of suppliers residing in Delhi.SQL>select*from supplierWhere city=’Delhi’;SNUM NAME CITY ITEMNO SUPPPLIEDQTY RATE --------- ---------- ------------ --------------- ---------------------- --------------S001 RAMU DELHI 1201 100 40S003 NEHA DELHI 1203 150 40S007 VEDIKA DELHI 1207 300 30

(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

Page 65: computer science c++ project

ANUPAMA 1206 180 VEDIKA 1207 300

(d) Create a view with one of the colomns as rate*10.

SQL>create view rateAs select rate*10From supplier;

(e) List the suppliers name in the descending order of supplied quantity.SQL>select name from supplier Order by supply desc;

NAME--------------VEDIKATINUNITUANUPAMANEHATOSHIKA

7 ROWS SELECTED.(f) List the different cities contained in supplier tables.

SQL>select city from supplierGroup by city;

CITY--------- BANGLOREBOMBAYDELHIMADRAS

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 supplierWhere suppliedqty>150;COUNT(DISTINCT(CITY))

Page 66: computer science c++ project

------------- 4(III) SQL>select name itemno,suppliedqty from supplierWhere suppliedqty>150;NAME ITEMNO SUPPLIEDQTY ----------------- --------------- ------------------- TINU 1202 200 NITU 1204 190ANUPAMA 1206 180 VEDIKA 1207 300

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

COMPUTER FUNDAMENTALSQ51. Program to find no. of vowels in a given line of text.DATE:1July,2009FILE 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':

Page 67: computer science c++ project

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 greatOUTPUT:Total no.of vowels in the given line is 4

Q52. Program to replace every space in a string with a hyphen.DATE:2July,2010FILE 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 stringSita is greatOUTPUT:The changed string is Stia-is-great

Q53. Program to check if a string is palindrome or not.DATE:3July,2009

Page 68: computer science c++ project

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";elsecout<<"It is not a palindrome.\n";return 0;}INPUT:Enter string:radarOUTPUT:It is a palindrome.INPUT:Enter string:computerOUTPUT:It is not a palindrome.

Q54.Program to reverse all the strings stored in a array.DATE:4July,2009FILE NAME:arr

#include<iostream.h>#include<conio.h>#include<string.h>int main(){clrscr();char string[3][31],ch;

Page 69: computer science c++ project

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 stringsIndiaIsGreatOUTPUT:The list of original string follows:IndiaIs GreatThe list of reversed string follows:AidniSiTaerg

Q55.Program to reverse all the strings stored in a array.DATE:5july,2009FILE NAME:arr

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

Page 70: computer science c++ project

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 stringsIndiaIsGreatOUTPUT:The list of original string follows:IndiaIs Great

The list of reversed string follows:AidniSiTaerg

Q56.Program to check the equality of two matrices.DATE:6july,2009FILE NAME:arr

Page 71: computer science c++ project

#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";elsecout<<"\n matrlces are equal";}

INPUT:Enter first matrix row wise:1 2 34 5 67 8 9Enter second matrix row wise:

Page 72: computer science c++ project

1 2 34 5 67 8 9OUTPUT: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,2009FILE 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 salary for employee1:12000Enter monthly salary for employee2:10000Enter monthly salary for employee3:5000Enter monthly salary for employee4:8000Enter monthly salary for employee5:15000

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

Page 73: computer science c++ project

Q58.Program to count the no. of employees earning more than Rupees 1Lakh per annum.The monthly salaries of employees are given.DATE:7july,2009FILE 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 for employee1:12000Enter monthly salary for employee2:10000Enter monthly salary for employee3:5000Enter monthly salary for employee4:8000Enter monthly salary for employee5:15000OUTPUT:3 employees out of 5 employees are earning more than Rs.1 lakh per annum.

Q58.Program to calculate grades of 4 students from 3 test scoresDATE:8july,2009FILE NAME:arr

#include<iostream.h>

Page 74: computer science c++ project

#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';elseif(avg<60.0)grade[i]='C';elseif(avg<75.0)grade[i]='B';elsegrade[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 scores of student 1:78 65 46Enter 3 scores of student 2:56 65 66Enter 3 scores of student 3:90 89 92Enter 3 scores of student 4:45 56 43

OUTPUT:Student1:NEHA total marks=189 grade=’B’Student2:VEENU total marks=187 grade=’B’Student3:PIYUSH total marks=271 grade=’A’

Page 75: computer science c++ project

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 salesmanDATE:9july,2009FILE 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:2000Month 2:3000Month 3:4000Month 4:5000OUTPUT:Total sales:14000INPUT:Enter sales for salesman2:Month 1:1000Month 2:2000Month 3:3000

Page 76: computer science c++ project

Month 4:4000OUTPUT: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,2009FILE 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 menu1.farenheit to Celsius2.Celsius to farenheitEnter your choice (1-2):1

Page 77: computer science c++ project

Enter temperature in farenheit:98.4

OUTPUT:36.888889

Q61.Program to input no. of week’s days(1-7) & tanslate to its equivalent name of the day of week.DATE:12oct,2009FILE 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 week’s days(1-7): 5OUTPUT: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.

Page 78: computer science c++ project

DATE:12oct,2010FILE 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 menu1.farenheit to Celsius2.Celsius to farenheitEnter your choice (1-2):1Enter temperature in farenheit:98.4OUTPUT:36.888889

Q63. Program to calculate and print roots of a quadratic equation ax^2+bx+c=0.DATE:13oct,2009FILE NAME:foc

#include<iostream.h>

Page 79: computer science c++ project

#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";}elsecout<<"Root are COMPLEX and IMAGINARY"<<"\n";}}

INPUT:Enter three no.:a b &c of ax^2+bx+c:2 3 4OUTPUT:Roots are complex and imaginary.

Q64.Program to find whether a year is a leap year or not.DATE:14oct,2009FILE NAME:foc

#include<iostream.h>#include<conio.h>int main(){clrscr();int year;

Page 80: computer science c++ project

cout<<"enter year in 4-digits\n";cin>>year;if(year%100==0){if(year%400==0)cout<<"\n leap year";}elseif(year%4==0)cout<<"\n leap year";elsecout<<"not a leap year";return 0;}INPUT:Enter year in 4 digits:2010OUTPUT:Not a leap year

Q65.Program to display a menu regarding rectangle operationsDATE:15oct,2009FILE 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){

Page 81: computer science c++ project

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 menu1.area2.perimeter3.diagonal4.exit

enter choice:1enter length & breadth:3,5OUTPUT:Area=15

INPUT:Want to enter more?:N FUNCTIONS

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

Page 82: computer science c++ project

#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:10Return value of function change is:20OUTPUT:Value after function change:10

Q67.Program to convert distance in feet or inches using a call by reference method.DATE:17dec,2009FILE 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;

Page 83: computer science c++ project

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):IOUTPUT:Distance=180 I

Q68.Program to convert distance in feet or inches using a call by reference method.DATE:18dec,2009

Page 84: computer science c++ project

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;}

Page 85: computer science c++ project

INPUT:enter distance in feet:15You want distance in feets or inches?(F/I):IOUTPUT:Distance=180 I

Q69. Program to check whether a given character is contained in a string or not and find its position.DATE:18dec,2009FILE 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);}

Page 86: computer science c++ project

INPUT:Enter a string:India is greatEnter character to be searched:i

OUTPUT:The character is in the string at the position 4The character is in the string at the position 7

Q70. Program to print largest element of an array.DATE:19dec,2009FILE 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

Page 87: computer science c++ project

Enter the elements of the array:4 5 6

OUTPUT:Largest element=6

Q72.The program to calculate the volume of sugar cube, cylindrical drumand the room(cuboid) by using the concept of function overloading?DATE:15dec,2009FILE 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);

Page 88: computer science c++ project

}}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........1The volume of cylindrical drum........2The volume of room (cuboid)........3Enter your choice.......2Enter the radius and height of cylindrical drum 4, 6

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,2010FILE 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);}

Page 89: computer science c++ project

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;}OUTPUTEnter the numbers of terms:3The 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,2009FILE 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);

Page 90: computer science c++ project

return 0;}

INPUT;Enter string;India is greatEnter a character :G

OUTPUT:character is contained in string

Q75. Program to input 3-digit characters & form a no. from them.DATE:2oct,2009FILE 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

Page 91: computer science c++ project

OUTPUT:The no. formed is 5928

Q76.Program to input characters & change their case.DATE:3oct,2009FILE 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;}elseif(ch>=65&&ch<=90)ch=ch+32;elseif(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.

Page 92: computer science c++ project

DATE:4oct,2009FILE 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,2009FILE 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";

Page 93: computer science c++ project

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 stringsIndiaIs Great

OUTPUT:The original string is as followsIndia Is Great

The list of reversed string is as followsaidnisitaerg

STRUCTURE

Q80.Program for passing structure to functions through call by value and call by reference.DATE:1feb,2010FILE NAME:Struct

#include<iostream.h>#include<stdio.h>

Page 94: computer science c++ project

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.:1Enter employee name: ramEnter employee salary;45000

OUTPUT:employee details:Empno:1Name:ramSalary:45000

Q81. Program for passing structures to functions through call by value and call by reference.DATE:7oct,2010FILE 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.";

Page 95: computer science c++ project

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:1Enter name:ramEnter salary:45000

OUTPUT:1Ram 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;

Page 96: computer science c++ project

}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.:1Enter employee name: ramEnter employee salary;45000

OUTPUT:employee details:Empno:1Name:ramSalary:45000

Q83. Program for passing structures to functions through call by value and call by reference.DATE:4feb,2010FILE 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;}

Page 97: computer science c++ project

void main(){emp e1;Reademp(e1);Showemp(e1);}

INPUT:Enter empno:1Enter name:ramEnter salary:45000OUTPUT:1Ram 45000

Q84.Program for passing structure to functions through call by value and call by reference.DATE:4feb,2010FILE 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

Page 98: computer science c++ project

Enter employee name: ramEnter employee salary;45000

OUTPUT:employee details:Empno:1Name:ramSalary:45000

Q85. Program for passing structures to functions through call by value and call by reference.DATE:7feb,2010FILE 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:1Enter name:ramEnter salary:45000

OUTPUT:1Ram 45000

Page 99: computer science c++ project
Page 100: computer science c++ project
Page 101: computer science c++ project