Skip to content

Commit 44b6440

Browse files
committed
OOP2 Lab 3 updated
1 parent 832197c commit 44b6440

File tree

3 files changed

+105
-47
lines changed

3 files changed

+105
-47
lines changed

OOP2_Lab3/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Practical Lab Assignment - Const member function, friend function, composition, friend functions and `this` pointer
2+
3+
**Note: In class diagram + for public, - for private.**
4+
5+
6+
### Program 1
7+
Define a class FullName and Player with the following specifications:
8+
9+
```
10+
FullName
11+
---
12+
- FirstName: string
13+
- MiddleName: string
14+
- LastName: string
15+
---
16+
<<constructor>> + FullName()
17+
<<destructor>> +~ FullName()
18+
+ setFirstName(string)
19+
+ getFirstName(): string
20+
+ setMiddleName(string)
21+
+ getMiddleName(): string
22+
+ setLastName(string)
23+
+ getLastName(): string
24+
```
25+
```
26+
Player
27+
---
28+
-Player_ID: string
29+
-Player_Name: FullName
30+
-Matches_Played: int
31+
-Goals_Scored: int
32+
---
33+
<<constructor>> + Player()
34+
<<destructor>> +~ Player()
35+
+ setPlayer_ID(string)
36+
+ getPlayer_ID(): string
37+
+ setMatches_Played(int)
38+
+ getMatches_Played(): int
39+
+ setGoals_Scored(int)
40+
+ getGoals_Scored(): int
41+
+ setPlayer_Name(FullName)
42+
+ getPlayer_Name()
43+
<<friend>> + Increase_GoalsScored(Player, int)
44+
```
45+
46+
`Increase_GoalsScored(int)` is friend function for Player: This function will increase Goal_scored by some int every time when called.
47+
48+
Write C++ create object pointer(through new) to Class Player and menu driven program to add player details (allocate memory for object and get player details), display player details, increase player goal scored delete player from memory.
-17.4 KB
Binary file not shown.

OOP2_Lab3/main.cpp

Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,48 @@
33
#include <string>
44
using namespace std;
55

