Programs

Published on May 2016 | Categories: Documents | Downloads: 35 | Comments: 0 | Views: 373
of 42
Download PDF   Embed   Report

Comments

Content

RAMA KRISHNA VIDYA
MANDIR

COMPUTER
SCIENCE(C++)
PRACTICAL FILE

SUBMITTED TO
SUBMITTED BY
HEMANT DIXIT
AYUSH PURI

CERTIFICATE
THIS

CERTIFICATE CERTIFIED THAT

CLASS

12TH

‘AYUSH

PURI’ OF

AND STUDYING IN RAMA KRISHNA

VIDYA MANDIR.HE HAS COMPLETED HIS ASSIGNMENT
WORK SUCCESSFULLY.
HE HAS SUBMITTED A SATISFACTORY PROJECT REPORT.

(MRS.MADHUGARG)
(MR.HEMANT DIXIT)
PRINCIPAL
OF COMPUTER SCIENCE

HOD

ACKNOWLEDGMENT
I gratefully acknowledge my extreme thanks
towards H.O.D. (C.S.) Hemant dixit R.K.V.M.
(C.B.S.E.) School, thatipur, Gwalior, (M.P.),
Project guide for his valuable guidance,
excellent, supervision & constant
encouragement throughout the entire project
completion.
I am also grateful to principle of R.K.V.M.
(C.B.S.E.) School Mrs.Madhu garg for
providing excellent academic atmosphere in
the institution. I pay may gratitude towards
the principal for unique lab facility and
support for making this endeavour possible.
Lastly I would like to thank my beloved
parents & my dear friends for their
encouragement and cooperation during the
time of working through the project.
AyushPuri

INDEX
Programs
Teacher sign
1.)Sum of two no. from class.

2.)Input student information and display menu.

3.)Create menu for area,daig,perimeter of
rectangle.

4.)Find Rowsum & Columnsum (2-D array).

5.)Check Even/odd of number from class
method.

6.) Input a year and weather its is leap year or
not.

7.) Find Roots of the quadratic
eqation(ax^2+bx+c).

8.)Input P,R,T and find its interested amount.

9.) Stream to file(marks.dat) with no lossof
data.

Teacher sign&
Remark

10.)Input two no. and swap its values by
pointer.

11.) Write a program to print where given
character is an uppercase or a lowercase
charcter or a digit any other character. Use
ASII code for it.

12.)Program to handle Exception.

13.)Program to insert and display data entered
by using pointer notation.

14.)Program to display the elements of two
dimensional array by passing it to a function.

15.)Program to store temprarture of two
different cities for a week and display it.

16.)Program to add two numbers entered by
user until users enters 0.

17.) Write a program to make a simple
calculator.
18.) Program to return absalute value of
variable type integers and float using fuction
overloading.

19.)Program to find cube of number by inline
class method.

20.) Program to read and write in file.

1.)WAP to input and calculate its sum by using class:#include<iostream.h>
#include<conio.h>
Class abc
{
Private:
Int a,b,c;
Public:
Void get()
Void disp()
};
Void abc :: get()
{
Clrscr();
Cout<<”Enter A=\nEnter B=”;
Cin>>a>>b;
}
Void abc :: disp()

{
Cout<<”A+C”=<<c;
}
Void main()
{
Abc x;
x.get();
x.disp();
getch();

2.)Program to input student information and display from
menu:#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
class abc
{
private:
char name[25];
int roll,clas,marks;
public:
void read();
void disp();
};
void abc::read()
{
clrscr();
cout<<"Enter name=";
gets(name);

cout<<"Enter class=";
cin>>clas;
cout<<"enter roll no=";
cin>>roll;
cout<<"Enter marks=";
cin>>marks;
}
void abc::disp()
{
clrscr();
cout<<"\nName="<<name;
cout<<"\nClass="<<clas;
cout<<"\nRoll no.="<<roll;
cout<<"\nMarks="<<marks;
}
int main()
{
abc x;
int ch;
do
{
clrscr();
cout<<"\n\n\nMain menu.\n";
cout<<"1.Input data\n";
cout<<"2.Display data\n";
cout<<"3.Exit\n";
cout<<"Enter your choice(1,2,3:";
cin>>ch;
switch(ch)
{
case 1:x.read();
break;
case 2:x.disp();
break;
default:exit(0);
break;

}
}
while(ch<=1&&ch<=3);
getch();
return 0;
}

Output:-

3.)WAP to input length & breadth and create menu for
area,perimeter,diagnol of rectangle:#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<math.h>
int main()
{
char ch,ch1;
float l,b,peri,area,diag;
clrscr();
cout<<"::::::::::::::::::::::::::::::::RECTANGLE
MENU::::::::::::::::::::::::::::::::::";
cout<<"\n1.Area";
cout<<"\n2.Perimeter";
cout<<"\n3.Diagnol";
cout<<"\n4.Exit\n";
cout<<"Enter your choice :";
do {
cin>>ch;
if(ch=='1'||ch=='2'||ch=='3')
{
cout<<"Enter length & breadth:";
cin>>l>>b;
} switch(ch) {

case'1':area=l*b;
cout<<"AREA="<<area;
break;
case'2':peri=2*(l+b);
cout<<"PERIMETER="<<peri;
break;
case'3':diag=sqrt((l*l)+(b*b));
cout<<"DIAGNOL="<<diag;
break;
case'4':exit(0);
break;
default:cout<<"\t\t\t
WORNG CHOICE...!";
break;
}
}
while(ch1=='y'||ch1=='Y');
getch();
return 0;
}

4.)Program to find Rowsum & Cloumnsum (2-D array):#include<iostream.h>
#include<conio.h>
int main()
{
int*val,*rsum,*csum;
int maxr,maxc,i,j;
clrscr();
cout<<"Enter Row & Column:";
cin>>maxr>>maxc;
val=new int[maxr * maxc];
rsum=new int[maxr];
csum=new int[maxc];
for(i=0;i<maxr;i++)
{
cout<<"\nEnter elements of row::"<<i+1;
rsum[i]=0;
for(j=0;j<maxc;j++)
{
cin>>val[i *maxc+j];

rsum[i]+=val[i * maxc+j];
}
}
for(j=0;j<maxc;j++)
{
csum[j]=0;
for(i=0;i<maxr;i++)
{
csum[j]+=val[i *maxc+j];
}}
cout<<"The given array along with rowsum & colsum is:\n\n";
for(i=0;i<maxr;i++)
{
for(j=0;j<maxc;j++)
{
cout<<val[i *maxc+j]<<"\t";
}
cout<<rsum[i];
}
for(j=0;j<maxc;j++)
{
cout<<csum[j]<<"\t";
}
cout<<endl;
getch();
return 0;
}

5.)WAP to input a no. and check (even/odd) by class method:#include<iostream.h>
#include<conio.h>
class abc
{
char ch;
int num;
public:
void get();
};
void abc:: get()
{
clrscr();
cout<<"Enter any no=";
cin>>num;
if(num%2==0)
cout<<"Number is even..!";
else if(num%2!=0)
cout<<"Number is odd..!";
}
void main()
{

abc x;
x.get();
getch();
}

6.)Program to input a year and weather its is leap year or not:#include<iostream.h>
#include<conio.h>
class abc
{
public:
int year;
void get()
{
clrscr();
cout<<"Enter any year:="<<" ";
cin>>year;
if(year%4==0)
{
cout<<"This is a leap year";
}
else
{
cout<<"This is not a leap year";
}
}
};
void main()
{
abc x;

x.get();
getch();
}

7.)WAP to finf the Roots of the quadratic eqation(ax^2+bx+c):#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
float a,b,c,root1,root2,delta;
clrscr();
cout<<"Enter three no a,b,c of"<<"ax^2+bx+c:\n";
cin>>a>>b>>c;
if(!a)
cout<<"Value of a should not be zero"<<"\nAborting !!!!";
else
{
delta=b*b-4*a*c;
if(delta>0)
{
root1=(-b+sqrt(delta))/(2*a);
root2=(-b-sqrt(delta))/(2*a);
cout<<"Roots are real and UNequal\n";
cout<<"Root1="<<root1<<"\nRoot2="<<root2;
}
else
cout<<"Roots are complex and imaginery";
}
getch();
return 0;
}

