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
#include 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>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]-1) cout<<"\nthe position of the element="<
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 #include 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
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 #include 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
} } 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 #include 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>reg[i]; } cout<<"\nenter the location from zero location"; cin>>loc; x=reg[loc]; back=loc; while(back>n; for(i=0;i>list[i]; } for(i=1;i=0)) { list[j+1]=list[j]; j=j-1; } list[j+1]=temp; } cout<<"\n the sorted list is:"; for(i=0;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 #include void main() { int reg[50]; int i,n,x,loc,back; cout<<"\nEnter the size of the list:"; cin>>n; for(i=0;i>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"<
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 #include 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>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:"<
{ for(int i=0;i
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 #include 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>A[i]; } for(i=0;i>B[i]; } a=b=c=0; while(a
for(i=0;i
Q8. Program to sort the elements of an array in descending order using selection sort. DATE: 8oct,2010 FILE NAME: arr #include #include 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>list[i]; }
for(i=0;ilist[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
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 #include
#include 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 :"<
} 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 #include 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<<"\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 #include 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 "<
{ 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 #include 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 :"<>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 #include 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"<
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 #include 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 "<>t; balance=balance-t; cout<<"\n\nYour account number: "<
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 #include 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<
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 #include #include 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 "<"<"<
cout<<"\n\nName of the subject----->"<"<"<
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 #include 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.:"<
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
#include #include 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<
Q18.Program for reading and writing class objects. DATE:2July,2010 FILE NAME:dfh #include #include 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:"<
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 #include #include 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<
Q20. Program to create a single file ant then display its content. DATE: 13july,2010 FILE NAME: dfh #include #include 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<>marks; fin.get(ch); cout<<"student name:"<
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 #include 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<>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 #include 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<
Q23. Program to display content of a file using get() function. DATE: 16july,2010 FILE NAME: dfh #include #include 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<
Q24. Program to create a file using put(). DATE: 17july,2010 FILE NAME: dfh #include #include 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<<" "<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 #include #include #include #include #include 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?"; 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--"<?"; 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"<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 #include 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>l->data; l->link=NULL; t->link=l; t=l; } t=f; cout<<"\nThe values are:"; while(t!=NULL) { cout<<"\n"<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 #include 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>last->data; last->link=NULL; temp->link=last; temp=last; } temp=first; cout<<"\n\nThe values are...."; while(temp!=NULL) { cout<<"\n"<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 #include #include #include 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"; 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"<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 searchedà25 Search is successful
Q28Program to create a linked list and insert elements at first. Date:21oct,2010 File Name: dst #include #include
#include #include 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"; 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 #include #include #include 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"; 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 #include #include #include #include void main() {char *s = "GOODLUCK"; for (int x =strlen(s) -1 ; x>=0; x--) { for ( int y=0; y<=x; y++) cout<
Q31Program to convert the uppercase in lower case & lowercase in uppercase. DATE:4oct,2010 FILE NAME:point #include #include #include #include
#include void main() { clrscr(); char *s = "HUMAN"; int L = strlen(s); for (int c =0;c
Q32. Program to find the length of the string . DATE: 5oct,2010 FILE NAME: point #include #include #include #include //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 #include #include #include 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 #include #include #include 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 #include #include 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 #include void main() { clrscr(); char ch='A'; int num=ch; cout<<"The ASCII code for"<
#include #include float cube(float); int main() { clrscr(); float num; cout<<"Enter a number"; cin>>num; cout<<"\n"<<"The cube of"< #include void main() { clrscr(); float side,area; cout<<"Enter side of the square:"; cin>>side; cout<<"\n The Area of the square is:" <
Q40Write a C++ program to convert a given number of days into years, weeks and days. DATE:7oct,2010 FILE NAME:comp
#include #include 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"<
Q41Write a C++ program that accepts a character between a to j and prints next 4 characters. DATE:10oct,2010 FILE NAME:comp #include #include 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 #include #include 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="< #include
#include #include 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 #include #include 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=<>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"<
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 #include #include 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="<
#include 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
} 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"<=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 50100,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 #include #include 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<>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"<
SQL
Q50. NUMBERS S001 S002 S003 S004 S005 S006 S007
NAME RAMU TINU NEHA NITU TOSHIKA ANUPAMA VEDIKA
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
--------------------------------------------------------------S001 40
RAMU
S003 40
NEHA
ITEMNO
DELHI
DELHI
---------------
1201
1203
100
150
S007 VEDIKA 30
(C)
DELHI
1207
300
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 #include #include void main() { clrscr(); char line[80]; int vow_ctr=0; cout<<"Enter the line:"<
case'o': case'O': case'u': case'U':++vow_ctr; } } cout<<" the total number of vowels in the given line is "< #include #include 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 #include #include 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
Q54.Program to reverse all the strings stored in a array. DATE:4July,2009 FILE NAME:arr #include #include #include 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"<
Q55.Program to reverse all the strings stored in a array. DATE:5july,2009 FILE NAME:arr #include #include #include
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"<
Q56.Program to check the equality of two matrices.
DATE:6july,2009 FILE NAME:arr
#include #include 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 #include void main() { clrscr(); const int size=5; float Sal[size], an_sal; int count=0; for(int i=0;i>Sal[i]; } for(i=0;i100000) count++; } cout<
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 #include void main() { clrscr(); const int size=5; float Sal[size], an_sal; int count=0; for(int i=0;i>Sal[i]; } for(i=0;i100000) count++; } cout<
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
#include 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"<>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"<
scores scores scores scores
of of of of
OUTPUT: Student1:NEHA Student2:VEENU Student3:PIYUSH
student student student student
1:78 2:56 3:90 4:45
65 65 89 56
46 66 92 43
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 #include 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"<>sales[i][j]; total+=sales[i][j]; } cout<<"\n"; cout<<"\n total sales of salesman"<
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 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"<>temp; conv_temp=(1.8*temp)+32; cout<<"The temperature in farenheit is"<
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,2009 FILE NAME: Foc #include 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): 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 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"<>temp; conv_temp=(1.8*temp)+32; cout<<"The temperature in farenheit is"< #include
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="<
#include #include 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 #include #include 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="<>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 #include void main() { clrscr(); int change(int); int org=10; cout<<"\n the original value is"< #include #include 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="<
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 #include #include 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="<
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 #include 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"<
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 #include 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>A[i]; MAX=Large(A,n); cout<<"\n Largest element of the given array is:"<
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 #include 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 "< #include void series(int n); void main() { clrscr(); int x; cout<<"Enter number of terms"; cin>>x; series(x); }
6
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"<
STRINGS Q74. Program to enter a string & acharacter & print whether character is contained in string or not. DATE:1oct,2009 FILE NAME:strg #include #include 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 #include 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"<
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 #include #include int main() { clrscr(); char ch; do { cout<<"\n enter a character"; cin>>ch; if(ch=='\n') { ch=getchar(); cout<=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 #include #include 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"< #include #include 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"<
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 #include 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:"< #include 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:"<
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 #include 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; }