Vous êtes sur la page 1sur 80

INDEX

Q-1 Write a program to Insert elements in an array (elements are in sorted order ).

Q- 2 Write a program using function to search an element in an array by linear search method.

Q- 3 Write a program using function to search an element in an array by binary search method.

Q-4 Write a program using function to sort the elements of array by using Insertion sort method.

Q-5 Write a program using function to sort the elements of array by using selection sort method.

Q-6 Write a program using function to produces third array c( which should be in ascending order) by merging two arrays A
and B (which are I ascending order).(AS,AS,AS)

Q-7 Write a program using function o print the upper hall of the given matrix, where matrix is given by the user.

Q- 8 Write a program using function which accepts a matrix and its prints the left diagonal elements.

Q- 9 Write a program using function which accepts an integer array and exchanges the values of first half side elements with
the second half side elements of the array.

Q-10 Write a program using function which accepts an array and its size and rearrange the array in such a way that the
values of alternate locations are exchanged.

Q- 11 Write a program in C++ using function \which accepts an integer array and its size as arguments and assign the
elements into two-dimensional array of integers in the following format:

Q- 12 Write a program using function to find the sum of elements each row of an integer matrix passed as an argument.

Q-13 Write an interactive menu driven Program to calculate:

Q-14 Write a program using classes.

Q- 15 Write an interactive menu driven program to implement stacks an (insert, delete and display),

Q-16 Queue as an array (Insert, Delete and Display).

Q-17 Insertion & deletion & Display.

Q- 18 Number of Characters.

Q- 19 Text File Creation

Q-20 Program to Created a Text File.

Q-21 Computing Problem


Submitted By : Tanisha Arora
𝐱𝟐 𝐱𝟒 𝐱𝟔
Q-22 Write a program to write the sum of the following series + 𝟒! + 𝟔! …
𝟐!

Q- 23 Declare a structure “employee” consists of fields empno, name, salary. Write a program to input records of 10 employees
& display data of all the employees getting salary more than 10000.

Q-24 Write a program to create a text file “text1.txt”.

Q-25 Write a program to count no. of words starting with "T" in a file “text1.txt”.

Submitted By : Tanisha Arora


Q-1 Write a program to Insert elements in an array (elements are in sorted order ).
#include<lostream.h>
#include<conio.h>
#include<process.h>
int findpos(inta[50],int,n,int index);
void main()
{
clrscr();
int a(50),item,n,index;
cout<<”\n enter the size of array:”;
cin<<n;
cout<<”\n enter array elements (must be sorted in asc.order)”;
for(int i=0;i<n;i++)
cin>>a(i);
char ch+’y’;
while(ch==’y’||ch==’y’)
{
cout<<”\n enter elements to be inserted:”;
cin>>item;
if(n==50)
{
cout<<”\n sorry||| element cannot be inserted (overflow)”;
exit(1);
{
if(a[i]<=item &item<a[i+1])
{
pos=i+1;
break;
}
}
if(==n-1)

Submitted By : Tanisha Arora


pos+n;
}
return pos;
}

Submitted By : Tanisha Arora


Q- 2 Write a program using function to search an element in an array by linear
search method.
#include<iostream.h>
#include<conio.h>
void lr_search();
void main()
{
clrscr();
lr-search();
getch();
}
void lr_search()
{
int a[10],n,i,num,pos,flag=0;
cout<<”\n enter the size of the array(number of elements):”;
cin>>n;
cout<<”\n enter the elements of the array in ascending order):”;
for(i=0;i>n;i++)
cin>>a(i);
cout<<”\n enter the elements to be searched in the array:”;
cin>>num;
for(i=0;i<n;i++)
if(a[i]==num)
{
flag+1;
}
Index+findpos(a,n,item);
for(i+n;i>index;i..)
{
a[i]=a[i-1];
}

Submitted By : Tanisha Arora


a[index]+item;
n+=1;
cout<<”\n do you want to insert more elements? (y/n)”;
cin>>ch;
}
cout<<”\n the array now is as shown below \n”;
for(i=0;i<n;i++)
cout<<a[i]<<” “;
cout<<”\n”;
getch();
}
int findpos(int a[],int,n,int item)
{
int pos;
if(item<a[0])
pos+0;
else
{
for(int i=0;i<n-1;i++)
pos+i;
braek;
}
if(flag==0)
cout<<”\n element not found”;
else
cout<<”\n element found at position:”>>pos+1;
}

Submitted By : Tanisha Arora


