Showing posts with label OOP and CG. Show all posts

Object Oriented Programming & Computer Graphics Laboratory

, by Prashant Gunjal


Object Oriented Programming & Computer Graphics Laboratory

GROUP A

· Constructor, Destructor:

Static member functions,friend class,this pointer,inline code and dynamic memory allocation :

· Operator overloading



· Inheritance


· Templates


· Virtual functions & files

8. Create a class named Television that has data members to hold the model number and the screen size in inches,and the price.Member functions include overloaded insertion and extraction operators.If more than four digits are entered for the model,if the screen size is smaller than 12 or greater than 70 inches, or if the price is negative or over $5000 then throw an integer.Write a main() function that instantiates a television
object,allows user to enter data and displays the data members .If an exception is caught ,replace all the data member values with zero values.

GROUP B

1. Assignments to understand functions available in graphics library such as,
(a) Text and Graphics mode, initialization of graphics mode, graphics drivers,
switching between text and graphics mode, error handling.
(b) Color, Color Palette, Aspect ratio, Text: fonts, alignment, size, orientation
and justification.
(c) Graphics Primitives: Pixel, Line, Circle, Ellipse, Polygons, Line styles, Bar
graphs, Pie Charts, Histograms, filling a polygon, windowing.
(d) Writing a Graphics Editor
2. Write a program to implement algorithm for line and circle drawing.
3. Write a program to implement algorithm for filling a polygon using scan-fill
method.
4. Write a program to implement 2-D transformations.
5. Case study of any graphics tool.


read more

C++ program to explain the concept of inheritance

, by Prashant Gunjal


Design a base class consisting of the data members such as name of the student,roll number and subject.The derived class consists of the data members subject code ,internal assessment and university examination marks.Construct a virtual base class for the item name of the student and roll number.The program should have the facilities. i) Build a master table ii) List a table iii) Insert a new entry iv) Delete old entry v) Edit an entry vi) Search for a record




#include<iostream.h>
#include<fstream.h>
#include<conio.h>

class student
{
protected:
 char nm[40];
 int rno;
 char sub[10];
public:
 void get();
};

class marks:virtual public student
{
int sub_code;
int internal;
int uni_marks;
public:
marks()
{
sub_code=0;
internal=0;
uni_marks=0;
}
void getdata();
void display();
void insert();
void modify();
};

void student::get()
{
cout<<"\n\n\t Enter name:";
cin>>nm;
cout<<"\n\n\t Enter roll no:";
cin>>rno;
cout<<"\n\n\t Enter subject name:";
cin>>sub;
}

void marks::getdata()
{
get();
cout<<"\n\n\t Enter subject code:";
cin>>sub_code;
cout<<"\n\n\t Enter internal assessment:";
cin>>internal;
cout<<"\n\n\t Enter university marks:";
cin>>uni_marks;
}

void marks::display()
{
cout<<" "<<nm<<"\t"<<rno<<"\t"<<sub<<"\t"<<sub_code<<"\t\t"<<internal<<"\t\t"<<uni_marks;
}

void marks::insert()
{
getdata();
}

void marks::modify()
{
getdata();
}

