Posts

Showing posts from July, 2022

C++ Program: Concept of Pointers to Objects

 // 13 C++ program - Concept of pointers to objects /* Create a class containing the following data members Register_No, Name and Fees. Also create a member function to read and display the data using the concept of pointers to objects. */ #include<iostream.h> #include<conio.h> class Student { private: long regno; char name[20]; float fees; public: void readdata( ); void display( ); }; void Student::readdata( ) { cout<<"Enter the Register Number:"<<endl; cin>>regno; cout<<"Enter the Student Name:"<<endl; cin>>name; cout<<"Enter the Fees:"<<endl; cin>>fees; } void Student::display( ) { cout<<"Register Number : "<<regno<<endl; cout<<"Student Name : "<<name<<endl; cout<<"Fees : "<<fees<<endl; } void main( ) { Student *S; // Create a pointer to point Student object clrscr(...

C++ Program: Single Inheritance

 /*  13 C++ Program Single Level Inheritance Create a base class containing the data member roll number and name. Also create a member function to read and display the data using the concept of single level inheritance. Create a derived class that contains marks of two subjects and total marks as the data members. */ #include<iostream.h> #include<conio.h> class Student // Base Class { private: long rollnumber; char name[20]; public: void readdata(); void display(); }; void Student::readdata( ) { cout<<"Enter the Roll Number: "; cin>>rollnumber; cout<<"Enter the Student Name:"; cin>>name; } void Student::display( ) { cout<<"\nRoll Number :"<<rollnumber<<endl; cout<<"Student Name:"<<name<<endl; } class Report : public Student // Derived class { private: int marks1, marks2, total; public:     void readmarks();     void compute(); }; void ...

HTML: Table and Form

html : table and form <html> <head> <title> online application </title> </head> <body> <form name=”appformpuc” method=”post” action=”ipuc_send.php> <h3 align=center> first puc application form </h3> <table cellspacing=5 cellpadding=5% align=center> <tr> <td align=left>student name: </td> <td><input type=”text” name=”stuname”></td> </tr> <tr> <td align=left>father name: </td> <td><input type=”text” name=”fatname”></td> </tr> <tr> <td align=left>father occupation: </td> <td><input type=”text” name=”fatocc”></td> </tr> <tr> <td align=left>date of birth: </td> <td><input type=”text” name=”dob”></td> </tr> <tr> <td align=left>contact number: </td> <td...

C++ Program : Sum of the Series using Constructor

 // 11 C++ program - Find the sum of the series 1 + x + x2+ x3 +….xn using constructors. // Write a C++ program to find sum of the series 1 + x + x2 + x3 + ….xn using constructors. #include<iostream.h> #include<conio.h> #include<math.h> class Series { private: int sum, x, n; public: Series(int y, int m) // Parameterized Constructor { sum = 1; x = y; n = m; for(int i=1;i<=n;i++) sum=sum+pow(x,i); } float getSum(); }; float Series::getSum() { return sum; } void main() { int x,n; clrscr( ); cout<<"Enter the value for Base(X)="<<endl; cin>>x; cout<<"Enter the value for Power(n)"<<endl; cin>>n; Series s1(x,n); // Calling Parameterized Constructor Series s2 = s1; // Copy Constructor cout<<"Sum of Series using Parameterised Constructor:"; cout<<s1.getSum()<<endl; cout<<"Sum of Series using Copy Constructor:"; c...

I PU Practical Exercises

I PU Practical Exercises  

C++ program: Inline function

 // 10 C++ program - Find cube of a number using inline function. #include<iostream.h> #include<conio.h> class InlineDemo { public: inline int cube(int a) //Inline function definition { return a*a*a; } }; void main() //Main Function { int n; InlineDemo i; clrscr( ); cout<<"Enter the input number"<<endl; cin>>n; cout<<"Cube of"<<" = "<<i.cube(n); //Inline function call getch( ); }

C++ Program: Function Overloading

 // 9 C++ program - Find the area of square/ rectangle/triangle using function overloading. #include<iostream.h> #include<conio.h> #include<stdlib.h> #include<math.h> class Funcoverload { public: float area(float a); float area(float l, float b); float area(float s1, float s2, float s3); }; float  Funcoverload:: area(float a) //To compute area of square { return a*a; } float  Funcoverload:: area(float l,float b) //To compute area of rectangle { return l*b; } float  Funcoverload:: area(float s1,float s2,float s3) //To compute area of triangle { float s=(s1+s2+s3)/2; return sqrt(s*(s-s1)*(s-s2)*(s-s3)); } void main() { float s1,s2,s3; int choice; Funcoverload f; clrscr( ); while(1) { cout<<"Program demonstrates Function Overloaded...!!!"<<endl; cout<<"1.To find area of square"<<endl; cout<<"2.To find area of rectangle"<<endl; cout<<"3.To find the area of triangle"...

HTML: Study Time Table

 8 HTML program - Create a study time-table <html> <head> <title> class time table </title> </head> <body text=darkblue color=white> <center> <h3> m d r pu science college </h3> <center> <h4> time table 2016-17 </h4> <table border=10 bordercolor=red bgcolor=cornsilk cellspacing=2 cellpadding=15> <caption> <b> ii puc pcmcs </b> <caption> <tr bgcolor=peachpuff> <td rowspan=2 align=center> <b> day </b> </td> <td colspan=8 align=center> <b> timings </b></td> </tr> <tr bgcolor=red> <th> 9.20 - 10.20 </th> <th> 10.20 - 11.20 </th> <th> 11.20 - 11.30 </th> <th> 11.30 - 12.30 </th> <th> 12.30 - 1.30 </th> <th> 1.30 - 2.30 </th> <th> 2.30 - 3.15 </th> <th> 3.15 - 4.00 </th> </tr...

