/* Q.N 4. Write a program to create that calculates the interest of any number */
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class interest
{
int year;
float rate,amount;
public:
void getval();
void calcint();
};
void interest::getval()
{
cout<<"Enter Principal Amount : "<<endl;
cin>>amount;
cout<<"\nEnter Rate and Time in Year : "<<endl;
cin>>rate>>year;
}
void interest::calcint()
{
float inter=(amount*year*rate/100);
cout<<"\nThe Interest Amount : "<<inter<<endl;
}
int main()
{
interest I;
I.getval();
I.calcint();
getch();
return 0;
}
Tuesday, February 5, 2013
sorting
/*Q.N 3. Write a C++ code to sort the given 10 numbers in assending order .*/
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class sort
{
int val[10];
public:
void getval(void);
void sorts(void);
void disp(void);
};
void sort::getval()
{
int i;
cout<<"\nEnter 5 integer Data : \n";
for(i=0;i<5;i++)
{
cout<<"\nEnter Value "<<i+1<<" :";
cin>>val[i];
}
}
void sort::sorts()
{
int i,j,temp;
for(j=0;j<5;j++)
{
for(i=0;i<4;i++)
{
if(val[i]>val[i+1])
{
temp=val[i];
val[i]=val[i+1];
val[i+1]=temp;
}
}
}
}
void sort::disp()
{
int i;
cout<<"\nThe Sorted Array : \n";
for(i=0;i<5;i++)
{
cout<<"\nValue "<<i+1<<":"<<val[i];
}
}
int main()
{
sort S;
S.getval();
S.sorts();
S.disp();
getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class sort
{
int val[10];
public:
void getval(void);
void sorts(void);
void disp(void);
};
void sort::getval()
{
int i;
cout<<"\nEnter 5 integer Data : \n";
for(i=0;i<5;i++)
{
cout<<"\nEnter Value "<<i+1<<" :";
cin>>val[i];
}
}
void sort::sorts()
{
int i,j,temp;
for(j=0;j<5;j++)
{
for(i=0;i<4;i++)
{
if(val[i]>val[i+1])
{
temp=val[i];
val[i]=val[i+1];
val[i+1]=temp;
}
}
}
}
void sort::disp()
{
int i;
cout<<"\nThe Sorted Array : \n";
for(i=0;i<5;i++)
{
cout<<"\nValue "<<i+1<<":"<<val[i];
}
}
int main()
{
sort S;
S.getval();
S.sorts();
S.disp();
getch();
return 0;
}
quadratic equations
/* Q.N 1. Write a C++ code to solve the quadratic equations . */
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<iostream.h>
class qequ
{
int a,b,c;
float root1,root2;
public:
void getdata(int ,int ,int);
void calroot();
void disp();
};
void qequ::getdata(int x,int y,int z)
{
a=x;
b=y;
c=z;
}
void
main()
{
int a,b,c;
float d,root1,root2;
cout<<"\nEnter The Value Of a , b & c from Equation : ";
cin>>a>>b>>c;
d=sqrt(b*b-4*a*c);
if(d<0)
cout<<"\nThe Roots Are Imaginarry !";
else
{
root1=((-b+d)/2*a);
root1=((-b+d)/2*a);
cout<<"\nThe Roots Are : ";
cout<<"\nRoot 1 : "<<root1;
cout<<"\nRoot 2 : "<<root2;
}
getch();
}
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<iostream.h>
class qequ
{
int a,b,c;
float root1,root2;
public:
void getdata(int ,int ,int);
void calroot();
void disp();
};
void qequ::getdata(int x,int y,int z)
{
a=x;
b=y;
c=z;
}
void
main()
{
int a,b,c;
float d,root1,root2;
cout<<"\nEnter The Value Of a , b & c from Equation : ";
cin>>a>>b>>c;
d=sqrt(b*b-4*a*c);
if(d<0)
cout<<"\nThe Roots Are Imaginarry !";
else
{
root1=((-b+d)/2*a);
root1=((-b+d)/2*a);
cout<<"\nThe Roots Are : ";
cout<<"\nRoot 1 : "<<root1;
cout<<"\nRoot 2 : "<<root2;
}
getch();
}
Student info
/*Create a class student with private data members name ,roll no,age and member functions input() to take input of data and display() to display the records .
Test the program for one student*/
#include<iostream.h>
#include<string.h>
#include<conio.h>
class student
{
private:
char name[25];
int roll,age;
public:
void input(char nam[] ,int rol,int ag);
void display(void);
};
void student::input(char nam[25],int rol,int ag)
{
strcpy(name,nam);
roll=rol;
age=ag;
}
void student::display()
{
cout<<"Name : "<<name<<endl;
cout<<"Roll No : "<<roll<<endl;
cout<<"Age : "<<age<<endl;
}
int main()
{
student st;
char name[25];
int roll,age;
cout<<"\nEnter Name : "<<endl;
cin>>name;
cout<<"Enter Roll No: "<<endl;
cin>>roll;
cout<<"Enter Age : "<<endl;
cin>>age;
st.input(name,roll,age);
st.display();
getch();
return 0;
}
Test the program for one student*/
#include<iostream.h>
#include<string.h>
#include<conio.h>
class student
{
private:
char name[25];
int roll,age;
public:
void input(char nam[] ,int rol,int ag);
void display(void);
};
void student::input(char nam[25],int rol,int ag)
{
strcpy(name,nam);
roll=rol;
age=ag;
}
void student::display()
{
cout<<"Name : "<<name<<endl;
cout<<"Roll No : "<<roll<<endl;
cout<<"Age : "<<age<<endl;
}
int main()
{
student st;
char name[25];
int roll,age;
cout<<"\nEnter Name : "<<endl;
cin>>name;
cout<<"Enter Roll No: "<<endl;
cin>>roll;
cout<<"Enter Age : "<<endl;
cin>>age;
st.input(name,roll,age);
st.display();
getch();
return 0;
}
/*Create a class Student with six data members (Roll No., name , marks in English ,Maths and Science , total), write a program with init()
to initializes necessary data members , Calctotal() that calculates the total of the marks obtained int the three subjects and display()
that displays the details of the Students.
In main() create two objects of the class student and for each object invoke calctotal() and display().*/
#include<iostream.h>
#include<string.h>
#include<conio.h>
class student
{
private:
char name[25];
int roll;
float eng,math,sci,total;
public:
void init(char [] ,int ,float ,float ,float);
float calctotal(void);
void display(void);
};
void student::init(char nam[25],int rol, float engl, float maths, float scie)
{
strcpy(name,nam);
roll=rol;
eng=engl;
math=maths;
sci=scie;
total=calctotal();
}
void student::display()
{
cout<<"Name : "<<name<<endl;
cout<<"Roll No : "<<roll<<endl;
cout<<"English : "<<eng<<endl;
cout<<"Math : "<<math<<endl;
cout<<"Science : "<<sci<<endl;
cout<<"Total : "<<total<<endl;
}
float student::calctotal()
{
return(eng+sci+math);
}
int main()
{
student st1,st2;
char name[25];
int roll;
float eng,sci,math;
cout<<"\nEnter Name : "<<endl;
cin>>name;
cout<<"Enter Roll No: "<<endl;
cin>>roll;
cout<<"\n\tEnter Marks : \n";
cout<<"English : "<<endl;
cin>>eng;
cout<<"Mathematics: "<<endl;
cin>>math;
cout<<"Science : "<<endl;
cin>>sci;
st1.init(name,roll,eng,math,sci);
st1.display();
cout<<"\nEnter Name : "<<endl;
cin>>name;
cout<<"Enter Roll No: "<<endl;
cin>>roll;
cout<<"\n\tEnter Marks : \n";
cout<<"English : "<<endl;
cin>>eng;
cout<<"Mathematics: "<<endl;
cin>>math;
cout<<"Science : "<<endl;
cin>>sci;
st2.init(name,roll,eng,math,sci);
st2.display();
getch();
return 0;
}
to initializes necessary data members , Calctotal() that calculates the total of the marks obtained int the three subjects and display()
that displays the details of the Students.
In main() create two objects of the class student and for each object invoke calctotal() and display().*/
#include<iostream.h>
#include<string.h>
#include<conio.h>
class student
{
private:
char name[25];
int roll;
float eng,math,sci,total;
public:
void init(char [] ,int ,float ,float ,float);
float calctotal(void);
void display(void);
};
void student::init(char nam[25],int rol, float engl, float maths, float scie)
{
strcpy(name,nam);
roll=rol;
eng=engl;
math=maths;
sci=scie;
total=calctotal();
}
void student::display()
{
cout<<"Name : "<<name<<endl;
cout<<"Roll No : "<<roll<<endl;
cout<<"English : "<<eng<<endl;
cout<<"Math : "<<math<<endl;
cout<<"Science : "<<sci<<endl;
cout<<"Total : "<<total<<endl;
}
float student::calctotal()
{
return(eng+sci+math);
}
int main()
{
student st1,st2;
char name[25];
int roll;
float eng,sci,math;
cout<<"\nEnter Name : "<<endl;
cin>>name;
cout<<"Enter Roll No: "<<endl;
cin>>roll;
cout<<"\n\tEnter Marks : \n";
cout<<"English : "<<endl;
cin>>eng;
cout<<"Mathematics: "<<endl;
cin>>math;
cout<<"Science : "<<endl;
cin>>sci;
st1.init(name,roll,eng,math,sci);
st1.display();
cout<<"\nEnter Name : "<<endl;
cin>>name;
cout<<"Enter Roll No: "<<endl;
cin>>roll;
cout<<"\n\tEnter Marks : \n";
cout<<"English : "<<endl;
cin>>eng;
cout<<"Mathematics: "<<endl;
cin>>math;
cout<<"Science : "<<endl;
cin>>sci;
st2.init(name,roll,eng,math,sci);
st2.display();
getch();
return 0;
}
Sunday, February 3, 2013
Comparision
#include<iostream.h>
#include<conio.h>
class comparison
{
int x,y,max;
public:
void getdata(int a,int b);
void largest(void);
void print(void);
};
void comparison::getdata(int a,int b)
{
x=a;
y=b;
}
void comparison::largest()
{
if(x>y)
max=x;
else
max=y;
}
void comparison::print()
{
cout<<"\nThe Largest Number : "<<max<<endl;
}
int main()
{
comparison com;
int a,b;
cout<<"Enter Two numbers : ";
cin>>a>>b;;
com.getdata(a,b);
com.largest();
com.print();
getch();
}
#include<conio.h>
class comparison
{
int x,y,max;
public:
void getdata(int a,int b);
void largest(void);
void print(void);
};
void comparison::getdata(int a,int b)
{
x=a;
y=b;
}
void comparison::largest()
{
if(x>y)
max=x;
else
max=y;
}
void comparison::print()
{
cout<<"\nThe Largest Number : "<<max<<endl;
}
int main()
{
comparison com;
int a,b;
cout<<"Enter Two numbers : ";
cin>>a>>b;;
com.getdata(a,b);
com.largest();
com.print();
getch();
}
Saturday, January 19, 2013
print the series....
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
clrscr();
int i;
float z;
for(i=0;i<8;i++)
{
z=pow(2,i);
//for(i=0;i<8;i++)
printf(" 1/%3.f\n",z);
}
getch();
}
#include<conio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
clrscr();
int i;
float z;
for(i=0;i<8;i++)
{
z=pow(2,i);
//for(i=0;i<8;i++)
printf(" 1/%3.f\n",z);
}
getch();
}
Subscribe to:
Posts (Atom)