C++ & Java : Assignment 3
Hello friends, this is the 3rd assignment of C++. I will post the others soon.
1)Cricket
#include
#include
#include
#include
class cricket
{
char name[20];
char team[10];
float average;
public:
void read(void);
void disp(void);
};
void cricket::read()
{
cout<<"\nEnter the name of the player: ";
cin >> name;
cout << "Enter the team: ";
cin >> team;
cout << "Enter batting average: ";
cin >> average;
}
void cricket::disp()
{
cout << name << "\t" << team << "\t" << average << "\n";
}
int main()
{
cricket player[10];
int i;
for(i=1;i<11;i++)
{
player[i].read();
}
cout << "\n\n";
for(i=1;i<11;i++)
{
player[i].disp();
}
getch();
return 0;
}
2) Cricket with Constructors
#include
#include
#include
#include
class cricket
{
char name[20];
char team[10];
float average;
public:
cricket()
{
cout<<"\nEnter the name of the player: ";
cin >> name;
cout << "Enter the team: ";
cin >> team;
cout << "Enter batting average: ";
cin >> average;
}
void disp()
{
cout << name << "\t" << team << "\t" << average << "\n";
}
};
int main()
{
cricket player[8];
int i;
for(i=1;i<9;i++)
{
player[i].disp();
}
getch();
return 0;
}
3) Publication program
#include
#include
#include
#include
class publication
{
public:
char title[20];
float price;
publication()
{
cout << "\nEnter the title: ";
cin >> title;
cout << "Enter the price: ";
cin >> price;
}
void display()
{
cout << "\n\nTitle: " << title << "\nPrice: " << price;
}
};
class book:public publication
{
public:
int pagecount;
book():publication()
{
cout << "Enter the number of pages: ";
cin >> pagecount;
}
void display()
{
cout << "\n\nTitle: " << title << "\nPrice: " << price;
cout << "\nNo. of pages: " << pagecount;
}
};
class tape:public publication
{
public:
float playtime;
tape():publication()
{
cout << "Enter the playtime: ";
cin >> playtime;
}
void display()
{
cout << "\n\nTitle: " << title << "\nPrice: " << price;
cout << "\nNo. of Minutes: " << playtime;
}
};
int main()
{
book b1;
tape t1;
b1.display();
t1.display();
getch();
return 0;
}
1)Cricket
#include
#include
#include
#include
class cricket
{
char name[20];
char team[10];
float average;
public:
void read(void);
void disp(void);
};
void cricket::read()
{
cout<<"\nEnter the name of the player: ";
cin >> name;
cout << "Enter the team: ";
cin >> team;
cout << "Enter batting average: ";
cin >> average;
}
void cricket::disp()
{
cout << name << "\t" << team << "\t" << average << "\n";
}
int main()
{
cricket player[10];
int i;
for(i=1;i<11;i++)
{
player[i].read();
}
cout << "\n\n";
for(i=1;i<11;i++)
{
player[i].disp();
}
getch();
return 0;
}
2) Cricket with Constructors
#include
#include
#include
#include
class cricket
{
char name[20];
char team[10];
float average;
public:
cricket()
{
cout<<"\nEnter the name of the player: ";
cin >> name;
cout << "Enter the team: ";
cin >> team;
cout << "Enter batting average: ";
cin >> average;
}
void disp()
{
cout << name << "\t" << team << "\t" << average << "\n";
}
};
int main()
{
cricket player[8];
int i;
for(i=1;i<9;i++)
{
player[i].disp();
}
getch();
return 0;
}
3) Publication program
#include
#include
#include
#include
class publication
{
public:
char title[20];
float price;
publication()
{
cout << "\nEnter the title: ";
cin >> title;
cout << "Enter the price: ";
cin >> price;
}
void display()
{
cout << "\n\nTitle: " << title << "\nPrice: " << price;
}
};
class book:public publication
{
public:
int pagecount;
book():publication()
{
cout << "Enter the number of pages: ";
cin >> pagecount;
}
void display()
{
cout << "\n\nTitle: " << title << "\nPrice: " << price;
cout << "\nNo. of pages: " << pagecount;
}
};
class tape:public publication
{
public:
float playtime;
tape():publication()
{
cout << "Enter the playtime: ";
cin >> playtime;
}
void display()
{
cout << "\n\nTitle: " << title << "\nPrice: " << price;
cout << "\nNo. of Minutes: " << playtime;
}
};
int main()
{
book b1;
tape t1;
b1.display();
t1.display();
getch();
return 0;
}