0% found this document useful (0 votes)
21 views3 pages

Bhatt Project of CPP

This C++ program allows users to manage a list of members by adding, removing, and displaying their details. It defines a Member struct to store each member's name, age, and ID. It includes functions to add a new member by prompting for their details, remove a member by ID, and display the full member list. The main function offers a menu to call these functions in a loop until the user selects the exit option.

Uploaded by

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

Bhatt Project of CPP

This C++ program allows users to manage a list of members by adding, removing, and displaying their details. It defines a Member struct to store each member's name, age, and ID. It includes functions to add a new member by prompting for their details, remove a member by ID, and display the full member list. The main function offers a menu to call these functions in a loop until the user selects the exit option.

Uploaded by

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

1: #include <iostream>

2: #include <cstring>
3: using namespace std;
4: struct Member {
5: char name[50];
6: int age;
7: int id;
8: };
9: void addMember(Member *members, int *count)
10: {
11: cout << "Enter name: ";
12: cin >> members[*count].name;
13: cout << "Enter age: ";
14: cin >> members[*count].age;
15: members[*count].id = *count + 1;
16: *count += 1;
17: cout << "Member added successfully!\n";
18: }
19: void removeMember(Member *members, int *count, int id)
20: {
21: bool found = false;
22: for (int i = 0; i < *count; i++)
23: {
24: if (members[i].id == id)
25: {
26: found = true;
27: for (int j = i; j < *count - 1; j++)
28: {
29: strcpy(members[j].name, members[j+1].name);
30: members[j].age = members[j+1].age;
31: members[j].id = members[j+1].id - 1;
32: }
33: *count -= 1;
34: cout << "Member removed successfully!\n";
35: break;
36: }
37: }
38: if (!found)
39: {
40: cout << "Member not found!\n";
41: }
42: }
43: void displayMembers(Member *members, int *count)
44: {
45: cout << "List of Members:\n";
46: for (int i = 0; i < *count; i++)
47: {
48: cout << "ID: " << members[i].id << endl;
49: cout << "Name: " << members[i].name << endl;
50: cout << "Age: " << members[i].age << endl;
51: }
52: }
53: int main()
54: {
55: Member members[100];
56: int count = 0;
57: int choice, id;
58: do
59: {
60: cout << "Enter your choice:\n";
61: cout << "1. Add Member\n";
62: cout << "2. Remove Member\n";
63: cout << "3. Display Members\n";
64: cout << "4. Exit\n";
65: cin >> choice;
66: switch (choice)
67: {
68: case 1:
69: addMember(members, &count);
70: break;
71: case 2:
72: cout << "Enter ID of member to remove: ";
73: cin >> id;
74: removeMember(members, &count, id);
75: break;
76: case 3:
77: displayMembers(members, &count);
78: break;
79: case 4:
80: cout << "Exiting program...\n";
81: break;
82: default:
83: cout << "Invalid choice!\n";
84: break;
85: }
86: }
87: while (choice != 4);
88: return 0;
89: }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy