Apex institute for IIT-JEE is the institution of making IITians in the Ghaziabad. It is the Institute in Indirapuram to making IITians (Eng..). Its mission is to upgrade the teaching profes…Full description
Class 12 cbse c++ file
For class 12 CBSE studentsFull description
For class 12 CBSE studentsFull description
a detailed investigatory project on the preparation of soap for class 12 final practical exam.. this project received full marks from the external examiner.Full description
For class 12 CBSE studentsFull description
c++ programs
COMPUTER SCIENCE NOTES
c++ programs
c++ programs
chemistry project on food preservative
Full description
Computer Shop ManagementFull description
This is the document of CBSE XII's Computer Project (Programs) This document contains 21 C++ Programs, 1 SQL.
This is the document of CBSE XII's Computer Project (Programs) This document contains 21 C++ Programs, 1 SQL.Full description
ICT Management System
A c++ program for class 12
dgxFull description
dgxFull description
CBSE Sample Paper for Class 12 Mathematics from 4ono.com
Title Self-explanatory.
ECO FULL STUDY MATERIALFull description
investigatory project on chemistry for class 12 CBSE on the topic composition of soft drinks
ARRAYS Q1. Write a program to illustrate the two types of searches in an integer type array. Make use of functions and make a menu driven program.
#include #include #include int Lsearch(int[],int,int); int Bsearch(int[],int,int); int main() { char ch1; int ch; int AR[50],i,item,N,index; do { clrscr(); cout<<"\n"<<"S E A R C H
M E N U";
cout<<"\n1. Linear Search"; cout<<"\n2. Binary Search"; cout<<"\n3. Exit"<<"\n"; cout<<" Enter your choice (1,2 or 3): "; cin>>ch; if( ch==1|| ch==2)
{ cout<< "Enter desired array size(max.50).....:"; cin>>N; } switch(ch) { case 1 :cout<<"\nEnter array elements:\n"; for(i=0;i>AR[i];} cout<<"\nEnter element to be searched for........:\n"; cin>>item; index=Lsearch(AR,N,item); if(index== -1) cout<<"\n*^*^* Sorry!! Given element could not be found *^*^*\n"; else cout<<"\nElement found at index : "<
case 2 : cout<<"\nEnter array elements(must be sorted in asc order) :\n"; for(i=0;i>AR[i]; cout<<"\nEnter element to be searched for........:"; cin>>item; index=Bsearch(AR,N,item); if(index== -1)
cout<<"\n*^*^* Sorry!! Given element could not be found *^*^*\n"; else cout<<"\nElement found at index : "<
case 3 :break ; default : cout<<"!!!!!!Wrong choice!!!!!!!\n"; break ; } cout<<"\nPress a key to continue......\n"; ch1 = getchar() ; } while(ch>=1 && ch<=2); return 0 ; } int Lsearch(int AR[],int size,int item) { for (int i=0;i
return i;
while(beg<=last) { mid=(beg+last)/2; if (item==AR[mid])
return mid;
else if (item >AR[mid])
beg=mid+1;
else last = mid-1; } return -1;
OUTPUT S E A R C H
M E N U
1.
Linear Search
2.
Binary search
3.
Exit
Enter your choice: 1 Enter desired array size (max.50)……: 3 Enter array elements : 1 4 6 Enter elements to be searched for ………..: 4
Element found at index : 1, Position: 2 Press a key to continue…….
Q2. Write a program to illustrate deletion (with position) in an array (the position can be the beginning or the end or in middle anywhere at a specified place, so all the cases should be handled). Write functions for all three separately. And make the program menu driven and user friendly. #include #include #include int size,a,ch,AR[50]; char ans; void delbeg(int AR[],int size) {for(int i=1;i
void dellast(int AR[],int size) {size=size-1; cout<<"\n The array after making changes"<
for(int i=0;i
void delany(int AR[],int size,int P) {for(int i=P;i>size; cout<<"Enter the elements of the array"; for(int i=0;i>AR[i]; { do {cout<<"Element to be deleted"<
cin>>ch; switch(ch) {case 1:delbeg(AR,size);
break; case 2:size=size-1; dellast(AR,size); break; case 3:cout<<"Enter the position of the element"; cin>>a; delany(AR,size,a); break; default:cout<<"Invalid choice"<>ans;} while(ans=='y');getch(); }}
OUTPUT: Enter the size of the array 4 Enter the elements of the array 1
2
3
4
Element to be deleted
1.From beginning 2.From end 3.From anywhere Enter your choice 1 The array after making changes 2
3
4
Want to continue?(y/n) N Q3. Write a program to illustrate all the three sorts – Insertion, Selection and Bubble sort in an array. Make use of functions to do the same. Make a menu driven and user friendly program.*/ #include #include void selectionSort(int Array[10]); int bubblesort(int array[10]); void insertion_sort(int x[],int length); void main() { clrscr(); int a[10]; cout<<"Enter the numbers in the array:"; for(int i=0;i<10;i++) { cin>>a[i]; } int ch;
do {cout<<"\nMENU" <<"\n1.selection sort" <<"\n2.insertion sort" <<"\n3.bubble sort" <<"\n4.exit\n" ; <<"\nenter your choice(1-4):"; cin>>ch; switch(ch) {case 1: selectionSort(a); break; case 2: bubblesort(a); break; case 3: insertion_sort(a,10); break; } }while(ch<4); getch(); } void selectionSort(int A[10]) { int i, j, min, min1; for(i = 0; i<10; i++) {
min1 = i;
min = A[i];
for(j = i+1;j<10;j++) { {
if(min > A[j]) min1 = j;
min = A[j]; } } int temp = A[i]; A[i] = A[min1]; A[min1]=temp; } cout<<"Array After selection Sorting is:"<
} int bubblesort(int array[10]) { int len=10; int temp; for(int i=1;iarray[j+1] && (j+1)
// then swap
cout<<"Array After Bubble Sorting is(ascending order):"<key && i>=0) { x[i+1]=x[i];
i--; } x[i+1]=key; } cout<
OUTPUT Enter number:1 9 7 5 0 2 4 6 3 8 MENU 1.
selection sort
2.
insertion sort
3.
bubble sort
4.
exit
enter your choice(1-4):1 array after selection sorting is : 0 1 2 3 4 5 6 7 8 9 MENU 1.
selection sort
2.
insertion sort
3.
bubble sort
4.
exit
enter your choice(1-4):2 array after bubble sorting is(ascending order) : 0 1 2 3 4 5 6 7 8 9
MENU 1.
selection sort
2.
insertion sort
3.
bubble sort
4.
exit
enter your choice(1-4):3 array after insertion sort is : 0 1 2
3 4 5 6 7 8 9 MENU 1.
selection sort
2.
insertion sort
3.
bubble sort
4.
exit
enter your choice(1-4):4
Q4. Write a program to sum the elements above and below the main diagonal of a matrix.*/
#include #include void main() { char ch; do { clrscr();
int a[20][20], i, j, m, n , csum, dsum; //Input rows and column of Matrix A\n"; cout<<"\n Input row and column of Matrix A\n"; cin>>m>>n; cout<<"\n Input Matrix A\n"; for(i=0;i>a[i][j]; } cout<<"\n Matrix A \n";
// Display Matrix-A\par
for(i=0;i
elements above the main diagonal\par
for(i=0;i
cout<j) dsum+=a[i][j]; } } cout<<"\n Below the main digonal is:"; cout<>ch; }while((ch=='y')||(ch=='Y')); getch(); } //end of main
OUTPUT Input row and column of Matrix-A 2 3 Input Matrix-A 1 2 3
4 5 6 Matrix A 1 2 3 4 5 6 Sum of elements Above the main diagonal is:11 Below the main diagonal is:4 Want to continue(y/n)? : n Q5. Write a program to merge two given arrays into the third array C. Use switch case and implement the same with at least 4 different combinations. Make use of functions. #include #include #include
//FUNCTION TO MERGE IF ONE IS ASCENDING AND ONE IS DESCENDING void merge(int[],int,int[],int); //FUNCTION TO MERGE IF BOTH IS ASCENDING void merge1(int[],int,int[],int); //FUNCTION TO MERGE IF BOTH IS DESCENDING void merge2(int[],int,int[],int);
int f_asc(int a[]) { int M; cout<<"How many elements do u want to enter in the first array?[ascending]\n"; cin>>M ; cout<<"\nEnter first arrays element..\n"; for(int i=0;i>a[i]; return M; }
int f_desc(int a[]) { int M; cout<<"How many elements do u want to enter in the first array?[descending]\n"; cin>>M; cout<<"\nEnter first arrays element..\n"; for(int i=0;i>a[i]; return M; } int s_asc(int a[]) { int M;
cout<<"How many elements do u want to enter in the second array?[ascending]\n"; cin>>M ; cout<<"\nEnter second arrays element..\n"; for(int i=0;i>a[i]; return M; } int s_desc(int a[]) { int M; cout<<"How many elements do u want to enter in the second array?[descending]\n"; cin>>M ; cout<<"\nEnter second arrays element..\n"; for(int i=0;i>a[i]; return M; } void main() { int a[50], b[50], M, N, choice; menu:; clrscr(); cout<<"\nMERGING ARRAYS\n"; cout<<"1. Both Arrays Ascending\n";
cout<<"2. Both Arrays Descending\n"; cout<<"3. Fisrt Ascending, Second Descending\n"; cout<<"4. Fisrt Descending, Second Ascending\n"; cout<<"0. Exit\n"; cout<<"Enter your choice:\t"; cin>>choice; switch(choice) { case 1 : M=f_asc(a); N=s_asc(b); merge1(a,M,b,N); break;
case 2 : M=f_desc(a); N=s_desc(b); merge2(a,M,b,N); break; case 3 : M=f_asc(a); N=s_desc(b); merge(a,M,b,N); break;
} else { while(b>=0) C[c++] = B[b--]; } cout<<"\n\nThe merged array is as shown \n"; for(i=0;i
OUTPUT MERGING ARRAYS 1.
Both Arrays Ascending
2.
Both Arrays Descending
3.
First Ascending, Second Descending
4.
First descending, second ascending
0.
Exit
Enter your choice : 1 How many elements do you want to enter in the first array? [ascending] 5 Enter first arrays element..
1 3 5 7 9 How many elements do you want to enter in the second array? [ascending] 5 Enter second arrays element.. 2 4 6 8 10 The merged array is as shown 1 2 3 4 5 6 7 8 9 10
MERGING ARRAYS 5.
Both Arrays Ascending
6.
Both Arrays Descending
7.
First Ascending, Second Descending
8.
First descending, second ascending
1.
Exit
Enter your choice : 0
Q6. Write a program to illustrate insertion (with position) in an array( the position can be the beginning or the end or in middle anywhere at a specified place)(all three cases are to be handled).Write functions for all three separately. And make the program menu driven and user friendly.*/
#include #include #include
int FindPos(int[], int, int);
void main() { char s; do { int AR[50], ITEM, N, index; //array can hold maximum 50 elements clrscr(); cout<<"How many elements do you want?(max. 50)..."; cin>>N; cout<<"\nEnter Array elements (in increasing order)\n"; for(int i=0; i>AR[i]; char ch='y'; while((ch=='y')||(ch=='Y')) { cout<<"\nEnter Element to be inserted..."; cin>>ITEM;
if(N==50) { cout<<"Overflow!!"; exit(1); } index=FindPos(AR, N, ITEM); for(i=N; i>index; i--) AR[i]=AR[i-1]; AR[index]=ITEM; N+=1; //Number of elements updated cout<<"\n Want to insert more elements? (y/n): "; cin>>ch; } cout<<"\nThe array is now as shown below.....\n"; for(i=0;i
";
cout<>s; }while((s=='y')||(s=='Y')); getch(); }
int FindPos(int AR[], int size, int item) determine the position for new element { int pos;
1 6 9 Enter Element to be inserted. . .5 Want to insert more elements?
:
y
Enter Element to be inserted. . .8 Want to insert more elements? The array is now 1
5
:
n
as shown below . . . .
6
8
9
Want to continue with new array ?
:
n
Q7. Write a program to wap in c++ to implement stack as an array.
#include #include #include
int pop(int[],int&); int push(int[],int&,int); void display(int[],int);
const int size=50;
void main() { clrscr(); char m,ch; int k,stack[size],item,top=-1,res; do
{
cout<<"\nChoose from the following : \n\n" <<"\n 1. Push" <<"\n 2. Pop" <<"\n 3. Display" <<"\n 4. Exit" <<"\n\nEnter your choice : ";
cin>>k;
switch(k) { case 1: ch='y'; while(ch=='y'||ch=='Y') {
cout<<"\nEnter the element : ";
cin>>item; res=push(stack,top,item); if(res==-1) {cout<<"\nOverflow !!!!"; exit(1); } cout<<"\nThe stack formed is : \n\n"; display(stack,top); cout<<"\n\n\nWant to enter again ?: "; cin>>ch; } break;
case 2: ch='y';
while(ch=='y'||ch=='Y') { res=pop(stack,top); if(res==-1) { cout<<"\nUnderflow !!!!"; exit(1); } else { cout<<"\nThe deleted Element is : "<>ch; } break;
case 3: cout<<"\nThe resultant stack is
: ";
display(stack,top); break;
case 4: exit(0); break;
default: cout<<"\nPlease enter desired keyword : ";
}
// end of switch
cout<<"\n\nChoose from the menu again ? : "; cin>>m;
Choose from the following : 1. Push 2. Pop 3. Display 4. Exit
Enter your choice : 1
Enter the element : 1 The stack formed is :
Want to enter again ?: y
Enter the element : 2 The stack formed is :
Want to enter again ?: y
Enter the element : 3 The stack formed is :
Want to enter again ?: y
Enter the element : 4 The stack formed is :
Want to enter again ?: N
Choose from the menu again ? : y
Choose from the following : 1. Push 2. Pop 3. Display 4. Exit
Enter your choice : 2 The deleted Element is : 4 The resultant stack is :
Want to delete again ? : y
The deleted Element is : 3 The resultant stack is :
Want to delete again ? : n
Choose from the menu again ? : y
Choose from the following : 1. Push 2. Pop 3. Display 4. Exit
Enter your choice : 3
The resultant stack is
:
2 1
Choose from the menu again ? : n
CONSTRUCTOR DESTRUCTOR Q1. Write a program using constructor and destructor to find the area of rectangle.
#include using namespace std;
// A class CRectArea with a constructor and descructor // to determine the area of a rectangle. class CRectArea { int *width, *height; public: CRectArea (int,int); ~CRectArea (); int areaofrect () { return (*width * *height); } };
// Constructor CRectArea::CRectArea (int x, int y) {
//Dynamically allocate some memory width = new int;
int main () { CRectArea myrectangle (2,2); cout << “The area of the rectangle is: ” << myrectangle.areaofrect() << endl; return 0; }
Q2.Define a class Outfit in C++ with the following descriptions : Private members :
OCode
Of type string
OType
Of type string
OSize
Of type integer
OFabric
Of type string
OPrice
Of type float
A function InitPrice( ) which calculates and assigns the values of OPrice as follows : For the value of OFabric “DENIM”, OType
OPrice(Rs)
TROUSER
1500
JACKET
2500
For fabric other than “DENIM” the above mentioned OPrice gets reduced by 25%.
Public members: • A constructor to assign initial values of OCode, OType and OFabric with the word “NOT INITIALISED” and OSize and OPrice with 0. • A function Input ( ) to input the values of the data members OCode, OType, OSize and OFabric and invoke the InitPrice( ) function. • A function Display ( ) which displays the content of all the data members for an Outfit.
Q3. Program defining a class TravelPlan with the given specifications and testing this class */ #include #include #include class TravelPlan
{ long PlanCode; char Place[25]; int Number_of_travellers; int Number_of_buses; public: TravelPlan()
{ PlanCode=1001; strcpy(Place,"Agra"); Number_of_travellers=5; Number_of_buses=1; } void NewPlan() { cout<<"Enter plancode"; cin>>PlanCode; cout<<"Enter place"; cin>>Place; cout<<"Enter number of travelers"; cin>>Number_of_travellers; int buses=0; if(Number_of_travellers<20) buses=1; else if(Number_of_travellers<40) buses=2; else if(Number_of_travellers>40) buses=3; Number_of_buses=buses; } void ShowPlan() { cout<<"Plancode:"<
cout<<"no. of travelers:"<
OUTPUT Enter plancode 1234 Enter place delhi Enter number of travelers 10 Plancode : 1234 Place :delhi No. of travelers : 10 No of buses :1
Q3. Write a program to print student details using constructors and destructors.
#include #include class stu { private: char name[20],add[20]; int roll,zip; public: stu ( );//Constructor ~stu( );//Destructor void read( ); void disp( ); }; stu :: stu( ) { cout<<”This is Student Details”<>name; cout<<”Enter the student roll no “; cin>>roll;
cout<<”Enter the student address”; cin>>add; cout<<”Enter the Zipcode”; cin>>zip; } void stu :: disp( ) { cout<<”Student Name :”<
is
:”<
cout<<”Address is
:”<
cout<<”Zipcode is
:”<
} stu : : ~stu( ) { cout<<”Student Detail is Closed”; }