C++ Program: Roots of a Quadratic Equation

 // 7 C++ program – Roots of a quadratic equation /* 7 Write a C++ program to create a class with data members a, b, c andmember functions to input data, compute the discriminant based on the following conditions and print the roots.  If discriminant = 0, print the roots are equal and their value.  If discriminant > 0, print the real roots and their values.  If discriminant < 0, print the roots are imaginary and exit the program. */ #include<iostream.h> #include<conio.h> #include<math.h> class Quadratic { private: int a, b, c; float disc, x, x1, x2; public: void readdata( ); void compute( ); void display( ); }; void Quadratic::readdata( ) { cout<<"Enter the values for a, b, c (Co-efficeient)"<<endl; cin>>a>>b>>c; } void Quadratic::compute( ) { disc = b*b-4*a*c; } void Quadratic::display( ) { compute( ); if(disc == 0) { cout<<"Equal Roots..."<<endl; x=-b/(2*a); ...

C++ Program: Computing Simple Interest

 // 6 C++ program - compute simple interest and to display the result. #include<iostream.h> #include<conio.h> class SimpleInterest { private: float principal,rate,time,si; //Data Members public: void readdata( ); void compute( ); //Member Functions Declaration void display( ); }; void SimpleInterest::readdata( ) //Member Function Definition { cout<<"Enter the Principal, Rate and Time"<<endl; cin>>principal>>rate>>time; } void SimpleInterest::compute( ) //Member Function Definition { si=(principal * time * rate)/100; } void SimpleInterest::display( ) //Member Function Definition { cout<<"Principal = "<<principal<<endl; cout<<"Time = "<<time<<endl; cout<<"Rate = "<<rate<<endl; cout<<"Simple Interest = "<<si<<endl; } void main( ) { SimpleInterest si; clrscr( ); si.readdata( ); si.compute( )...

C++ Program: Binary Search

  // 5 C++ program - search for a given element in an array using binary search method. #include<iostream.h> #include<conio.h> class Search { private: int a[10], n, ele, loc, beg, end, mid, i; public: void readdata( ); void bsearch( ); void display( ); }; void Search::readdata( ) { cout<<"Enter the size of the array:"<<endl; cin>>n; cout<<"Enter the array elements in sorted order:"<<endl; for(i=0;i<n;i++) cin>>a[i]; cout<<"Enter the element to search:"<<endl; cin>>ele; } void Search::bsearch( ) { loc = -1; // Assume that element does not exist beg = 0; // First element of the array end = n-1; // Second element of the array while(beg <= end) { mid = (beg+end)/2; if(ele == a[mid]) // Element found at mid { loc = mid; break; } elseif(ele < a[mid]) end = mid-1; else beg = mid+1; } } void Search::display( ) { ...

C++ Program: Insertion Sort

// 4 Write a C++ program to sort the element of an array in ascending order using insertion sort. #include<iostream.h> #include<conio.h> #include<stdlib.h> class Sort { private: int a[10], n, i; public: void readdata( ); void insertionsort( ); void display( ); }; void Sort::readdata( ) { cout<<"Enter the size of the array:"<<endl; cin>>n; cout<<"Enter the elements for the array:"<<endl; for(i=0; i<n; i++) cin>>a[i]; } void Sort::insertionsort( ) { int j, temp; for(i=1; i<n; i++) { j = i; while(j >= 1) { if(a[j] < a[j-1]) { temp = a[j]; a[j] = a[j-1]; a[j-1] = temp; } j = j-1; } } } void Sort::display( ) { for(i=0; i<n; i++) cout<<a[i]<<"\t"; cout<<endl; } void main( ) { Sort s; clrscr(); s.readdata( ); cout<<"Unsorted List......"<<endl; cout<<...

C++ Program: Delete an Element from an Array

  //  3 C++ program - delete an element from an array from a given position. #include<iostream.h> #include<conio.h> #include<stdlib.h> class Deletion { private: int a[10], n, pos, i; public: void readdata( ); void delet( ); void display( ); }; void Deletion::readdata( ) { cout<<"Enter the size of the array"<<endl; cin>>n; cout<<"Enter the elements for the array:"<<endl; for (i=0; i<n; i++) cin>>a[i]; cout<<"Enter the position to an delete an element:\n"; cin>>pos; } void Deletion::delet( ) { if(pos>n) { cout<<"Out of array limits...!!!"; getch( ); exit(0); } else { for(i=pos; i<n; i++) a[i] = a[i+1]; // Move higher position element n = n-1; // Reduce size of the array by 1 } } void Deletion::display( ) { cout<<"After deletion the array elements are"<<endl; for(i=0; i<n; i...

C++ Program: Insert an Element into an Array

 // 2 C++ program - insert an element into an array at a given position. #include<iostream.h> #include<conio.h> #include<stdlib.h> class Insertion { private: int a[10], n, pos, ele, i; //Data Members public: void readdata( ); void insert( ); // Member Function Declaration void display( ); }; void Insertion::readdata( ) { cout<<"Enter the size of the array"<<endl; cin>>n; cout<<"Enter the elements for the array"<<endl; for(i=0; i<n; i++) cin>>a[i]; cout<<"Enter the position of the element in the array"<<endl; cin>>pos; cout<<"Enter the element to be inserted"<<endl; cin>>ele; } void Insertion::insert( ) { if(pos>n) { cout<<"Out of array limits!!!"; getch( ); exit(0); } else { for(i=n; i>=pos; i--) a[i+1] = a[i]; // Shift array elements a[pos] = ele; // Insert the given el...