Q- 3 Write a program using function to search an element in an array by binary
search method.
#include<iostream.h>
#include<<conio.h>
int bsearch(int a[],int n,int item);
void main()
{
clrsr();
int a[50],item, index;
cout<<”\n enter array elements(must be sorted in asc.order):”;
for(int i=0;i<n;i++)
cin>>a[i];
cout<<”\n enter elements to be searched for in the array “;
cin>>item;
index+bsearch(a,n,item);
if(index==-1)
cout<<”\n elements is not present in the array’;
else
cout<<”\n elements is found at index:”<<index<<” and
position:”<<index+1;
getch();
}
int bsearch (int a[],int n, int item)
{

int beg,mid,last;
beg+0,last+n-1;
while(beg<+last)
{
mid+(beg+last)/2;
if(item==a[mid])

Submitted By : Tanisha Arora


return mid;
else if(item>a[mid])
beg+mid+1;
else
last+mid-1;
}
return-1;
}

Submitted By : Tanisha Arora


Q-4 Write a program using function to sort the elements of array by using
Insertion sort method.
#include<iostream.h>
#include<<conio.h>
void ins_sort(int a[],int n);
void main()
{
clscr();
int a[20],n,index,item;
cout<<”\n enter the size of array :”
cin>>n;
cout<<”\n enter array elements:”;
for(int i=1;i<n;i++)
cin>>a[i];
ns_sort(a,n);
cout<<”\n the sorted is as shown below:\n”;
for(i=1;i<=n;i++)
cout<<a[i]<<” “;
cout<<”\n”;
getch();
}
void ints_sort(inta[],int n)
{
int tmp,j,k;
for(int i=1;kni++)
{
tmp=a[i];
j=i-1;
while(tmp<a[i]&& j>=0)
{
a[j+1]=a[j];

Submitted By : Tanisha Arora


j..;
}
a[j+1]+tmp;
cout<<”\n array after pass .”<<|<<”is:”;
for(k=0;k<n;k++)
cout<<a[k]<<” “
cout<<”\n”;
}
}

Submitted By : Tanisha Arora


Q-5 Write a program using function to sort the elements of array by using
selection sort method.
#Include<iostream.h>
#include<coino.h>
void main()
{
clsrc();
int a[20],n;
cout<<”\n enter the size of array:”;
cin>>n;
cout<<”\n enter array elements:”;
for(int i=0;i<n;i++)
cin>>a[i];
sel_sort(a,n);
cout<<”\n the sorted array is as shown below:”;
for(i=0;i<ni++)
cout<<a[i]<<” “;
cout<<”\n”;
getch();
}
voidsel_sort(int a[],int,n)
{
int small,pos,tmp;
for(int i=0;i<(nn-1);i++)

{
small=a[i];
pos=i;
for(int j=i+1;j<n;j++)
{
if(a[j]<small)

Submitted By : Tanisha Arora


{
small=a[j];
pos=j;
}
}
tmp+a[i]
a[i]=a[pos];
a[pos]=tmp;
cout<<”\n array after pass,”<<+1<<”is:”;
for(j=0;j<n;j++)
cout<<a[j]<<” “;
}
}

Submitted By : Tanisha Arora


Q-6 Write a program using function to produces third array c( which should be in
ascending order) by merging two arrays A and B (which are I ascending
order).(AS,AS,AS)
#include<iostream.h>
#include<coino.h>
void merge(inta[],int m,int b[],int,n,intc[]);
void main()
{
clsrc();
int a[20],b[20],c[40],m,n;
cout<<”\n enter the size of first array ():”;
cin>>m;
cout<<”\n enter the elements of first array in ascending order:\”;
for(int i=0;i<m;i++)
cn>>a[i];
cout<<\n enter the size of second array [b]:”;
cin>>n;
cout<<”\n enter the elements of second array in ascending order :\n”;
for(i=0;i<n;i++)
cin>>b[i];
merge(a,m,b,n,c);
cout<<”\n the merged array © in ascending order is as shown below:\n”;
for(i=0;i<m+n;i++)
cout<<c[i]<<” “;
cout<<”\n”;
getch();
}
void merge(int aa[],int m, int b[],int n,int c[j]
{
int a,b,c;
for(a=0,b=0,c=0;a<m &&b>=0;)

Submitted By : Tanisha Arora


{
if(a[a]<=b[b])
c[c++]=a[a++];
else c[c++]=b[b++];
}
if(a<m)
{
while(a<m)
c[c++]=a[a++];
}
else
{
while(b>=0)
c[c++]=b[b++];
}
}

Submitted By : Tanisha Arora


Q-7 Write a program using function o print the upper hall of the given matrix,
where matrix is given by the user.
#include<iostream.h>
#include<conio.h>
void upper_half(int a[3]3],int n);
void main()
{
clrscr();
int a[3][3],n,i,j;
cout<<”\n enter he elements for the squarer matrix:”;
cin>>n;
cout<<\n enter the elements of the matrix:”;
for(i=0;i<n;i++)
{
for(j=0;i<n;i++)
{
for(j=0;j<n;j++)
cin>>a[i][j];
}
cout<<”\n the matrix is :”;
for(i=0;i<n;i++)
{
cout<<”\n”;
for(j=0;j<n;j++)
cout<<a[i][j]<<” “;
}
upper_half(a,n);
getch();
}
void upper_half(int a[3][3],int n)
{

Submitted By : Tanisha Arora


inti,j;
cout<<’\n the upper half of the matrix is :”;
for(i=0;i<n;i++)
{
cout<<”\n”;
for(j=0;j<n;j++)
{
if(i<=j)
cout<<a[i][j]<<” “;
else
cout<<” “;
}
}
}

Submitted By : Tanisha Arora


Q- 8 write a program using function which accepts a matrix and its prints the left
diagonal elements.
#include<iostream.h>
#include<conio.h>
void left_diag(int [3][3],int n, int m);
void main()
{
clrscr();
int a[3][3],n,m,i,j;
cout<<”\n enter the number of rows and columns of the matrix :”;
cin>>m>>n;
cout<<”\n enter the elements of the matrix:”;
for(i=0;i<m;i++)
{
for(j=0;)<n;j++)
cin>>a[1][j];
}
left_diag(a,m,n);
getch();
}
vold left_diag(inta[1][3],int n,int m)
{
int i,j;]
for(i=o;l<m;l++)
{
cout<<”\n”;
for(j=0;j<n;j++)
{
if(i==j)
cout<<a[i][j];
else

Submitted By : Tanisha Arora


cout<<” ”;
}
}
}

