0% found this document useful (0 votes)
64 views

Computer Practical File: Submitted By: Rohan Pradhan Class: Xii A

The document contains 10 programming problems and their solutions in C++. The problems cover topics like inputting and displaying multiples of a number, checking if a number corresponds to a day of the week, calculating surface areas and volumes of shapes, string manipulation, arrays, matrices, checking palindromes, and function overloading. For each problem, the code to solve it is provided along with an expected output. The document appears to be a computer practical submission containing solutions to various basic programming exercises.

Uploaded by

Nikhar Pradhan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Computer Practical File: Submitted By: Rohan Pradhan Class: Xii A

The document contains 10 programming problems and their solutions in C++. The problems cover topics like inputting and displaying multiples of a number, checking if a number corresponds to a day of the week, calculating surface areas and volumes of shapes, string manipulation, arrays, matrices, checking palindromes, and function overloading. For each problem, the code to solve it is provided along with an expected output. The document appears to be a computer practical submission containing solutions to various basic programming exercises.

Uploaded by

Nikhar Pradhan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 42

COMPUTER PRACTICAL

FILE

SUBMITTED BY: ROHAN PRADHAN


CLASS: XII A
SUBMITTED TO: Mr. Sunil Jangra
Roll No.: 16

1. Write a program to input two numbers m and n and display first m multiples of n.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int m,n;
cout<<"enter the base number:";
cin>>n;
cout<<"enter the no. of multiples you want:";
cin>>m;
cout<<"The multiples are:"<<endl;
for(int i=1;i<=m;i++)
{
cout<<(n*i)<<endl;
}
getch();
}
OUTPUT:
2. Write a program to input day number of a week and display the corresponding day name.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
cout<<"Enter the day number:" ;
cin>>a;
switch(a)
{
case 1:
cout<<"the day is:"<<"\t"<<"Monday";break;
case 2:
cout<<"the day is:"<<"\t"<<"Tuesday";break;
case 3:
cout<<"the day is:"<<"\t"<<"Wednesday";break;
case 4:
cout<<"the day is:"<<"\t"<<"Thursday";break;
case 5:
cout<<"the day is:"<<"\t"<<"Friday";break;
case 6:
cout<<"the day is:"<<"\t"<<"Saturday";break;
case 7:
cout<<"the day is:"<<"\t"<<"Sunday";break;
default:
cout<<"Invalid number.";
}
getch();
}
OUTPUT:

3. Write a menu driven program to calculate the total surface area and volume of a cube,
cuboid, or cylinder depending upon user’s choice.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d,e,f,g;
cout<<"****WELCOME****"<<endl;
cout<<"The choices are:"<<endl;
cout<<"1.CUBE"<<endl<<"2.CUBOID"<<endl<<"3.CYLINDER"<<endl;
cout<<"Enter your choice: ";
cin>>a;
if(a==1)
{
cout<<"Enter the length of side of cube: ";
cin>>b;
cout<<"the surface area is = "<<(6*b*b)<<endl;
cout<<"the volume is = "<<(b*b*b);
}
else if(a==2)
{
cout<<"Enter the length of cuboid: ";
cin>>c;
cout<<"Enter the breadth of the cuboid: ";
cin>>d;
cout<<"Enter the height of the cuboid: ";
cin>>e;
cout<<"the surface area is = "<<(6*c*d*e)<<endl;
cout<<"the volume is = "<<(c*d*e);
}
else if(a==3)
{
cout<<"enter the length of the cylinder: " ;
cin>>f;
cout<<"enter the radius of cylinder: ";
cin>>g;
cout<<"the surface area of cylinder is= "<<(2*(22/7)*g*f);
cout<<"\n"<<"the volume of cylinder is= "<<((22/7)*g*g*f);
}
else
cout<<"Invalid choice.";
getch();
}
OUTPUT:

4. Write a program to read a string and print out the following:


 No. of capital alphabets.
 No. of small alphabets.
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main()
{
clrscr();
int c=0,s=0,m;
char str[100];
cout<<"enter the no. of alphabets in string:";
cin>>m;
cout<<"Enter the string(max=100):"<<endl;
for(int i=0;i<m;i++)
{
cin>>str[i];
if(islower(str[i]))
s++;
else if(isupper(str[i]))
c++;
}
cout<<"The no. of capital alphabets = "<<c<<endl;
cout<<"The no. of small alphabets = "<<s;
getch();
}
OUTPUT:
5. Write a program to read a string and print it after replacing each of its capital alphabets by
the corresponding small alphabet and each small alphabet by its corresponding capital
alphabet.
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main()
{
clrscr();
char str[100];
int a;
cout<<"Enter the no. of alphabets in string(max-100): ";
cin>>a;
cout<<"Enter the string: "<<endl;
for(int i=0;i<a;i++)
{
cin>>str[i];
if(islower(str[i]))
str[i]=toupper(str[i]);
else if(isupper(str[i]))
str[i]=tolower(str[i]);
}
cout<<"The new string is: "<<endl;
for(i=0;i<a;i++)
{
cout<<str[i];
}
getch();
}
OUTPUT:

