// C++ Example - Game Lobby
#include <iostream>
#include <string>
using namespace std;
class Player {
public:
Player(const string& name = "");
string GetName() const;
Player* GetNext() const;
void SetNext(Player* next);
private:
string m_Name;
Player* m_pNext;
};
Player::Player(const string& name) : m_Name(name), m_pNext(0) {}
string Player::GetName() const {
return m_Name;
}
Player* Player::GetNext() const {
return m_pNext;
}
void Player::SetNext(Player* next) {
m_pNext = next;
}
class Lobby {
friend ostream& operator<<(ostream& os, const Lobby& aLobby);
public:
Lobby();
~Lobby();
void AddPlayer();
void RemovePlayer();
void searchplayer();
void Clear();
private:
Player* m_pHead;
};
Lobby::Lobby() : m_pHead(0) {}
Lobby::~Lobby() {
Clear();
}
void Lobby::AddPlayer() {
cout << "Please enter the name of the new player: ";
string name;
cin >> name;
Player* pNewPlayer = new Player(name);
if (m_pHead == 0) {
m_pHead = pNewPlayer;
} else {
Player* pIter = m_pHead;
while (pIter->GetNext() != 0) {
pIter = pIter->GetNext();
}
pIter->SetNext(pNewPlayer);
}
}
void Lobby::RemovePlayer() {
if (m_pHead == 0) {
cout << "The game lobby is empty. No one to remove!\n";
} else {
Player* pTemp = m_pHead;
m_pHead = m_pHead->GetNext();
delete pTemp;
}
}
void Lobby::Clear() {
while (m_pHead != 0) {
RemovePlayer();
}
}
ostream& operator<<(ostream& os, const Lobby& aLobby) {
Player* pIter = aLobby.m_pHead;
os << "\nHere's who's in the game lobby:\n";
if (pIter == 0) {
os << "The lobby is empty.\n";
} else {
while (pIter != 0) {
os << pIter->GetName() << endl;
pIter = pIter->GetNext();
}
}
return os;
}
void Lobby::searchplayer() {
string searchname;
cout << "Enter name to search: ";
cin >> searchname;
Player* iter = m_pHead;
bool found = false;
while (iter != 0) {
if (iter->GetName() == searchname) {
found = true;
break;
}
iter = iter->GetNext();
}
if (found) {
cout << "Player Found!!!\n";
} else {
cout << "Player Not Found!!\n";
}
}
int main() {
Lobby myLobby;
int choice;
do {
cout << myLobby;
cout << "\nGAME LOBBY\n";
cout << "0 - Exit the program.\n";
cout << "1 - Add a player to the lobby.\n";
cout << "2 - Remove a player from the lobby.\n";
cout << "3 - Clear the lobby.\n";
cout << "4 - Search lobby.\n";
cout << "Enter choice: ";
cin >> choice;
switch (choice) {
case 0: cout << "Good-bye.\n"; break;
case 1: myLobby.AddPlayer(); break;
case 2: myLobby.RemovePlayer(); break;
case 3: myLobby.Clear(); break;
case 4: myLobby.searchplayer(); break;
default: cout << "That was not a valid choice.\n";
}
} while (choice != 0);
return 0;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Gunter,Colt Mardi Gras Store</title>
<link rel="icon" href="images/faviconMG.ico" type="image/x-icon">
<link rel="stylesheet" href="styles/normalize.css">
<link rel="stylesheet" href="styles/main.css">
</head>
<body>
<header>
<img src="images/MardiGrasLogo.png" alt="Mardi Gras Logo">
<h2>Welcome party animals</h2>
<h3>Prepare to celebrate!</h3>
</header>
<nav id="nav_menu">
<ul>
<li><a href="index.html" class="current">Home</a></li>
<li><a href="products/index.html">Product List</a></li>
<li><a href="personal/index.html">Personal</a></li>
<li><a href="decorating/index.html">Decorating Ideas</a></li>
<li><a href="email.html">Join Email</a></li>
</ul>
</nav>
<main>
<h1>Sam's Mardi Gras Store</h1>
<p>Growing up in New Orleans, Louisiana I always looked forward to Mardi Gras...</p>
</main>
</body>
</html>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
int main()
{
string ans;
int option;
int num1;
int num2;
cout << "would you like to use the calculator" << endl;
cin >> ans;
while (ans == "yes" || ans == "Yes") {
cout << "option 1: addition" << endl;
cout << "option 2: subtraction" << endl;
cout << "option 3: division" << endl;
cout << "option 4: multiplication" << endl;
cin >> option;
if (option == 1) {
cout << "enter the first number: ";
cin >> num1;
cout << endl << "enter the second number: ";
cin >> num2;
cout << num1 << "+" << num2 << "=" << num1 + num2 << endl;
cout << "would you like to continue using the calculator" << endl;
cin >> ans;
}
else if (option == 2) {
cout << "enter the first number: ";
cin >> num1;
cout << endl << "enter the second number: ";
cin >> num2;
cout << num1 << "-" << num2 << "=" << num1 - num2 << endl;
cout << "would you like to continue using the calculator" << endl;
cin >> ans;
}
else if (option == 3) {
cout << "enter the first number: ";
cin >> num1;
cout << endl << "enter the second number: ";
cin >> num2;
cout << num1 << "/" << num2 << "=" << num1 / num2 << endl;
cout << "would you like to continue using the calculator" << endl;
cin >> ans;
}
else if (option == 4) {
cout << "enter the first number: ";
cin >> num1;
cout << endl << "enter the second number: ";
cin >> num2;
cout << num1 << "*" << num2 << "=" << num1 * num2 << endl;
cout << "would you like to continue using the calculator" << endl;
cin >> ans;
}
}
}