Submitted By : Tanisha Arora


Q- 9 Write a program using function which accepts an integer array and
exchanges the values of first half side elements with the second half side
elements of the array.
For eg: if the array is 2,4,1,6,7,9,23,10
Output: 7,9,23,10,2,4,1,6.
#include<iostream.h>
#include<conio.h>
void swap(int a[10],int n);
void main()
{
clrscr();
int a[10],n,i;
cout <<”\n enter the size of array:”;
cin>>n;
cout<<”\n enter the elements of the array:”;
for(i=0;i<n;i++)
cin>>a[i];
swap(a,n);
cout<<”\n the updated array is :\n”;
for(i=0;n;i++)
cout<<a[i]<<” ” ;
getch();
}
void swap(inta[],intn)
{
inti,j,tmp,mid=(n/2);
if(n%2==0)
j=mid;
else
j=mid+1;
for(i=0;i<mid;i++,j++)

Submitted By : Tanisha Arora


{
tmp=a[i]
a[i]=a[j];
a[i]=atmp ;
}
}

Submitted By : Tanisha Arora


Q-10 Write a program using function which accepts an array and its size and
rearrange the array in such a way that the values of alternate locations are
exchanged.
For eg: 2,5,9,14,8,19,16,
Output: 5,2,14,9,19,8,16.

#include<iostream.h>
#include<conio.h>
void swap(int a[3],int n);
void main()
{
clrscr();
int a[3],n,i;
cout<<”|n enter the size of array:”;
cin>>n;
cout<<”\n enter the elements of array :” ;
for(i=0;i<n;i++)
cin>>a[i];
swap(a,n);
getch();
}
void swap(int a[3],int n)
{
int i,j,tmp;
for(i=0;i<n;i+=2)
{
j=i+1;
tmp=a[i];
a[i]=a[j];
a[j]=tmp;
}

Submitted By : Tanisha Arora


cout<<”\n the updates\d array is : ”;
for(i=0;i<n;i++)
cout<<a[i]<<” ”;
cout<<\n”;
}

Submitted By : Tanisha Arora


Q- 11 Write a program in C++ using function \which accepts an integer array and
its size as arguments and assign the elements into two-dimensional array of
integers in the following format:
For eg: If the array is 1,2,3,
Output: 1 2 3
120
100

#include<iostream.h>
#include<coino.h>
void fun(int A[10],int m);
void main()
{
clrscr();
int A[10],n;
cout<<”\n Enter the size of array :”;
cin >>n;
cout<<”\n Enter the elements of the array:”;
for(int i=o;i<n;i++)
cin>>A[i];
fun(A,n);
getch();
}
void fun(int A[10],int n)
{
Int A2[20][20],I,j;
Cout<<”\n the 2-D form of the array is :\n;
for(i=0<n;i++)
{
for(j=0;j<nj++)
{

Submitted By : Tanisha Arora


if((i+j)>=n)
A2[i][j]=0;
else
A2[i][j]=A[j];
cout<<A2[i][j]<<” ”;
}
cout<<”\n”;
}
}

Submitted By : Tanisha Arora


Q- 12 Write a program using function to find the sum of elements each row of an
integer matrix passed as an argument.
For eg: if the matrix is 1 2 3
456
Output: sum of Row 1=6
Sum of Row 2= 15

#include<iostream.h>
#include<<conio.h>
void sum(int a[10][10],int m,int n);
void main()
{
clrscr():
int a[10][10],n,m,i,j;
cout<<”\n enter the number row and columns of the matrix:’;
cin>>m>>n;
cout<<”\n enter the elements of the matrix:”;
for(i=0;<m;i++)
{
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cin>>a[i][i];
}
cout<<”\n the matric\x is:”;
for(i=0;i<m;i++)
{

cout<<”\n”;

for(j=0;j<m;j++)

Submitted By : Tanisha Arora


cout<<a[i][j]<<” ”;
}
sum (a,m,n);
getch();
}

viod sum(int a[10][10],int m,int n)


{
int pro[10];
for(int i=0;i<m;i++)
{
p[i]=0;
for(int j=0;j<n;j++)
pro[i]+a[i][j];
cout<<”\n sum of row “<<i+1<<”is : “<< pro[i]<<”\n”;
}
}

Submitted By : Tanisha Arora


Q-13 Write an interactive menu driven Program to calculate :
No of students passed with distinction
No of student felled . (assume 40 % as passing marks )
Details of the topper.
Define a structure student (rollno, name, marks in three subjects) to store
information of student’s result8

#include<iostream.h>
#include<conio.h>
struct stu
{
int rno;
flot m1,m2,m3;
};
Stu s[50],t1.t2;
void main()
}
clrscr();
int n;
int ndist=0,p=0;
float top1=0,p=0;
cout<<\n enter the number of students: “;
cin>>n;
for (inti=0;i<n;i++)
{
cout<<”\n enter rollno : ” ;
cin>>s[i].rno;
cout <<”n\ Enter marks in three subjects: ”;
cin>>s[i].m1>>s[1].m2>>s[i].m3;
}
for(i=0;i<n;i++)

Submitted By : Tanisha Arora


{
p=(s[i].m1+s[i].m2+s[i].m3)/3;
if(p<40)
nfail++;
else
if(p>25)
ndist++;
if(top1<p)
{
top1=p;
}
}
int ch;
do
{
cout<<”\n menu :”;
cout<<”\n 1. No of Students passed with distinction.”;
cout<<”\n 2. No of students failed. ”;
cout<<”\n 3. Detalls of the topper.”;
cout<<”\n 4. Exit. ”;
cout<<”\n Enter your choice: ”;
cin>>ch;
switch(ch)
{
case 1:
cout<<”\n No of Students passed with distinction :”<<ndist;
break;
case 3:
cout<<”\n Details of the topper are:”;
cout<<”\n Roll no :”<<t1.rno;
cout<<”\n Percentage :”<<top1;

Submitted By : Tanisha Arora


break;
case 4:
exit(0);
default :
coult<<\n you entered wrong choice.”;
};
}
while(ch>0& ch<4);
getch();
}

Submitted By : Tanisha Arora


Q-14 Write a program using classes and objects to simulate result preparation
system for 4 students. The data available for each student includes rollno,name
and marks in 3 subjects includes rollno, name and marks in 3 subjects. The
percentage ,arks and grade are be calculated from the above information . the
percentage marks are the average marks and the grade is to be calculated as
follows :
When percentage marks (<50), grade is ‘F’
When percentage marks (>=50 and <60), grade is ‘D’
When percentage marks (<=60 and <75), grade is ;B’
When percentage marks I>=90 and <100),grade is ‘A’.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
const int obj=4;
const int n=3;
class student
{
intg rno;
char name[20];
float Marks[n];
float per;
char grade;
public;
vold getval();
vold calculate();
vold prnresult();
};
else
if(per<75)
grade=’c’;

Submitted By : Tanisha Arora


else
if(per<90)
grade=’B’
else
grade=’A’;
}
void student::prnresult()
{
cout<<\n’;
cout<<”Roll Number:”<<no<<”\n”;
cout<<”Name :”;
cout<<write(name,20);
cout<<”\n”;
cout<<”Marks in subject 1: “<<Marks [0] <<\n”;
cout<<”Marks in subject 2: ‘<<Marks [1]<<”\n”;
cout<<”Marks in subject 3 ‘<<Marks [2]<<”\n”;
cout<<”Total Marks :”<< (marks[0]+marks[1]+Marks[2])<<”\n”;
cout”Grade :”<< grade<<”\n”;
cout<<”\n”;
}
student std[obj];
void main()
{
clrscr();
int i=0;
for(i=0;i<obj;i++)
{
cout<<”Student”<<(i+1)<<”\n”;
std[i].getval();
}
for(i=o;i<ob;i++)

Submitted By : Tanisha Arora


{
std[i].calculate();
cout<<”result of student” <<(i+1)<<”\n”
std[i].prnresult();
}
getch()
}

Submitted By : Tanisha Arora


Q- 15 Write an interactive menu driven program to implement stacks an (insert,
delete and display), when top is at-1 initially.

#include<iostream.h>
#include<conio.h
#include<process.h>
constint size=20;
class stack
{
int stack [size];
int top;
public;
stack()
{

top=-1;
}
int push(int item);
int pop();
void display();
};
int stack:: push (int item)
{
if(top==size-1)
return-1;
else
{
top++;
stack[top]=ite,;
}
retum 0;

Submitted By : Tanisha Arora


}
int stack :: pop()
{
int ret;
if(top==-1)
return-1;
else
{
ret=stack[top];
top--;
}
void stack:: display()
{
if(top==-1)
cout<<”\n stack is empty (underflow)”;
else
{
cout<<stack[top]<<”<-“<<”\n”;
for(int i=top-1;i>=0;1--)
cout<<stack[i]<<”\n\;
}
}
void main()
{
clrscr();
stack st;
int ret,ch,ltem;
do
{
cout<<”\n menu:”;
cout<<”\n 1.push.”;

Submitted By : Tanisha Arora


cout<<”\n 2.pop.” ;
cout<<”\n 3. display.”;
cout<<”\n 4.exit.” ;
cout<<”\n enter your choice(1-4):”;
cin>>ch;
switch(ch)
{
case 1;
cout<<”\n enter element to be added :”;
cin>>item;
ret>>st.push(item);
if(ret==-1)
cout<<”\n overflow,”;
else
if(ret==o)
cout<<”\n element is added successfully.”;
break;
case 2:
ret=st.pop();
if(ret==-1)
cout<<”\n stack is empty.”;
else
cout<<”\n the deleted element: is: “ <<ret;
break;
case 3;
st.display();
break;
case 4:
exit(o);
default :
cout<<”\n you entered wrong choice. “;

Submitted By : Tanisha Arora


};
}
while(ch>0);
getch();
}

Submitted By : Tanisha Arora


Q-16 Queue as an array (Insert, Delete and Display).
#include<iostream.h>
#include<conio.h>
#include<process.h>
const int size=20;
class queue
{
intque[size];
int front,rear;
public;
queue();
int ins_ele(int);
int del();
void display();
};
queue::queue()
{
front,rear=-1;
}
int queue :: ins_ele(ent item)
{
if(rear==size-1)
return -1;
else
if(rear==-1)
{
front=rear=0;
que[rear]=item;
}
else
{

Submitted By : Tanisha Arora


rear++;
que[rear]=item;
}
return 0;
}
int queue ::del()
{
int ret;
if(front==-1)
return -1;
else
{
ret=que[front];
if(front==rear)
front=rear=-1;
else
front++;
}
return ret;
}
void queue :: display()
{
if(front==-1)
cout<<”\ The queue is empty (underflow).”;
else
for(int i=front;i<rear;i++)
cout<<que[i]<<”<-“;
cout<<que[rear];
}
void main()
{

Submitted By : Tanisha Arora


clrscr();
int item;
int ch,res;
queue q;
do
{
cout<<”\n MANU :’;
cout<<”\n 1. INSERTION. “;
cout<<”\n 2. DELETION. “;
cout<<”\n 3. DISPLAY. “;
cout<<”\n 4. EXIT. “;
cout<<”\n Enter your choice :”;
cin>>ch;
switch(ch)
{
case 1:
cout<<”\n Enter item to be inserted : “;
cin>>item;
res=q.ins_ele(item);
if(res==-1)
cout<<”\n Queue is full (Overflow). “;
else
cout<<”\n Element is inserted successfully. “;
break;
case 2:
res=q.del();
if(res==-1)
cout<<”\n Queue is empty (Underflow). “;
else
break;
case 3:

Submitted By : Tanisha Arora


q.display();
break;
exit(0);
default:
cout<<”\n You entered wrond choice. “;
break;
};
}
while(ch>0);
getch();
}

Submitted By : Tanisha Arora


(E) STACK/QUEUES AS LINKED LIST
Q-17 Insertion & deletion & Display.

#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
clrscr();
int ch,i,top=-1,stack[5];
x:
cout<<endl<<endl;
cout<<"Enter Choice 1> Insert 2> Delete 3>exit "<<endl;
cin>>ch;
switch(ch)
{
case 1:
top++;
if(top<=4)
{
cout<<"Enter The Element"<<endl;
cin>>stack[top];
cout<<"The Stack is"<<endl;
for(i=0;i<=top;i++)
cout<<stack[i];
goto x;
}
else
{
cout<<" ************* Stack OVERFLOW ********** "<<endl;
goto x;}

Submitted By : Tanisha Arora


case 2:
if(top>=0)
{
top--;
cout<<"Stack is"<<endl;
for(i=0;i<=top;i++)
cout<<stack[i];
goto x;
}
else
{
cout<<"************** Stack UNDER FLOW ***********"<<endl;
goto x;
}

case 3:
exit(0);
default :
cout<<"WRONG CHOICE !!!!!!!!!!! "<<endl;
goto x;
}
}

Submitted By : Tanisha Arora