6. Write a program to input 10 elements in an array and then display these elements in
reverse order.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int ar[10];
cout<<"Enter the array elements: ";
for(int i=0;i<10;i++)
{
cin>>ar[i];
}
cout<<"\n"<<"The reversed order is: ";
for(i=9;i>=0;i--)
{
cout<<ar[i]<<" ";
}
getch();
}
OUTPUT:
7. Write a program to input elements in a 2-D array and then print the sum of the main
diagonal elements of this array.
#include<iostream.h>
#include<conio.h>
void main()
{
int m,n,b=0;
clrscr();
int a[50][50];
cout<<"Enter the no. of rows in array(max-50): ";
cin>>m;
cout<<"Enter the no. of columns in array(max-50): ";
cin>>n;
cout<<"Enter the array: "<<endl;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cin>>a[i][j];
}
cout<<endl;
}
cout<<"The sum of the main diagonl elements is: ";
for(i=0;i<m;i++)
b=(b+a[i][i]);
cout<<b;
getch();
}
OUTPUT:

8. Write a program to check whether the given string is palindrome or not.


#include <iostream>
#include <string.h>
#include<conio.h>
int main()
{ clrscr();
char str1[10],str2[10],c;

do
{
cout<<"\nENTER A STRING: ";
cin>>str1;

strcpy(str2,str1);

strrev(str1);

if(strcmp(str1,str2)==0) //compares str1 and str2


cout<<"GIVEN STRING IS PALINDROME";
else
cout<<"GIVEN STRING IS NOT PALINDROME";

cout<<"\n\nDO YOU WISH TO CONTINUE (Y/N)? ";


cin>>c;

}while(c=='y'||c=='Y');

return 0;
}
OUTPUT:
9. Write a program to input two matrices, find their sum, difference, or product depending
upon user’s choice, and then display the resultant matrix along with the original matrices.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[50][50],c[50][50],m,n,b,x,y,d[50][50],z,i,j;
int e[50][50],f[50][50];
char g;
do
{
cout<<"******WELCOME******"<<endl;
cout<<"OPTIONS: "<<endl;
cout<<"1. Sum"<<endl<<"2. Product"<<endl<<"3. Difference";
cout<<"\n"<<"Enter your choice: ";
cin>>b;
cout<<"\n"<<"Enter the no. of rows of matrix 1: ";
cin>>m;
cout<<"\n"<<"Enter the no. of columns of matrix 1: ";
cin>>n;
cout<<"\n"<<"Enter the no. of rows of matrix 2: ";
cin>>x;
cout<<"\n"<<"Enter the no. of columns of matrix 2: ";
cin>>y;
if(b==1)
{
if((m==x)&&(n==y))
{
cout<<"Enter the matrix 1:"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cin>>a[i][j];
}
cout<<"\n"<<"The matrix 1 is: "<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<a[i][j];
cout<<" ";
}
cout<<"\n";
}
cout<<"\n"<<"Enter the matrix 2:"<<endl;
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
cin>>c[i][j];
}
cout<<"\n"<<"The matrix 2 is:"<<endl;
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
cout<<c[i][j];
cout<<" ";
}
cout<<"\n";
}
cout<<"\n"<<"The sum of two matrices is: ";
for(i=0;i<m;i++)
{
for(j=0;j<y;j++)
{
cout<<a[i][j]+c[i][j];
cout<<" ";
}
cout<<"\n";
}
}
else
cout<<"The sum is not possible.";
}
else if(b==2)
{
if(n==x)
{
cout<<"Enter the matrix 1:"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cin>>a[i][j];
}
cout<<"\n"<<"The matrix 1 is:"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<a[i][j];
cout<<" ";
}
cout<<"\n";
}
cout<<"\n"<<"Enter the matrix 2:"<<endl;
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
cin>>c[i][j];
}
cout<<"\n"<<"The matrix 2 is:"<<endl;
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
cout<<c[i][j];
cout<<" ";
}
cout<<"\n";
}
cout<<"\n"<<"The product of matrices is: "<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<y;j++)
{
d[i][j]=0;
for(z=0;z<n;z++)
d[i][j]=d[i][j]+(a[i][z]*c[z][j]);
cout<<d[i][j]<<" ";
}
cout<<"\n";
}
}
else
cout<<"The multiplication is not possible.";
}
else if(b==3)
{
if((m==n)&&(x==y))
{
cout<<"Enter the matrix 1: "<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cin>>e[i][j];
}
cout<<"The matrix 1 is:"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<e[i][j];
cout<<" ";
}
cout<<"\n";
}
cout<<"Enter the matrix 2:"<<endl;
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
cin>>f[i][j];
}
cout<<"The matrix 2 is:"<<endl;
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
cout<<f[i][j];
cout<<" ";
}
cout<<"\n";
}
cout<<"The differnce of two matrices is:"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<y;j++)
{
cout<<(e[i][j]-f[i][j]);
cout<<" ";
}
cout<<"\n";
}
}
cout<<"The difference is not possible.";
}
else
cout<<"The option is invalid.";
getch();
cout<<"Do you want to continue(y/n)?";
cin>>g;
}
while(g=='y');
}
OUTPUT:
10. Write a program using function overloading to calculate area of circle, square,
rectangle, right triangle and triangle using Heron’s Formula.
#include<iostream.h>
#include<conio.h>
#include<math.h>

