Home
Welcome To
Programming Page Of 2k1CP
Here are given some very useful programs prepared by
our team. They are very helpful in understanding C++.
PROGRAM # 1
This program is a menu- wise program and it calculates and tells
the GPA of the student. It is created mainly with the help of
ARRAYS.
Enjoy:-
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
const true=1;
void newentry(void);
void list(void);
void display(int);
struct record
{
char name[30];
char roll[30];
float gpa;
} person[20],temp;
int n=0;
void main(void)
{
char ch;
int i,j,studentname;
while(true)
{
clrscr();
cout<<"\n\t Press \n\t e,E for new entry\n\t l,L for list"
<<"\n\t d,D for display\n\t q,Q for quit.";
ch=getche();
switch(ch)
{
case 'e':
case 'E':
newentry();
n++;
getch();
break;
case 'q':
case 'Q':
exit(0);
break;
case 'l':
case 'L':
list();
getch();
break;
case 'd':
case 'D':
cout<<"\n\t Enter the number whose biodata is required";
cin>>studentname;
display(studentname);
getch();
break;
}
}
}
void newentry(void)
{
clrscr();
cout<<"\n\t Enter the name of student\n";
gets(person[n].name);
cout<<"\n\t Enter the Roll number\n";
gets(person[n].roll);
cout<<"\n\t Enter the GPA";
cin>>person[n].gpa;
fflush(stdin);
}
void list(void)
{
int i,j,k=0;
for( i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(person[i].gpa>person[j].gpa)
{
temp=person[i];
person[i]=person[j];
person[j]=temp;
}
while(k<n)
{
cout<<"\n\t"<<k+1<<person[k].name;
cout<<person[k].roll;
k++;
}
}
void display(int studentname)
{
clrscr();
studentname=studentname-1;
cout<<"\n\t Name="<<person[studentname].name;
cout<<"\n\t Roll no="<<person[studentname].roll;
cout<<"\n\t GPA="<<person[studentname].gpa;
}
PROGRAM # 2
This program is about the Quadratic Formula. It is created with the help of
FUNCTIONS.
Here we go: -
#include<iostream.h>
#include<conio.h>
#include<math.h>
void quad(int,int,int);
void quad1(int,int,int);
void main(void)
{
clrscr();
int a,b,c;
cout<<"enter the value of a=";
cin>>a;
cout<<"enter the value of b=";
cin>>b;
cout<<"enter the value of c=";
cin>>c;
quad(a,b,c);
}
void quad(int a,int b,int c)
{ int disc,x1,x2;
disc=b*b-4*a*c;
if(disc>0)
{
cout<<"Following roots are real\n";
disc=sqrt(disc);
x1=(-b+disc)/(2*a);
x2=(-b-disc)/(2*a);
cout<<"Ist root is="<<x1<<endl;
cout<<"2nd root is="<<x2<<endl;
}
if(disc<0)
quad1(a,b,c);
}
void quad1(int x,int y,int z)
{
int disc=4*x*z-y*y;
cout<<"ist root is"<<-y/(2*x)<<"+i"<<disc/(2*x)<<endl;
cout<<"2nd root is"<<-y/(2*x)<<"-i"<<disc/(2*x)<<endl;
getch();
}
PROGRAM # 3
This program calculates the Transpose of
the matrix.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main(void)
{ clrscr();
int x[3][3],i,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>x[i][j];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{ cout<<x[j][i]<<setw(3);
if(j%3==0)
cout<<endl; }
getch(); }
Have any questions or
suggestion, contact us on: -
[email protected]
©2001.All rights
reserved by
www.2k1cp.com