void main()
{
fstream f1;
f1.open("stud.dat", ios::in | ios::out);
int ch,n,loc,i;
marks m[10];
clrscr();
cout<<"\n\n\t Enter no.of records";
cin>>n;
do
 {
  cout<<"\n\n\t 1> Build master table";
  cout<<"\n\n\t 2> Display \n\n\t 3> Insert";
  cout<<"\n\n\t 4> Delete \n\n\t 5> Modify";
  cout<<"\n\n\t 6> Search";
  cout<<"\n\n\t Enter your choice";
  cin>>ch;
  switch(ch)
  {
  case 1:for(i=0;i<n;i++)
{
 m[i].getdata();
 f1.write((char *) & m[i],sizeof(m[i]));
}
  break;
  case 2:cout<<"\n\n";
 cout<<"NAME\tROLL NO\tSUBJECT\tSUB CODE\tINTERNAL\tMARKS";
 cout<<"\n\n";
 cout<<"-----------------------------------------------------------------";
 cout<<"\n\n";
 for(i=0;i<n;i++)
{
 f1.read((char *) & m[i],sizeof(m[i]));
 m[i].display();
 f1.write((char *) & m[i],sizeof(m[i]));
 cout<<"\n\n";
}
 break;
  case 3:cout<<"\n\n\t Enter loc at which record to be inserted";
 cin>>loc;
 for(i=n-1;i>=loc-1;i--)
{
 f1.read((char *) & m[i],sizeof(m[i]));
 m[i+1]=m[i];
}
 f1.write((char *) & m[i],sizeof(m[i]));
 m[loc-1].insert();
 n++;
 break;
  case 4:cout<<"\n\n\t enter loc at which record to be deleted";
 cin>>loc;
 for(i=loc-1;i<=n-1;i++)
{
 f1.read((char *) & m[i],sizeof(m[i]));
 m[i]=m[i+1];
}
 n--;
 cout<<"\n\n";
 cout<<"NAME\tROLL NO\tSUBJECT\tSUB CODE\tINTERNAL\tMARKS";
 cout<<"\n\n";
 cout<<"-----------------------------------------------------------------";
 cout<<"\n\n";
 for(i=0;i<n;i++)
{
 f1.read((char *) & m[i],sizeof(m[i]));
 m[i].display();
 f1.write((char *) & m[i],sizeof(m[i]));
 cout<<"\n\n";
}
 break;
  case 5:cout<<"\n\n\t Enter which record to be editted";
 cin>>loc;
 m[loc-1].insert();
 cout<<"\n\n";
 cout<<"NAME\tROLL NO\tSUBJECT\tSUB CODE\tINTERNAL\tMARKS";
 cout<<"\n\n";
 cout<<"-----------------------------------------------------------------";
 cout<<"\n\n";
 f1.read((char *) & m[i],sizeof(m[i]));
 m[loc-1].display();
 f1.write((char *) & m[i],sizeof(m[i]));
 cout<<"\n\n";
break;
  case 6:cout<<"\n\n\t Enter record to be searched";
 cin>>loc;
 if(n>=loc)
{
cout<<"\n\n\t Found Record";
cout<<"\n\n";
cout<<"NAME\tROLL NO\tSUBJECT\tSUB CODE\tINTERNAL\tMARKS";
cout<<"\n\n";
cout<<"-----------------------------------------------------------------";
cout<<"\n\n";
f1.read((char *) & m[i],sizeof(m[i]));
m[loc-1].display();
f1.write((char *) & m[i],sizeof(m[i]));
cout<<"\n\n";
}
 else
 cout<<"\n\n\t Not Found";
break;
  }
 }while(ch!=7);
 f1.close();
 getch();
}

/* OUTPUT

Enter no.of records 1

1> Build master table
2> Display
3> Insert
4> Delete
5> Modify
6> Search

Enter your choice 1

Enter name:PR
Enter roll no:10
Enter subject name:DS
Enter subject code:23
Enter internal assessment:45
Enter university marks:67

Enter name:PR2
Enter roll no:20
Enter subject name:CO
Enter subject code:44
Enter internal assessment:48
Enter university marks:71

Enter name:PR3
Enter roll no:30
Enter subject name:CG
Enter subject code:12
Enter internal assessment:46
Enter university marks:65


1> Build master table
2> Display
3> Insert
4> Delete
5> Modify
6> Search

Enter your choice 2

NAME    ROLL NO  SUBJECT  SUB CODE  INTERNAL    MARKS
-------------------------------------------------------
PR       10       DS       23        45          67
PR2      20       CO       44        48          71
PR3      30       CG       12        46          65



1> Build master table
2> Display
3> Insert
4> Delete
5> Modify
6> Search

Enter your choice 3

Enter name:PR4
Enter roll no:40
Enter subject name:M2
Enter subject code:89
Enter internal assessment:39
Enter university marks:62


1> Build master table
2> Display
3> Insert
4> Delete
5> Modify
6> Search

Enter your choice2

NAME    ROLL NO SUBJECT   SUB CODE  INTERNAL   MARKS
------------------------------------------------------
PR       10       DS       23        45          67
PR2      20       CO       44        48          71
PR3      30       CG       12        46          65
PR4      40       M2       89        39          62


1> Build master table
2> Display
3> Insert
4> Delete
5> Modify
6> Search

Enter your choice 4

enter loc at which record to be deleted 2

NAME    ROLL NO SUBJECT   SUB CODE  INTERNAL   MARKS
------------------------------------------------------
PR       10       DS       23        45          67
PR2      20       CO       44        48          71
PR3      30       CG       12        46          65

1> Build master table
2> Display
3> Insert
4> Delete
5> Modify
6> Search

Enter your choice 5

Enter which record to be editted 2

Enter name:PR6
Enter roll no:50
Enter subject name:MIT
Enter subject code:78
Enter internal assessment:47
Enter university marks:69

NAME    ROLL NO SUBJECT   SUB CODE  INTERNAL   MARKS
------------------------------------------------------
PR6  50      MIT       78        47         69

1> Build master table
2> Display
3> Insert
4> Delete
5> Modify
6> Search

Enter your choice 6

Enter record to be searched 3

Found Record

NAME    ROLL NO SUBJECT   SUB CODE  INTERNAL   MARKS
------------------------------------------------------
PR3   30       CG       12        46          65

1> Build master table
2> Display
3> Insert
4> Delete
5> Modify
6> Search

Enter your choice 7 */
read more