Q- 18 Number of Characters.
#include <stdio.h>

int main()

printf ("Characters: %c %c \n", 'a', 65);

printf ("Decimals: %d %ld\n", 1977, 650000L);

printf ("Preceding with blanks: %10d \n", 1977);

printf ("Preceding with zeros: %010d \n", 1977);

printf ("Some different radices: %d %x %o %#x %#o \n", 100, 100, 100, 100,
100);

printf ("floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416);

printf ("Width trick: %*d \n", 5, 10);

printf ("%s \n", "A string");

return 0;

Submitted By : Tanisha Arora


Q-19 Program to Created a Text File.

#include<fstream.h>

#include<conio.h>

void main()

clrscr();

ofsteam f;

f.open(“New.text”);

char ch [80],ch1;

do

cout<<”enter any line”;

gets(ch);

f<<ch;

cout<<”\n enter (y/n) to write more”;

cin>>ch1;

while(ch1==‘y’||ch==’Y’);

f.close();

Submitted By : Tanisha Arora


Q-20 Computing Problem
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x,i,f,r,b,g,c,h,v=1,q,j,n,p,k=1;
int ch;
cout<<"Enter choice 1:STARS"<<endl;
cout<<" 2:NUMBERS"<<endl;
cin>>ch;
switch(ch)
{
//WITH STAR
case 1:
v=2;
char a2[100][100];
cout<<"Enter Limit : "<<endl;
cin>>n;
p=n-1;
//INPUTTINGfor(i=0;i<=(2*n)-2;i++)
{

for(j=0;j<=(2*n)-2;j++)
{
a2[i][j]= ' ';
}
}
//STARTING
for(i=0;i<=(2*n)-2;i++)
{

Submitted By : Tanisha Arora


for(j=0;j<=(2*n)-2;j++)
{
if(((i+j)==p)&&(i<n))
{
for(c=0;c<k;c++)
{
a2[i][j]='*';
j=j+v;
}
k++;
j=(2*n)-2;
r=c-1;
}
if(((i+j)==(p+2))&&(i>=n))
{
for(h=r;h>0;h--)
{
a2[i][j]='*';
j=j+v;
}
p=p+2;
r--;
j=(2*n)-2;
}
}
}
for(i=0;i<=(2*n)-2;i++)
{
cout<<endl;
for(j=0;j<=(2*n)-2;j++)
{

Submitted By : Tanisha Arora


cout<<a2[i][j];
}
}
break;
//CASE TWO WITH NUMBERS
case 2:
int a[100][100];
cout<<"Enter Limit : "<<endl;
cin>>n;
p=n-1;
for(i=0;i<=(2*n)-2;i++)
{
for(j=0;j<=(2*n)-2;j++)
{
a[i][j]=0;
}
}
for(i=0;i<=(2*n)-2;i++)
{
for(j=0;j<=(2*n)-2;j++)
{
if(((i+j)==p)&&(i<n))
{
b=1;
for(c=0;c<k;c++)
{
if(j<=(n-1))
{
a[i][j]=b;
j=j+v;
b++;

Submitted By : Tanisha Arora


r=b-2;
}
if(j>(n-1))
{
a[i][j]=r;
j=j+v;
r--;
}
}
k=k+2;
j=(2*n)-2;
r=c-2;
}
if(((i+j)==p+2)&&(i>=n))
{
f=1;
for(h=r;h>0;h--)
{
if(j<=(n-1))
{
a[i][j]=f;
j=j+v;
f++;
x=f-2;
}
if(j>(n-1))
{
a[i][j]=x;
j=j+v;
x--;
}

Submitted By : Tanisha Arora


}
r=r-2;
p=p+2;
j=(2*n)-2;
}
}
}
for(i=0;i<=(2*n)-2;i++)
{
cout<<endl;
for(j=0;j<=(2*n)-2;j++)
{
if(a[i][j]!=0)
cout<<a[i][j];
else
cout<<" ";
}
}
break;
default:
cout<<"Wrong choice"<<endl;
break;
}
getch();
}

Submitted By : Tanisha Arora


𝒙𝟐 𝒙𝟒 𝒙𝟔
Q-21 Write a program to write the sum of the following series + + …
𝟐! 𝟒! 𝟔!

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,x,n;
double sum=0,term=1;
cout<<"\nEnter the no of terms : ";
cin>>n;
cout<<"\nEnter the value of x : ";
cin>>x;
for(i=1;i<=n;i++)
{ term=term*x*x/((2*i)*(2*i-1));
sum=sum+term;
}
cout<<"\nThe sum of the series is :"<<sum;
getch();
}

Submitted By : Tanisha Arora


