Вы находитесь на странице: 1из 11

List of Practical (FE Sem 1: All Divisions) 1) Area of Triangle Accept three sides and find area of triangle.

2) Simple and Compound Interest Accept p, n and r and find simple and compound i nterest. 3) Circle and Square Accept side of square and find area of largest circle that can fit into it. Also find area of square that will be left outside the circle. 4) Greatest Number Accept three integers and find greatest integers. 5) Roots of Quadratic Equation Accept coefficient of Quadratic Equation and find roots and types of roots. 6) Money Conversion Accept value in rupees and convert in dollar and vice versa as per user s choice. Keep current dollar rate as constant. (1 $ = 44.89 Rs) 7) Arithmetic Calculator Accept two numbers and perform arithmetic operations on them as per user s choice. Provide manual checking for division by zero error. ( Use audible bell to attract user s attention to the user) 8) Fibonacci Series Display first k numbers of Fibonacci series. 9) Display Pattern Accept number of lines and display following pattern. 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 ( for n = 4) 10) GCD and LCM Accept 2 integers and find their gcd and lcm. 11) Palindrome Number Accept an integer and check whether it s palindrome or not. 12) Prime Number Write a function isprime which checks whether given integer is pr ime or not. Use this in main to print all prime numbers till n.

13) Perfect Square Write a function perfect to check whether given integer is pe rfect square or not. Use this in main to display perfect square between given tw o integers. 14) Recursion Write a recursive function fact which returns factorial of given integer. Use this to find combination of 2 numbers. nCr = n! / ( r! * (n r )!) 15) Sorting Write a function sort which sorts given array of integers. Program sho uld find given set of elements. (Median is the middle most element of the elemen t when sorted. It s an average of two middle most element if number of elements ar e even) 16) Matrix Multiplication Write a program to perform matrix multiplicati on of two matrices. Use separate functions read, display and product. 17) Call by reference Write a function compute which finds minimum, maximum and av erage of given array. All results computed by function must be displayed in main ( return type of function compute is void ) 18) Counting Words Accept a string and count number of words in it. 19) Sorting of Strings Accept n strings and sort them in alphabetical order. 20) Student Record A student structure stores name, roll number, marks of 10 tes ts (each out of 100), grand total and percentage. Accept records of n students, find their grand total and percentage and display them in descending order of th eir grand total. 21) Objects and Classes Create a class complex which stores rea l and imaginary parts of a complex number. Provide following functions: read( ) to read a complex number display( ) to display a complex number in proper format modulus( ) returns modulus of complex number reverse( ) returns complex number by swapping real and imaginary partsq 22) Arra y of Objects Create a class player which stores name of player, country, runs sc ored in last 5 matches, total runs and batting average. Write a program to accep t records of n players find their total runs and batting average. Display list o f players in descending order of their batting average. Use separate member func tions getdata, putdata, sort (static function) and display.

23) Constructor and Destructor Create a class distance which stores a distance val ue in feet and inches. The class should suit the following main function. void main( ) { distance d1(4,8),d2(8,10),d3; d3=d1.add(d2); d3.display( ); if (d1.compare(d2)==1) cout<< Two distances are equal\n ; else cout<< Two distances are not equal\n ; } 24) Operator Overloading Create a class ratio which stores numerator and denom inator of a ratio. Overload following operator as given + : adding two ratios - : subtracting two ratios * : multiplying two ratios / : dividing two ratios ! : find reciprocal of ratio 25) Inheritance Consider a class network given below. The class master derives i nformation from both account and admin classes which in turn derive information from class person. Define all the classes and write a program to create, update and display information contained in master objects.

Prog No 20 #include<iostream.h> #include<math.h> #include<conio.h> /* A student structure stores name, roll number, marks of 10 tests (each out of 100), grand total and percentage. Accept records of n students, find their grand total and percentage and display them in descending order of their grand total. */ struct student { char name[50]; int rno,m[10],gt; float per; }; void sort(student x[], int n) { for (int i=0; i<n-1; i++) for (int j=0; j<n-1; j++) if (x[j].gt<x[j+1].gt) { student t=x[j]; x[j]=x[j+1]; x[j+1]=t; }

} int main() { student s[100]; int n; cout<<"Enter no of students\n"; cin>>n; for (int i=0; i<n; i++) { cout<<"Enter name\n"; cin>>s[i].name; cout<<"Enter roll no\n"; cin>>s[i].rno; s[i].gt=0; for (int j=0; j<10; j++) { cout<<"Enter marks "<<j+1<<endl; cin>>s[i].m[j]; s[i].gt+=s[i].m[j]; } s[i].per=s[i].gt/10.0; } sort(s,n); cout<<"List of students in descending order of marks\n"; for (int i=0; i<n; i++) cout<<s[i].name<<" "<<s[i].rno<<" "<<s[i].gt<<" "<<s[i].per<<endl; getch(); }

Prog No 21 #include<iostream.h> #include<math.h> #include<conio.h> /* Create a class complex which stores real and imaginary parts of a complex number . Provide following functions: read( ) - to read a complex number display( ) - to display a complex number in proper format modulus( ) - returns modulus of complex number reverse( ) - returns complex number by swapping real and imaginary partsq */ class complex { float r,i; public: void read() { cout<<"Enter real and imaginary part of complex number\n"; cin>>r>>i; }