C++ program using function template to perform arithmatic operations

, by Prashant Gunjal


Write a program in C++ using function template to read two matrices of different data types such as integers and floating point values and perform simple arithmetic operations on these matrices separately and display it.



#include<iostream.h>
#include<conio.h>
template<class T>
class matrix
{
T x[3][3];
public:
void getmatrix();
void showmatrix();
void addition(matrix<T>);
void subtraction(matrix<T>);
void multiplication(matrix<T>,matrix<T>);
};
template<class T>
void matrix<T>::getmatrix()
{
int i,j;
cout<<"\n\n\t enter values of matrix";
for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
      {
cin>>x[i][j];
      }
  }
}
template<class T>
void matrix<T>::showmatrix()
{
int i,j;
cout<<"\n\n\t matrix is:";
for(i=0;i<3;i++)
  {
   cout<<"\n\n";
   for(j=0;j<3;j++)
      {
cout<<"\t"<<x[i][j];
      }
  }
}
template<class T>
void matrix<T>::addition(matrix<T> b)
{
int i,j;
for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
      {
x[i][j]=x[i][j]+b.x[i][j];
      }
   }
}
template<class T>
void matrix<T>::subtraction(matrix<T> b)
{
int i,j;
for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
      {
x[i][j]=x[i][j]-b.x[i][j];
      }
   }
}
template<class T>
void matrix<T>::multiplication(matrix<T> b,matrix<T> a)
{
int i,j,k;
for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
      {
x[i][j]=0;
      }
   }
for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
      {
for(k=0;k<3;k++)
  {
   x[i][j]=x[i][j]+(a.x[i][k]*b.x[k][j]);
  }
      }
   }
}
void main()
{
int ch;
matrix<int> a1,b1,c1;
matrix<float> a2,b2,c2;
clrscr();
do
 {
  cout<<"\n\n\t 1> Addition (int)";
  cout<<"\n\n\t 2> Subtraction (int)";
  cout<<"\n\n\t 3> Multiplication (int)";
  cout<<"\n\n\t 4> Addition (float)";
  cout<<"\n\n\t 5> Subtraction (float)";
  cout<<"\n\n\t 6> Multiplication (float)";
  cout<<"\n\n\t enter your choice";
  cin>>ch;
  switch(ch)
  {
  case 1:a1.getmatrix();
 a1.showmatrix();
 b1.getmatrix();
 b1.showmatrix();
 a1.addition(b1);
 a1.showmatrix();
 break;
  case 2:a1.getmatrix();
 a1.showmatrix();
 b1.getmatrix();
 b1.showmatrix();
 a1.subtraction(b1);
 a1.showmatrix();
 break;
  case 3:a1.getmatrix();
 a1.showmatrix();
 b1.getmatrix();
 b1.showmatrix();
 c1.multiplication(b1,a1);
 c1.showmatrix();
 break;
  case 4:a2.getmatrix();
 a2.showmatrix();
 b2.getmatrix();
 b2.showmatrix();
 a2.addition(b2);
 a2.showmatrix();
 break;
  case 5:a2.getmatrix();
 a2.showmatrix();
 b2.getmatrix();
 b2.showmatrix();
 a2.subtraction(b2);
 a2.showmatrix();
 break;
  case 6:a2.getmatrix();
 a2.showmatrix();
 b2.getmatrix();
 b2.showmatrix();
 c2.multiplication(b2,a2);
 c2.showmatrix();
 break;
  }
}while(ch!=7);
getch();
}
/* OUTPUT
1> Addition (int)
2> Subtraction (int)
3> Multiplication (int)
4> Addition (float)
5> Subtraction (float)
6> Multiplication (float)
enter your choice1
enter values of matrix 1 2 3 4 5 6 7 8 9
matrix is:

1       2       3
4       5       6
7       8       9
enter values of matrix 2 3 4 5 6 7 8 9 0
matrix is:

2       3       4
5       6       7
8       9       0
matrix is:
3       5       7
9       11      13
15      17      9

1> Addition (int)
2> Subtraction (int)
3> Multiplication (int)
4> Addition (float)
5> Subtraction (float)
6> Multiplication (float)
enter your choice 2

enter values of matrix 0 9 8 7 6 5 4 3 2
matrix is:

0       9       8
7       6       5
4       3       2

enter values of matrix 1 2 3 4 5 6 7 8 9
matrix is:
1       2       3
4       5       6
7       8       9

matrix is:
-1      7       5
3       1       -1
-3      -5      -7

1> Addition (int)
2> Subtraction (int)
3> Multiplication (int)
4> Addition (float)
5> Subtraction (float)
6> Multiplication (float)
enter your choice 3

enter values of matrix 1 2 3 4 5 6 7 8 9
matrix is:
1       2       3
4       5       6
7       8       9

enter values of matrix 2 3 4 5 6 7 8 9 0
matrix is:
2       3       4
5       6       7
8       9       0

matrix is:
36      42      18
81      96      51
126     150     84

1> Addition (int)
2> Subtraction (int)
3> Multiplication (int)
4> Addition (float)
5> Subtraction (float)
6> Multiplication (float)

enter your choice 4

enter values of matrix 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5
matrix is:
1.5     2.5     3.5
4.5     5.5     6.5
7.5     8.5     9.5

enter values of matrix 1.2 2.3 3.4 4.5 5.6 6.7 7.8 8.9 9.0
matrix is:
1.2     2.3     3.4
4.5     5.6     6.7
7.8     8.9     9

matrix is:
2.7     4.8     6.9
9       11.1    13.2
15.3    17.4    18.5

1> Addition (int)
2> Subtraction (int)
3> Multiplication (int)
4> Addition (float)
5> Subtraction (float)
6> Multiplication (float)
enter your choice 5

enter values of matrix 1.2 2.3 3.4 4.5 5.6 6.7 7.8 8.9 9.0
matrix is:
1.2     2.3     3.4
4.5     5.6     6.7
7.8     8.9     9

enter values of matrix 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9
matrix is:
1.1     2.2     3.3
4.4     5.5     6.6
7.7     8.8     9.9

matrix is:
0.1     0.1     0.1
0.1     0.1     0.1
0.1     0.09   -0.9

1> Addition (int)
2> Subtraction (int)
3> Multiplication (int)
4> Addition (float)
5> Subtraction (float)
6> Multiplication (float)
enter your choice 6

enter values of matrix 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9
matrix is:
1.1     2.2     3.3
4.4     5.5     6.6
7.7     8.8     9.9

enter values of matrix 1.2 2.3 3.4 4.5 5.6 6.7 7.8 8.9 9.0
matrix is:
1.2     2.3     3.4
4.5     5.6     6.7
7.8     8.9     9

matrix is:
36.959999       44.219997       48.18
81.510002       99.659996       111.20999
126.059998      155.099991      174.23999

1> Addition (int)
2> Subtraction (int)
3> Multiplication (int)
4> Addition (float)
5> Subtraction (float)
6> Multiplication (float)

enter your choice 7 */

read more

