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()
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:-
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]);
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;
}