8.)WAP to input principal,rate,time and find its interested
amount:#include<iostream.h>
#include<conio.h>
class abc
{
int pa,tm,rt;
float ia;
public:
void get();
void disp();
void cal();
};
void abc::get()
{
cout<<"Enter principal amount=";
cin>>pa;
cout<<"Enter time=";
cin>>tm;
cout<<"Enter Rate=";
cin>>rt;
}
void abc::cal()
{
ia=(pa*tm*rt)/100;
}
void abc :: disp()
{
cout<<"Interest Amount="<<ia;
}
void main()
{
abc x;
x.get();
x.disp();

x.cal();
getch();
}

9.)WAP that reads such deatil appends them to

file(marks.dat) with no lossof data:-

#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
#include<conio.h>
int main()
{
ofstream fout;
fout.open("marsk.dat",ios::app);
char ans='y';
int rollno;
float marks;
while(ans=='y'||ans=='Y')
{
cout<<"\nEnter rollno:";
cin>>rollno;
cout<<"\nenter marks=";
cin>>marks;
fout<<rollno<<"\n"<<marks<<"\n";
cout<<"\nWnat to enter more records?(y/n)...";
cin>>ans;
}
fout.close();
return 0;
getch();
}

10.)WAP to input two no. and swap its values by pointer:-

#include<iostream.h>
#include<conio.h>
int main()
{
void swap(int*x,int*y);
int a,b;
clrscr();
cout<<"Enter A=";
cin>>a;
cout<<"Enter B=";
cin>>b;
clrscr();
cout<<"Original values\n";
cout<<"A="<<a<<",B="<<b<<"\n";
swap(&a,&b);
cout<<"Swapped values \n";
cout<<"A="<<a<<",B="<<b<<"\n";
getch();
return 0;
}
void swap(int*x,int*y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}

11.) Write a program to print where given character is an
uppercase or a lowercase charcter or a digit any other character.
Use ASII code for it.

#include<iostream.h>
#include<conio.h>
int main()
{
char ch;
clrscr();
cout<<"\nEntre a character : ";
cin>>ch;
if(ch >= 48 && ch <= 57)
cout<<"\n"<<"You entered a digit";
else if(ch >= 65 && ch <= 90)
cout<<"\n"<<"You entered an uppercase character";
else if(ch >= 97 && ch <= 122)
cout<<"\n"<<"You entered an lowercase character";
else
cout<<"\n"<<"You entered a special character";
getch();
}

12.) PROGRAM TO USE POINTER
#include<iostream.h>

#include<conio.h>
int main()
{
int fv,sv;
int *p1.*p2;
clrscr();
cout<<”Enter first value=”;
cin>>fv;
cout<<”Enter second value=”;
cin>>sv;
p1=&fv;
p2=&sv;
*p1=10;
*p2=*p1;
p1=p2;
*p1=20;
cout<<”First value=”<<fv\n”;
cout<<”Second value=”<<sv\n”;
getch();
return 0;
}

13.) PROGRAM TO INSERT AND DISPLAY DATA ENTERED BY USING
POINTER NOTATION.
#include <iostream.h>
#include<conio.h>

int main( )
{
float a[5];
cout << "Enter 5 numbers: ";
for (int i = 0; i < 5; ++i)
{
cin >> *(a+i) ;
}
cout << "Displaying data: " << endl;
for (int i = 0; i < 5; ++i)
{
cout << *(a+i) << endl ;
}
getch();
return 0;
}

14.) PROGRAM TO DISPLAY THE ELEMENTS OF TWO DIMENSIONAL
ARRAY BY PASSING IT TO A FUNCTION.
#include <iostream.h>
#include<conio.h>
void display(int n[3][2]);