C++ program to implement concept of inheritance and perform basic operations on it

, by Prashant Gunjal


Design a base class with name,date of birth,blood group and another base class consisting of the data members such as height and weight.Design one more base class consisting of the insurance policy number and contact address.The derived class contains the data members telephone numbers and driving license number. Write a menu driven program to carry out the following things: i) Build a master table ii) Display iii) Insert a new entry iv) Delete entry v) Edit vi) Search for a record


#include<iostream.h>
#include<conio.h>
#include<string.h>

class a
{
private:
char *name,*date,*bg;
int len;
public:
a();
a(char*name1);
void create_a();
void display_a();


};
a::a()
{
this->name='\0';
this->date='\0';
this->bg='\0';
}
a::a(char * name1)
{
len=strlen(name1);
name=new char[len+1];
strcpy(name,name1);
cout<<"Parametrized const......";
}
void a::create_a()
{
char name1[20];
int len;
if(name=='\0')
{
cout<<"\nEnter name=> ";
cin>>name1;
len=strlen(name1);
name=new char[len+1];
strcpy(name,name1);
}
cout<<"\nEnter Date of Birth => ";
cin>>name1;
len=strlen(name1);
date=new char[len+1];
strcpy(date,name1);
cout<<"\nEnter Blood Group => ";
cin>>name1;
len=strlen(name1);
bg=new char[len+1];
strcpy(bg,name1);

}
void a::display_a()
{
     cout<<"\n"<<name<<"\t"<<date<<"  "<<bg;
}
class b
{
private:
float ht,wt;
public:
b();
void create_b();
void display_b();
};
b::b()
{
ht=wt=0.0;
}
void b::create_b()
{
cout<<"\nEnter Height => ";
cin>>ht;
cout<<"\nEnter Weight => ";
cin>>wt;

}
void b::display_b()
{
     cout<<"\t\t"<<ht<<"\t"<<wt;


}
class c
{
private:
long int incno,telno,licno,len;
public:
c();
void create_c();
void display_c();
};
c::c()
{
incno=telno=len=0;
}
void c::create_c()
{
cout<<"\nEnter Liscence no => ";
cin>>licno;
cout<<"\nEnter Incumtax  no => ";
cin>>incno;

}
void c::display_c()
{
     cout<<"\t"<<licno<<"\t"<<incno;
}
class info:public a,b,c
{
public:
info()
{
a();
b();
c();
}
void create();
void display();
inline void disp()
{
cout<<"\nEnter Record...";
}
friend void show()
{
cout<<"\nName\t\tBirth\tBloog group";
cout<<"  Height   Weight  LICno    INC";
}
};
void info::create()
{
   create_a();
   create_b();
   create_c();
}
void info::display()
{
display_a();
display_b();
display_c();
}
void main()
{
clrscr();
int ch,no,del,src;
info obj[20];
do
{
cout<<"\n1.Built Table\n2.Display\n3.Insert new\n4.Delete entry";
cout<<"\n5.Edit\n6.Search record\n7.Exit\nEnter choice no=";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\nEnter how many records ?= ";
cin>>no;
for(int i=0;i<no;i++)
{
obj[i].disp();cout<<i+1;
obj[i].create();
}
break;
case 2:
show();
for(i=0;i<no;i++)
obj[i].display();
break;
case 3:
obj[no].disp();cout<<"To insert at= "<<no+1;
obj[no].create();
no++;
break;
case 4:
cout<<"\nEnter record which to delete = ";
cin>>del;
for(i=del-1;i<no;i++)
{
obj[i]=obj[i+1];
}
no--;
break;
case 5:
cout<<"\nEnter record no to be modify : - ";
cin>>src;
cout<<"\nEnter new record with modification-> ";
obj[src-1].create();
break;
case 6:
cout<<"\nEnter enter search record no:- ";
cin>>src;
if(src<=no)
{
cout<<"\nSearch record :- ";
show();obj[src-1].display();
}
else
cout<<"\nNot present......";
break;
}
}while(ch!=7);
getch();
}
/*
OUTPUT

1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=1

Enter how many records ?= 2

Enter Record...1
Enter name=> Prashant

Enter Date of Birth => 17\02\92

Enter Blood Group => B+ve

Enter Height => 5.6

Enter Weight => 57

Enter Liscence no => 1234

Enter Incumtax  no => 3456

Enter Record...2
Enter name=> Rameshwar

Enter Date of Birth => 12\12\92

Enter Blood Group => O+ve

Enter Height => 6

Enter Weight => 60

Enter Liscence no => 1234

Enter Incumtax  no =>2345
1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=2

Name            Birth   Bloog group  Height   Weight  LICno    INC
Prashant        17\02\92  B+ve          5.6     57      1234    3456
Rameshwar       12\12\92  O+ve          6       60      1234    2345
1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=3

Enter Record...To insert at= 3
Enter name=> Ramakant

Enter Date of Birth => 13\05\91

Enter Blood Group => O-ve

Enter Height => 6

Enter Weight => 80

Enter Liscence no => 5678

Enter Incumtax  no => 5678

1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=2

Name            Birth   Bloog group  Height   Weight  LICno    INC
Prashant        17\02\92  B+ve          5.6     57      1234    3456
Rameshwar       12\12\92  O+ve          6       60      1234    2345
Ramakant        13\05\91  O-ve          6       80      5678    5678
1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=4

Enter record which to delete = 2

1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=2

Name            Birth   Bloog group  Height   Weight  LICno    INC
Prashant        17\02\92  B+ve          5.6     57      1234    3456
Ramakant        13\05\91  O-ve          6       80      5678    5678
1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=5

Enter record no to be modify : - 2

Enter new record with modification->
Enter Date of Birth => 12\12\92

Enter Blood Group => O+ve

Enter Height => 5.2

Enter Weight => 60

Enter Liscence no => 1100

Enter Incumtax  no => 2222

1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=2

Name            Birth   Bloog group  Height   Weight  LICno    INC
Prashant        17\02\92  B+ve          5.6     57      1234    3456
Ramakant        12\12\92  O+ve          5.2     60      1100    2222
1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=6

Enter enter search record no:- 3

Not present......
1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=6

Enter enter search record no:- 2

Search record :-
Name            Birth   Bloog group  Height   Weight  LICno    INC
Ramakant        12\12\92  O+ve          5.2     60      1100    2222
1.Built Table
2.Display
3.Insert new
4.Delete entry
5.Edit
6.Search record
7.Exit
Enter choice no=7

*/
read more

