0% found this document useful (0 votes)
3 views5 pages

My Two C-- Program Using Classes, Objects and Functions From My Local Community

The document contains two C++ programs designed for a local community in Sierra Leone. The first program manages a local sports club with functionalities for adding members and activities, while the second program organizes cultural events by managing participants. Both programs utilize classes, objects, and user input to enhance interactivity.

Uploaded by

manbudukamara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

My Two C-- Program Using Classes, Objects and Functions From My Local Community

The document contains two C++ programs designed for a local community in Sierra Leone. The first program manages a local sports club with functionalities for adding members and activities, while the second program organizes cultural events by managing participants. Both programs utilize classes, objects, and user input to enhance interactivity.

Uploaded by

manbudukamara
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Name: Mandudu Kamara

ID: 23/CS/TEC/130
Department: Computer science
Level: Degree year two(2)

Assignment
Create two C++ programs with classes, objects and functions. The program should be real
life example from something in a local community with Sierra Leone and you should prompt
users for inputs instead of using constants.

First Program
Local Sports Club Management

#include <iostream>
#include <vector>
#include <string>

using namespace std;

class Activity {
public:
string name;

Activity(string n) : name(n) {}
};

class Member {
public:
string name;
vector<Activity> activities;

Member(string n) : name(n) {}

void addActivity() {
string activityName;
cout << "Enter the name of the activity: ";
getline(cin, activityName);

activities.push_back(Activity(activityName));
cout << "Activity added successfully! ";
}

void displayActivities() {
cout << " Activities for Member " << name << endl;
for (const auto& activity : activities) {
cout << "Activity: " << activity.name <<endl;
}
}
};

class SportsClub {
private:
vector<Member> members;

public:
void addMember() {
string memberName;
cout << " Enter the name of the member: ";
getline(cin, memberName);

members.push_back(Member(memberName));
cout << " Member added successfully! ";
}

void manageMemberActivities() {
string memberName;
cout << " Enter the name of the member to manage activities: ";
getline(cin, memberName);

for (auto& member : members) {


if (member.name == memberName) {
member.addActivity();
return;
}
}
cout << " Member not found. ";
}

void displayAllActivities() {
for (const auto& member : members) {
member.displayActivities();
}
}
};

int main() {
SportsClub club;
int choice;

do {
cout << " Add a Member, Manage Member Activities, Display All Activities, Exit";
cout << " Choose an option: ";
cin >> choice;
cin.ignore(); // clear the input buffer
switch (choice) {
case 1:
club.addMember();
break;
case 2:
club.manageMemberActivities();
break;
case 3:
club.displayAllActivities();
break;
case 4:
cout << " Exiting “;
break;
default:
cout << " Invalid choice. Please try again ” ;
}
} while (choice != 4);

return 0;
}

Program two(2)
Local Cultural Event Organizer

#include <iostream>
#include <vector>
#include <string>
using namespace std;

class EventParticipant {
public:
string name;
string role; // e.g., Performer, Attendee

EventParticipant(string n, string r) : name(n), role(r) {}


};

class CulturalEvent {
public:
string title;
vector<EventParticipant> participants;

CulturalEvent(string t) : title(t) {}

void addParticipant() {
string name, role;
cout << "Enter the name of the participant:";
getline(cin, name);
cout << "Enter the role of the participant: ";
getline(cin, role);

participants.push_back(EventParticipant(name, role));
cout << " Participant added successfully! ";
}

void displayParticipants() {
cout << " Participants in the event '" << title <<endl;
for (const auto& participant : participants) {
cout << " Name: " << participant.name << ", Role: " << participant.role <<endl;
}
}
};

class EventOrganizer {
private:
vector<CulturalEvent> events;

public:
void addEvent() {
string title;
cout << " Enter the title of the cultural event: ";
getline(cin, title);

events.push_back(CulturalEvent(title));
cout << " Event added successfully! ";
}

void manageEventParticipants() {
string title;
cout << "Enter the title of the event to manage participants: ";
getline(cin, title);

for (auto& event : events) {


if (event.title == title) {
event.addParticipant();
return;
}
}
cout << "Event not found.";
}

void displayAllParticipants() {
for (const auto& event : events) {
event.displayParticipants();
}
}
};

int main() {
EventOrganizer organizer;
int choice;

do {
cout << " Add a Cultural Event . Manage Event Participants . Display All Participants.
Exit ";
cout << "Choose an option: ";
cin >> choice;
cin.ignore(); // clear the input buffer

switch (choice) {
case 1:
organizer.addEvent();
break;
case 2:
organizer.manageEventParticipants();
break;
case 3:
organizer.displayAllParticipants();
break;
case 4:
cout << "Exiting ";
break;
default:
cout << "Invalid choice. Please try again “;
}
} while (choice != 4);

return 0;
}

You might also like