int main( )
{
int num[3][2] =
{
{3, 4}, {9, 5}, {7, 1}
};
display(num);
getch();
return 0;
} void display(int n[3][2])
{
cout<<"Displaying Values: "<<endl;
for(int i = 0; i < 3; ++ i)
{
for(int j = 0; j < 2; ++j)
{
cout<<n[i][j]<<" ";
}
}}

15.) PROGRAM TO STORE TEMPERATURE OF TWO DIFFERENT
CITIES FOR A WEEK AND DISPLAY IT.
#include <iostream.h>
#include<conio.h>
const int CITY = 2;
const int WEEK = 7;

int main( )
{
int temperature[CITY][WEEK];
cout<<"Enter all temperature for a week of first city and then
second city. \n";
for (int i = 0; i < CITY; ++i)
{
for(int j = 0; j < WEEK; ++j)
{
cout<<"City "<<i+1<<", Day "<<j+1<<" : ";
cin>>temperature[i][j];
}
}
cout<<"\n\nDisplaying Values:\n";
for (int i = 0; i < CITY; ++i)
{
for(int j = 0; j < WEEK; ++j)
{
cout<<"City "<<i+1<<", Day "<<j+1<<" = "<< temperature[i]
[j]<<endl;
}
}
getch();
return 0;
}

16.) PROGRAM TO ADD NUMBERS ENTERED BY USER UNTIL USER
ENTERS 0
#include<iostream.h>

#include<conio.h>
int main( )
{
float number,
sum = 0.0;
do
{
cout<<"Enter a number: ";
cin>>number;
sum += number;
}
while(number != 0.0);
cout<<"Total sum = "<<sum;
getch();
return 0;
}

17.) Write a program to make a simple calculator.
#include<iostream.h>
#include<conio.h>

int main()
{
char ch;
clrscr();
float a,b,result;
cout<<"Enter first number=";
cin>>a;
cout<<"Enter second number=";
cin>>b;
cout<<"Enter any operation (+,-,*,/)=";
cin>>ch;
if (ch=='+')
result=a+b;
else
if (ch=='-')
result=a-b;
else
if (ch=='*')
result=a*b;
else
if (ch=='/')
result=a/b;
else
cout<<"Wrong operator\n";
cout<<"Result is="<<result<<"\n";
getch();
}

18.) PROGRAM TO RETURN ABSOLUTE VALUE OF VARIABLE TYPES
INTEGER AND FLOAT USING FUNCTION OVERLOADING

#include <iostream.h>
#include<conio.h>
int absolute(int);
float absolute(float);
int main( )
{
int a = -5;
float b = 5.5;
cout<<"Absolute value of "<<a<<" = "<<absolute(a)<<endl;
cout<<"Absolute value of "<<b<<" = "<<absolute(b);
getch();
return 0;
}
int absolute(int var)
{
if (var < 0)
var = -var;
return var;
}
float absolute(float var)
{
if (var < 0.0)
var = -var;
return var;
}

19.)program to find cube of number by inline class method

#include<iostream.h>
#include<conio.h>
class line
{
public:
inline float mul(float x,float y)
{
return(x*y);
}
inline float cube(float x)
{
return(x*x*x);
} };
void main()
{
line obj;
float val1,val2;
clrscr();
cout<<"Enter two values:";
cin>>val1>>val2;
cout<<"\nMultiplication value is:"<<obj.mul(val1,val2);
cout<<"\n\nCube value
is :"<<obj.cube(val1)<<"\t"<<obj.cube(val2);
getch();
}

20.) PROGRAM TO READ AND WRITE IN A FILE
#include <fstream.h>
#include <iostream.h>
#include<conio.h>
int main ()
{
char data[100];
ofstream outfile;
outfile.open("afile.dat");
cout << "Writing to the file" << endl;
cout << "Enter your name: ";
cin.getline(data, 100);

outfile << data << endl;
cout << "Enter your age: ";
cin >> data; cin.ignore();
outfile << data << endl;
outfile.close();
ifstream infile;
infile.open("afile.dat");
cout << "Reading from the file" << endl;
infile >> data;
cout << data << endl;
infile >> data;
cout << data << endl;
infile.close();
return 0;
}

*********

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close