C++ program to perform String operations

, by Prashant Gunjal

Write a C++ program to perform String operations i. = Equality ii. == String Copy iii. + Concatenation iv. << To display a string v. >> To reverse a string vi. Function to determine whether a string is a palindrome To find occurrence of a sub-string. Use Operator Overloading


#include<iostream.h>
#include<conio.h>

class string
{
private:
char str[10];
public:
char str1[20];
void accept();
void operator<<(string s2);//display
void operator>>(string & str);//reverse
void operator+(string &s1); //concate
void operator=(string s2);//equality
void operator==(string & s3);//copy
};
void string::accept()
{
cout<<"\nEnter string :=> ";
cin>>str1;
}
void string::operator<<(string s2)
{
cout<<"\nString1=>"<<str1;
cout<<"\nString2=>"<<s2.str1;
}
void string::operator>>(string & str)
{
int i=0,j=0;
char t;
while(str.str1[i]!='\0')
i++;
i--;
while(i>j)
{
t=str.str1[i];
str.str1[i]=str.str1[j];
str.str1[j]=t;
i--;
j++;
}
}
void string::operator+(string &s1)
{
int i=0,j=0;
while(s1.str1[i]!='\0')
i++;
while(str1[j]!='\0')
{
s1.str1[i]=str1[j];
i++;
j++;
}
s1.str1[i]='\0';
}
void string::operator=(string s2)
{
int i=0;
while(str1[i]!='\0'&&s2.str1[i]!='\0')
{
if(str1[i]!=s2.str1[i])
{
cout<<"\nNot equal";
break;
}
i++;
}
if(str1[i]=='\0'&&s2.str1[i]=='\0')
cout<<"Strings are equal";
}
void string::operator==(string & s3)
{
int i=0;
while(str1[i]!='\0')
{
s3.str1[i]=str1[i];
i++;
}
s3.str1[i]='\0';
}
void main()
{
clrscr();
int ch;
string s1,s2,s3;
do
{
cout<<"\n\n1.Accept strings\n2.Display\n3.Reverse string\n4.Concatinate";
cout<<"\n5.Check equality\n6.Copy\n7.Exit";
cout<<"\nEnter choice no= ";cin>>ch;
switch(ch)
{
case 1:
s1.accept();
s2.accept();
break;
case 2:
cout<<"\nDisplay.....";
s1<<s2;
break;
case 3:
cout<<"\nReverse IInd str ......";
s1>>s2;
s1<<s2;
break;
case 4:
cout<<"\nConcatinate......";
s2+s1;
cout<<"\nString="<<s1.str1;
break;
case 5:
s1=s2;
break;
case 6:
s1==s3;
cout<<"\nCopied string = >"<<s3.str1;
break;
}
}while(ch!=7);
getch();
}