6-
class FullName
6+
class FullName
77
{
88
public:
9-
10-
FullName() {
9+
FullName()
10+
{
1111
FirstName = "Rustam";
1212
MiddleName = "Zokirov";
1313
LastName = "Ibrohimovich";
1414
}
1515

16-
FullName(string fName, string mName, string lName ){
16+
FullName(string fName, string mName, string lName)
17+
{
1718
fName = FirstName;
1819
mName = MiddleName;
1920
lName = LastName;
2021
}
21-
void setFirstName(string f_Name) {
22+
void setFirstName(string f_Name)
23+
{
2224
FirstName = f_Name;
2325
}
24-
string getFirstName() {
26+
string getFirstName()
27+
{
2528
return FirstName;
2629
}
27-
void setMiddleName(string m_Name) {
30+
void setMiddleName(string m_Name)
31+
{
2832
MiddleName = m_Name;
2933
}
30-
string getMiddleName() {
34+
string getMiddleName()
35+
{
3136
return MiddleName;
3237
}
33-
void setLastName(string l_Name) {
38+
void setLastName(string l_Name)
39+
{
3440
LastName = l_Name;
3541
}
36-
string getLastName() {
42+
string getLastName()
43+
{
3744
return LastName;
3845
}
39-
40-
private:
46+
47+
private:
4148
string FirstName;
4249
string MiddleName;
4350
string LastName;
@@ -50,62 +57,69 @@ class Player
5057
int Matches_Played;
5158
FullName Player_Name;
5259

53-
5460
public:
55-
5661
static int Goals_Scored;
5762

58-
Player() {
63+
Player()
64+
{
5965
Player_ID = "U1910049";
6066
Matches_Played = 100;
6167
}
62-
Player(string id, int matches, int goals) {
68+
Player(string id, int matches, int goals)
69+
{
6370
Player_ID = id;
6471
Matches_Played = matches;
65-
}
66-
void setPlayer_ID(string ID) {
72+
}
73+
void setPlayer_ID(string ID)
74+
{
6775
Player_ID = ID;
6876
}
69-
string getPlayer_ID() {
77+
string getPlayer_ID()
78+
{
7079
return Player_ID;
7180
}
72-
void setMatches_Played(int Matches) {
81+
void setMatches_Played(int Matches)
82+
{
7383
Matches_Played = Matches;
7484
}
75-
int getMatches_Played() {
85+
int getMatches_Played()
86+
{
7687
return Matches_Played;
7788
}
78-
/* void setGoals_Scored(int Goals) {
79-
Matches_Played = Goals;
80-
}
81-
int getGoals_Scored() {
82-
return Goals_Scored;
83-
}*/
89+
/* void setGoals_Scored(int Goals) {
90+
Matches_Played = Goals;
91+
}
92+
int getGoals_Scored() {
93+
return Goals_Scored;
94+
}*/
8495
friend void Increse_GoalScored(Player);
8596
};
8697

8798
int Player::Goals_Scored;
88-
void Increse_GoalScored(Player player1) {
99+
void Increse_GoalScored(Player player1)
100+
{
89101
player1.Goals_Scored++;
90102
}
91103

92-
93104
int main()
94105
{
95106
int choice;
96107
while (1)
97108
{
98109

99-
string firstName,middleName,lastName;
110+
string firstName, middleName, lastName;
100111
FullName fullName1;
101112
// 2
102113
string Id;
103114
int goals, matches;
104115
Player player1;
105116
cout << "Add: First Name, Middle Name, Last Name: \n\n";
106-
cout << "First Name: \n"; cin >> firstName;
107-
cout << "Middle Name: \n"; cin >> middleName;
108-
cout << "Last Name:\n "; cin >> lastName;
117+
cout << "First Name: \n";
118+
cin >> firstName;
119+
cout << "Middle Name: \n";
120+
cin >> middleName;
121+
cout << "Last Name:\n ";
122+
cin >> lastName;
109123

110124
FullName fullName(firstName, middleName, lastName);
111125
fullName.setFirstName(firstName);
@@ -121,20 +135,20 @@ int main()
121135
cout << "Your Choice: ";
122136

123137
cin >> choice;
124-
switch (choice)
138+
switch (choice)
125139
{
126140
case 1:
127141
system("cls");
128142
cout << "We have entered in the beginning!" << endl;
129-
//fullName.setFirstName(firstName);
130-
//fullName.setMiddleName(middleName);
131-
//fullName.setLastName(lastName);
132-
/* FullName fullName(firstName, middleName, lastName);
133-
fullName.setFirstName(firstName);
134-
fullName.setMiddleName(middleName);
135-
fullName.setLastName(lastName);*/
143+
// fullName.setFirstName(firstName);
144+
// fullName.setMiddleName(middleName);
145+
// fullName.setLastName(lastName);
146+
/* FullName fullName(firstName, middleName, lastName);
147+
fullName.setFirstName(firstName);
148+
fullName.setMiddleName(middleName);
149+
fullName.setLastName(lastName);*/
136150

137-
break;
151+
break;
138152
case 2:
139153
system("cls");
140154
cout << "Details of the Player: \n";
@@ -146,22 +160,18 @@ int main()
146160
player1.setMatches_Played(matches);
147161
cout << endl;
148162
cout << player1.getPlayer_ID();
149-
150163
cout << fullName.getFirstName() << " " << fullName.getLastName() << " " << fullName.getMiddleName() << endl;
151-
152164
cout << player1.getMatches_Played();
153-
154165
break;
155166
case 3:
156167
system("cls");
157168
cout << "Number of goals: \n";
158169
Increse_GoalScored(player1);
159-
break;
170+
break;
160171
case 4:
161172
system("cls");
162173
cout << "Deletion for finished successfully! \n";
163174
break;
164-
165175
case 5:
166176
system("exit");
167177
}

0 commit comments

Comments
 (0)