-
Notifications
You must be signed in to change notification settings - Fork 0
/
12.cpp
115 lines (85 loc) · 1.94 KB
/
12.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
@Author: Amritanshu Sikdar
Session: 2018-'19
Repository: https://github.com/amritanshusikdar/CS30PracticalQuestion
*/
// Program to calculate total amount collected in class Travel
#include <iostream.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#define PEOPLE 5
void line(); // Prototype
int i=0; // Global variable 'i'
class travel
{
private:
char name[PEOPLE][20], vip[PEOPLE];
int people, amount;
public:
travel() // Constructor
{
strcpy(name[i],"NULL");
vip[i] = 'n'; // NO
people = amount = 0;
}
void input()
{
cout << "Name: ";
gets(name[i]);
cout << "VIP(y/n): ";
cin >> vip[i];
if(vip[i] == 'y' || vip[i] == 'Y') isVIP();
else notVIP();
}
void isVIP()
{
people++;
}
void notVIP()
{
people++;
amount += 50;
}
void showAll()
{
cout << name[i] << "\t\t";
if(vip[i] == 'n' || vip[i] == 'N')
cout << "No" << endl;
else
cout << "Yes" << endl;
}
int getPeople(){return people;}
int getAmount(){return amount;}
~travel(){}; // Deconstructor
};
// Globally declared
travel fare;
void main()
{
clrscr();
for(i=0; i<PEOPLE; i++)
{
fare.input();
}
// Displaying the contents
line();
cout << "S.No.\tName\t\tVIP\n";
line();
for (i = 0; i < PEOPLE; i++)
{
cout << i+1 << '\t';
fare.showAll();
}
line();
cout << "Total people visited: " << fare.getPeople() << endl;
cout << "Total amount collected: " << fare.getAmount() << endl;
line();
getch();
}
void line()
{
for (int i = 0; i < 40; i++)
cout << '-';
cout << endl;
}