OUTPUT :

1.Accept strings
2.Display
3.Reverse string
4.Concatinate
5.Check equality
6.Copy
7.Exit
Enter choice no= 1

Enter string :=> abc

Enter string :=> xyz

1.Accept strings
2.Display
3.Reverse string
4.Concatinate
5.Check equality
6.Copy
7.Exit
Enter choice no= 2


Display.....
String1=>abc
String2=>xyz

1.Accept strings
2.Display
3.Reverse string
4.Concatinate
5.Check equality
6.Copy
7.Exit
Enter choice no= 3

Reverse IInd str ......
String1=>abc
String2=>zyx

1.Accept strings
2.Display
3.Reverse string
4.Concatinate
5.Check equality
6.Copy
7.Exit
Enter choice no= 4

Concatinate......
String=abczyx
1.Accept strings
2.Display
3.Reverse string
4.Concatinate
5.Check equality
6.Copy
7.Exit
Enter choice no= 5

Not equal
1.Accept strings
2.Display
3.Reverse string
4.Concatinate
5.Check equality
6.Copy
7.Exit
Enter choice no= 6

Copied string = >abczyx

1.Accept strings
2.Display
3.Reverse string
4.Concatinate
5.Check equality
6.Copy
7.Exit
Enter choice no= 7
read more

C++ program to perform arithmatic operations on complex numbers

, by Prashant Gunjal

Design a Class ‘Complex ‘ with data members for real and imaginary part. Provide default and parametrized constructors.Write a program to perform arithmetic operations of two complex numbers using operator overloading (using either member functions or friend functions).


#include<iostream.h>
#include<conio.h>

class comp
{
private:
int r,i;
public:
comp()
{
r=i=0;
}
void create();
void display();
comp operator+(comp c2);
comp operator-(comp c2);
comp operator*(comp c2);
};
void comp::create()
{
cout<<"\nEnter real part=>";
cin>>r;
cout<<"\nEnter imaginary part=> ";
cin>>i;
}
void comp::display()
{
cout<<"\n\tno =>"<<r<<"+"<<i<<"i";
}
comp comp::operator+(comp c2)
{
comp c3;
c3.r=r+c2.r;
c3.i=i+c2.i;
return c3;
}
comp comp::operator*(comp c2)
{
comp c3;
c3.r=r*c2.r;
c3.i=i*c2.i;
return c3;
}
comp comp::operator-(comp c2)
{
comp c3;
c3.r=r-c2.r;
c3.i=i-c2.i;
return c3;
}

void main()
{
clrscr();
comp c1,c2,add,sub,mul;
cout<<"\nEnter no1=>";
c1.create();
cout<<"\nEnter no2=>";
c2.create();
cout<<"\nYour c1";
c1.display();
cout<<"\nYour c2";
c2.display();
add=c1+c2;
cout<<"\nAddition";
add.display();
sub=c1-c2;
cout<<"\nSubtraction";
sub.display();
mul=c1*c2;
cout<<"\nMultiplication";
mul.display();
getch();
}

OUTPUT :

Enter no1=>
Enter real part=>12

Enter imaginary part=> 13

Enter no2=>
Enter real part=>14

Enter imaginary part=> 15

Your c1
        no =>12+13i