void display() { if (i>=0) cout<<r<<"+"<<i<<"i\n"; else cout<<r<<i<<"i\n"; } float modulus() { return (sqrt(r*r+i*i)); } complex reverse() { complex z; z.r=i; z.i=r; return z; } }; int main() { complex obj; obj.read(); cout<<"Complex number entered : "; obj.display(); cout<<"\nModulus = "<<obj.modulus(); cout<<"\nReverse of a complex number : "; complex r=obj.reverse(); r.display(); getch(); }

Prog No 22 #include<iostream.h> #include<math.h> #include<conio.h> /* Create a class player which stores name of player, country, runs scored in last 5 matches, total runs and batting average. Write a program to accept records of n players find their total runs and batting average. Display list of players in descending order of their batting average. Use separate member functions getdata, putdata, sort (static function) and display. */ class player { char name[50],country[50]; int runs[5],totruns; float bavg; public: void getdata()

{ cout<<"Enter name of player\n"; cin>>name; cout<<"Enter country name\n"; cin>>country; cout<<"Enter runs in 5 matches\n"; totruns=0; for (int i=0; i<5; i++) { cin>>runs[i]; totruns+=runs[i]; } bavg=float(totruns)/5; } void display() { cout<<name<<" "<<country<<" "<<totruns<<" "<<bavg<<endl; } static void sort(player x[], int n) { for (int i=0; i<n-1; i++) for (int j=0; j<n-1; j++) if (x[j].bavg<x[j+1].bavg) { player t=x[j]; x[j]=x[j+1]; x[j+1]=t; } } }; int main() { int n; cout<<"Enter no of elements\n"; cin>>n; player p[100]; for (int i=0; i<n; i++) p[i].getdata(); player::sort(p,n); cout<<"Sorted List\n"; for (int i=0; i<n; i++) p[i].display(); getch(); } Prog No 23

#include<iostream.h> #include<math.h> #include<conio.h> /* Create a class 'distance' which stores a distance value in feet and inches. The class should suit the following main function.

void main( ) { distance d1(4,8),d2(8,10),d3; d3=d1.add(d2); d3.display( ); if (d1.compare(d2)==1) cout<<"Two distances are equal\n"; else cout<<"Two distances are not equal\n"; } */ class distance { int f,i; public: distance() { f=i=0; } distance(int f, int i) { this->f=f; this->i=i; } void display() { cout<<f<<" ft "<<i<<" inches\n"; } distance add(distance t) { distance z; z.i=i+t.i; z.f=z.i/12; z.i=z.i%12; z.f+=f+t.f; return z; } int compare(distance t) { if (f==t.f && i==t.i) return 1; else return 0; } }; int main() { distance d1(4,8),d2(8,10),d3; d3=d1.add(d2); d3.display( ); if (d1.compare(d2)==1) cout<<"Two distances are equal\n"; else cout<<"Two distances are not equal\n"; getch(); }

Prog No 24 #include<iostream.h> #include<math.h> #include<conio.h> /* Create a class ratio which stores numerator and denominator of a ratio. Overload following operator as given + : adding two ratios - : subtracting two ratios * : multiplying two ratios / : dividing two ratios ! : find reciprocal of ratio } */ class ratio { int n,d; public: ratio() { n=d=1; } ratio (int n, int d) { this->n=n; this->d=d; } ratio operator + (ratio { ratio z; z.n=n*t.d+t.n*d; z.d=d*t.d; return z; } ratio operator - (ratio { ratio z; z.n=n*t.d-t.n*d; z.d=d*t.d; return z; } ratio operator * (ratio { ratio z; z.n=n*t.n; z.d=d*t.d; return z; } ratio operator / (ratio { ratio z; z.n=n*t.d; z.d=d*t.n; return z;

t)

t)

t)

t)

} ratio operator !( ) { ratio z; z.n=d; z.d=n; return z; } void display() { cout<<n<<" / "<<d<<endl; } };

int main() { ratio a(5,3),b(2,5),c; c=a+b; cout<<"Addition = "; c.display(); c=a-b; cout<<"Subtraction = "; c.display(); c=a*b; cout<<"Multiplication = "; c.display(); c=a/b; cout<<"Division = "; c.display(); c=!a; cout<<"Reciprocal = "; c.display(); getch(); }

Prog No 25 #include<iostream.h> #include<math.h> #include<conio.h> /* Consider a class network given below. The class master derives information from both account and admin classes which in turn derive information from class person. Define all the classes and write a program to create, update and display information contained in master objects. */ class person {

char name[50]; int code; public: void getdata() { cout<<"Enter name and code\n"; cin>>name>>code; } void putdata() { cout<<name<<" "<<code<<" "; } }; class account:public virtual person { int pay; public: void getdata() { cout<<"Enter pay\n"; cin>>pay; } void putdata() { cout<<pay<<" "; } }; class admin:public virtual person { int experience; public: void getdata() { cout<<"Enter experience\n"; cin>>experience; } void putdata() { cout<<experience<<" "; } }; class master:public account, public admin { public: void getdata() { person::getdata(); account::getdata(); admin::getdata(); } void putdata() { person::putdata(); account::putdata();

admin::putdata(); cout<<endl; } }; int main() { master obj[100]; int n; cout<<"Enter number of master objects\n"; cin>>n; for (int i=0; i<n; i++) obj[i].getdata(); for (int i=0; i<n; i++) obj[i].putdata(); getch(); }

Вам также может понравиться