Q- 22 Declare a structure “employee” consists of fields empno, name, salary.
Write a program to input records of 10 employees & display data of all the
employees getting salary more than 10000.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct employee
{
int empno;
char name[20];
float salary;
};
void main()
{
clrscr();
employee e[10];
cout<<"Enter records of 10 Employees\n\n";
for(int i=0;i<10;i++)
{
cout<<"\nEnter record of employee number "<<i+1<<"\n\n";
cout<<"\nEnter Employee number : ";
cin>>e[i].empno;
cout<<"\nEnter Name : ";
gets(e[i].name);
cout<<"\nEnter Salary : ";
cin>>e[i].salary;
}
clrscr();
cout<<"Record of those employees whose salary is more than 10000 is
as follows\n\n”;
for(i=0;i<10;i++)
if(e[i].salary>10000)
{
cout<<"\nEmployee number is :";
cout<<e[i].empno;
Submitted By : Tanisha Arora
cout<<"\nName is :";
cout<<e[i].name;
cout<<"\nSalary is :";
cout<<e[i].salary;
}
getch();
clrscr();
cout<<"\t\t\t\n\n\n\n\n\n\nThat's all !!!!!!!!!";
getch();
}

Submitted By : Tanisha Arora


Q-23 Write a program to create a text file “text1.txt”.

#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<dos.h>
void main()
{
clrscr();
ofstream f("text1.txt",ios::app);
char ch[80],c;
do{
cout<<"\nEnter the info in file:-\n";
gets(ch);
f<<ch<<"\n";
cout<<"\nWant to enter more info ?(Y/N) : ";
cin>>c;
}while(c=='y'||c=='Y');
cout<<"\n\n\t\tProcessing!!!Please Wait!!!";
delay(3000);
clrscr();
cout<<"\n\t\tFile successfully created, modified & saved!!!!!!";
f.close();
getch();
}

Submitted By : Tanisha Arora


Q-24 Write a program to count uppercase & lowercase letters present in afile
“text1.txt”.

#include<fstream.h>
#include<ctype.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
void main()
{
clrscr();
ifstream f("text1.txt");
char ch;
int c=0,d=0;
if(!f)
{
cout<<"\nFile Absent\n";
getch();
exit(0);
}

while(!f.eof())
{
f.get(ch);
if(isupper (ch))
c++;
else
d++;
}
f.close();
cout<<"\nNumber of Uppercase alphabets in the file Text1.txt : "<<c;
cout<<"\nNumber of lowercase alphabets in the file Text1.txt : "<<d;
getch();
}
Submitted By : Tanisha Arora
Q-25 Write a program to count no. of words starting with "T" in a file
“text1.txt”.
#include<fstream.h>
#include<dos.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<ctype.h>
void main()
{
clrscr();
ifstream f1("text1.txt");
char ch[80];
int count=0;
if(!f1)
{
cout<<"\nFile is absent\n";
getch();
exit(0);
}
while(!f1.eof())
{
f1>>ch;

if(ch[0]=='T')
{
count++;
}}
cout<<"\nCounting....Please Wait!!!";
delay(3000);
clrscr();
cout<<"\nTotal number of words starting with 'T' is "<<count;
f1.close();
getch();
}
Submitted By : Tanisha Arora
OUTPUT (1)

Enter the size of array : 10

Enter array elements(must be sorted in ace. Order)11


14
17
22
37
58
60
67
78
88

Enter element to be inserted : 12

Do you want to insert more element ? (y/n) y

Enter element to be inserted : 1

Do you want to insert more element ? (y/n) n

The array now is as show below


1 11 12 14 17 22 37 58 60 67 78 88

Submitted By : Tanisha Arora


OUTPUT (2)

Enter the size of the array(number of elements) : 10

Enter the elements of the array (in ascending order) : 11


11
55
67
77
60
61
65
90
100

Enter the element to be searched in the array : 77

Element found at position : 5_

Submitted By : Tanisha Arora


OUTPUT (3)

Enter the size of the array(max. 50) : 8

Enter array elements(must be sorted in asc. Order) : 11


15
20
30
40
50
60
90

Enter elements to be searched for in the array 40

Enter is found at index : 4 and position : 5

Submitted By : Tanisha Arora


OUTPUT (4)

Enter the size of array : 8

Enter array elements : 11


23
54
6
19
8
65
4
Array after pass – 1 is : 11 23 54 6 19 8 65 4
Array after pass – 2 is : 11 23 54 6 19 8 65 4
Array after pass – 3 is : 6 11 23 54 19 8 65 4
Array after pass – 4 is : 6 11 19 23 54 8 65 4
Array after pass – 5 is : 6 8 11 19 23 54 65 4
Array after pass – 6 is : 6 8 11 19 23 54 65 4
Array after pass – 7 is : 4 6 8 11 19 23 54 65

The sorted array is as show below :


4 6 8 11 19 23 54 65

Submitted By : Tanisha Arora


OUTPUT (5)

Enter the size of array : 7

Enter array elements : 11 4 6 32 9 1 45