Your c2
        no =>14+15i
Addition
        no =>26+28i
Subtraction
        no =>-2+-2i
Multiplication
        no =>168+195i
read more

Object oriented program in C++ to create a database of the personnel information system

, by Prashant Gunjal

Develop an object oriented program in C++ to create a database of the personnel information system containing the following information: Name,Date of Birth,Blood group,Height,Weight,Insurance Policy number,Contact address,telephone number,driving license no. etc Construct the database with suitable member functions for initializing and destroying the data viz constructor,default constructor,copy constructor,destructor,static member functions,friend class,this pointer,inline code and dynamic memory allocation operators-new and delete.


CPP program :


#include<iostream.h>
#include<conio.h>
#include<string.h>

class info
{
private:
char *name,*date,*add,*bg;
float ht,wt;
long int incno,telno,licno,len;
public:
info();
info(char*name1);
void create();
void display();
inline void disp()
{
cout<<"\nEnter Record.........";
}
friend void show()
{
cout<<"\nName\t\tAddress \tBirth  Bloog group";
cout<<"  Height   Weight  LICno INC";
}
};
info::info()
{
static int cnt=0;
cout<<"\nStatic Count is ="<<cnt;
cnt++;
cout<<"\nCount="<<cnt;
cout<<"\nDefault constructor.......";
this->ht=0;
this->licno=0;
this->name='\0';
this->date='\0';
this->add='\0';
this->bg='\0';
this->len=0;
}
info::info(char * name1)
{
len=strlen(name1);
name=new char[len+1];
strcpy(name,name1);
cout<<"Parametrized const......";
}
void info::create()
{
char name1[20];
int len;
if(name=='\0')
{
cout<<"\nEnter name=> ";
cin>>name1;
len=strlen(name1);
name=new char[len+1];
strcpy(name,name1);
}
cout<<"\nEnter Date of Birth => ";
cin>>name1;
len=strlen(name1);
date=new char[len+1];
strcpy(date,name1);
cout<<"\nEnter address => ";
cin>>name1;
len=strlen(name1);
add=new char[len+1];
strcpy(add,name1);
cout<<"\nEnter teliphone no=> ";
cin>>telno;
cout<<"\nEnter Blood Group => ";
cin>>name1;
len=strlen(name1);
bg=new char[len+1];
strcpy(bg,name1);
cout<<"\nEnter Height => ";
cin>>ht;
cout<<"\nEnter Weight => ";
cin>>wt;
cout<<"\nEnter Liscence no => ";
cin>>licno;
cout<<"\nEnter Incumtax  no => ";
cin>>incno;

}
void info::display()
{
     cout<<"\n"<<name<<"\t"<<add<<"\t"<<date<<"  "<<bg;
     cout<<"\t\t"<<ht<<"\t"<<wt<<"\t"<<licno<<"\t"<<incno;


}
void main()
{
clrscr();
info obj1,obj,a,b,c;
obj1.disp();
obj1.create();
info obj2("Rameshwar");
obj2.disp();
obj2.create();
show();
obj1.display();
obj2.display();
getch();
}

OUTPUT :




Static Count is =1
Default constructor.......
Static Count is =2
Default constructor.......
Static Count is =3
Default constructor.......
Static Count is =4
Default constructor.......
Static Count is =5
Default constructor.......
Enter Record.........
Enter name=> prashant

Enter Date of Birth => 2/12/1992

Enter address => khandgoan

Enter teliphone no=> 123456

Enter Blood Group => b+ve

Enter Height => 5.6

Enter Weight => 57

Enter Liscence no => 123

Enter Incumtax  no => 345
Parametrized const......
Enter Record.........
Enter Date of Birth => 2/10/1991

Enter address => karvenagar

Enter teliphone no=> 123457

Enter Blood Group => o+ve

Enter Height => 5.5

Enter Weight => 56

Enter Liscence no => 345

Enter Incumtax  no => 7890

Name            Address         Birth  Blood group  Height   Weight  LICno  INC
prashant        khandgoan       2/12/1992  b+ve         5.6     57      123       345
Rameshwar       karvenagar      2/10/1991  o+ve         5.5     56      345   7890


read more