float area(float a)
{
return((3.14)*a*a);
}
float area1(float a)
{
return(a*a);
}
float area(float a,float b)
{
return(a*b);
}
float area1(float a,float b)
{
return((0.5)*a*b);
}
float area(float a,float b,float c)
{
float s=((0.5)*(a+b+c));
return(sqrt(s*(s-a)*(s-b)*(s-c)));
}

void main()
{
clrscr();
char i;
float x,y,z;
int d;
cout<<"\t"<<"****WELCOME****"<<endl;
cout<<"1. Circle"<<endl<<"2. Square"<<endl<<"3. Rectangle"<<endl;
cout<<"4. Right Traingle"<<endl<<"5. Triangle"<<endl;
do
{
cout<<"Enter your choice: ";
cin>>d;

if(d==1)
{
cout<<"Enter the radius of circle: ";
cin>>x;
cout<<"The area of circle is= "<<area(x);
}
else if(d==2)
{
cout<<"enter the side of sqaure: ";
cin>>x;
cout<<"The area of square is= "<<area1(x);
}
else if(d==3)
{
cout<<"Enter the length of rectangle: ";
cin>>x;
cout<<"Enter the breadth of rectangle: ";
cin>>y;
cout<<"The area of rectangle is= "<<area(x,y);
}
else if(d==4)
{
cout<<"Enter the length of base: ";
cin>>x;
cout<<"Enter the length of altitude: ";
cin>>y;
cout<<"The area of the right triangle is= "<<area1(x,y);
}
else if(d==5)
{
cout<<"Enter the length of side 1: ";
cin>>x;
cout<<"Enter the length of side 2: ";
cin>>y;
cout<<"Enter the length of side 3: ";
cin>>z;
cout<<"The area of triangle is:= "<<area(x,y,z);
}
else
cout<<"The choice is invalid.";
cout<<"\n"<<"Do you want to continue(y/n)?";
cin>>i;
}while(i=='y');
getch();
}
OUTPUT:
11. Write a function to find and display the sum of each row and each column of a two
dimensional array of type float.
#include<iostream.h>
#include<conio.h>
float array()
{
int m,n;
cout<<"Enter the number of rows(max-50):";
cin>>m;
cout<<"Enter the no. of columns(max-50):";
cin>>n;
float b[50],c[50],a[50][50];
cout<<"Enter the 2-D array:"<<"\n";
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
cin>>a[i][j];
}
}
for(i=1;i<=m;i++)
{
b[m]=0;
for(int j=1;j<=n;j++)
{
b[m]+=a[i][j];
}
cout<<"the sum of row"<<i<<"="<<b[m]<<"\n";
}
for(int j=1;j<=n;j++)
{
c[n]=0;
for(int i=1;i<=m;i++)
{
c[n]+=a[i][j];
}
cout<<"The sum of column"<<j<<"="<<c[n]<<"\n";
}
return 0.1;
}

int main()
{
clrscr();
array();
getch();
return 0;
}
OUTPUT:

You might also like