Array after pass – 1 is : 1 4 6 32 9 11 45


Array after pass – 2 is : 1 4 6 32 9 11 45
Array after pass – 3 is : 1 4 6 32 9 11 45
Array after pass – 4 is : 1 4 6 9 32 11 45
Array after pass – 5 is : 1 4 6 9 11 32 45
Array after pass – 6 is : 1 4 6 9 11 32 45
The sorted array is as show below : 1 4 6 9 11 32 45

Submitted By : Tanisha Arora


OUTPUT (6)

Enter the size of first (A) : 4

Enter the elements of first array in ascending order:


10 12 13 14

Enter the size of second array (B) : 6

Enter the elements of second array in ascending order:


2 4 5 6 7 8

The merged array (C) in ascending order is as show below:


2 4 5 6 7 8 10 12 13 14

Submitted By : Tanisha Arora


OUTPUT (7)

Enter the dimension for the square matrix : 3

Enter the elements of the matrix : 1 2 3 4 5 6 7 8 9

The matrix is :
1 2 3
4 5 6
7 8 9
The upper half of the matrix is :
1 2 3
5 6
9_

Submitted By : Tanisha Arora


OUTPUT (8)

Enter the number of rows and columns of the matrix : 3 3

Enter the elements of the matrix : 1 2 3 4 5 6 7 8 9

Left diagonal is :
1
5
9_

Submitted By : Tanisha Arora


OUTPUT (9)

Enter the size of array : 10

Enter the element of the array : 11 11 11 11 11 12 12 12 12 12

The updated array is :

12 12 12 12 12 11 11 11 11 11

Submitted By : Tanisha Arora


OUTPUT (10)

Enter the size of array : 10

Enter the element of the array : 11 12 13 14 15 16 17 18 19 20

The updated array is : 12 11 14 13 16 15 18 17 20 19

Submitted By : Tanisha Arora


OUTPUT (11)

Enter the size of array : 5


Enter the element of the array : 11 12 13 14 15
The 2-D form of the array is :
11 12 13 14 15
11 12 13 14 0
11 12 13 0 0
11 12 0 0 0
11 0 0 0 0

Submitted By : Tanisha Arora


OUTPUT (12)

Enter the number of row and colums of the matrix : 3 3


Enter the element of the matrix : 1 2 3 4 5 6 7 8 9
The Matrix is :
1 2 3
4 5 6
7 8 9
Sum of row 1 is : 6
Sum of row 2 is : 15
Sum of row 3 is : 24

Submitted By : Tanisha Arora


OUTPUT (13)

Enter the number of students : 3


Enter roll no : 11
Enter marks in there subjects : 23 23 34
Enter roll no : 12
Enter marks in there subjects : 56 56 56
Enter roll no : 13
Enter marks in there subjects : 87 68 89

Menu :
1. No of students passed with distinction.
2. No of students failed.
3. Details of the topper.
4. Exit
Enter your choice : 3
Details of the topper are :
Roll No. 12
Marks : 56 56 56
Percentage : 56
Menu :
1. No of students passed with distinction.
2. No of students failed.
3. Details of the topper.
4. Exit

Submitted By : Tanisha Arora


OUTPUT (14)

Student 1

Enter data
Roll No. : 11

Name : Meenakshi

Marks for subject 1 : 76

Marks for subject 2 : 87

Marks for subject 3 : 77

Submitted By : Tanisha Arora


OUTPUT (15)
1. PUSH
2. POP
3. DISPLAY
4. EXIT
Enter your choice (1-4) : 1

Enter element to be added : 10

Element is added successfully.

Submitted By : Tanisha Arora


OUTPUT (16)

1. INSERTION
2. DELETION
3. DISPLAY
4. EXIT
Enter your choice (1-4) : 1

Enter element to be added : 15

Element is added successfully.

Submitted By : Tanisha Arora


OUTPUT (17)

Submitted By : Tanisha Arora


OUTPUT (18)

Characters: a A
Decimals: 1977 650000
Preceding with blanks: 1977
Preceding with zeros: 0000001977
Some different radices: 100 64 144 0x64 0144
floats: 3.14 +3e+000 3.141600E+000
Width trick: 10
A string

Submitted By : Tanisha Arora


OUTPUT (19)

enter any line


arjit rastogi

enter (y/n) to write more


n
__________________________
Process exited after 8.218 seconds with return value 0
Process any key to continue . . . _

Submitted By : Tanisha Arora


OUTPUT (20)

Submitted By : Tanisha Arora


OUTPUT (21)

Submitted By : Tanisha Arora


OUTPUT (22)

Submitted By : Tanisha Arora


OUTPUT (23)

Submitted By : Tanisha Arora


OUTPUT (24)

Submitted By : Tanisha Arora


OUTPUT (25)

Submitted By : Tanisha Arora

Vous aimerez peut-être aussi