SlideShare a Scribd company logo
1 of 13
Download to read offline
C++ Programming: (Please help me!! Thank you!!)
Problem A: Win SimUniversity (20 points) Currently there is not way to “win” the game.
Modify the SimUniversity.cpp file to have a “hours until graduation” variable that starts at 48
(you may change this number for testing, but ensure you the code you submit has it at 48). In
addition to the normal output, give the time left to graduate as shown in the example below.
When you have graduated, end the game and tell them they have won. If you are expected to
graduate right when you would normally lose the game, you should graduate anyways and win
the game (see 2nd example). Please ensure you follow the sample output exactly
This is my program named SimUniversity.cpp to modify (you copy and paste to C++ to modify)
This is an example that I should get
Example 1 (user input is bold, board is not displayed because it is too big... do not change it):
Current stats are: Energy = 70, Entertainment = 70, Smartness = 70.
Current time: 8:00. You are at the Dorm. Do you want to (S)leep, do (H)omeowrk or (W)atch
some YouTube?
Do you want to (G)o to a different location?
g
Where do you want to travel to: (O, U, D)?
u
You go to University.
From your actions changed your stats by... Energy: -4, Entertainment: 0, Smartness: 0.
You have 47 hours left until graduation...
(Press enter to advance an hour)
Current stats are: Energy = 66, Entertainment = 70, Smartness = 70.
Current time: 9:00.
You are at the University. Do you want to (A)ttend class or (S)leep through lecture? Do you
want to (G)o to a different location?
a
You take copious notes and pay close attention to the material. From your actions changed your
stats by... Energy: --4, Entertainment: --8, Smartness: 3.
You have 46 hours left until graduation...
(Press enter to advance an hour)
... (skipping some time, this line is not actually output!) Current stats are: Energy = 67,
Entertainment = 50, Smartness = 73. Current time: 9:00.
You are at the Dorm.
Do you want to (S)leep, do (H)omeowrk or (W)atch some YouTube?
Do you want to (G)o to a different location?
h
You break out the books and pound through some problems. From your actions changed your
stats by... Energy: --3, Entertainment: --20, Smartness: 3. You have 1 hours left until graduation...
(Press enter to advance an hour)
Current stats are: Energy = 64, Entertainment = 30, Smartness = 76.
Current time: 10:00.
You are at the Dorm.
Do you want to (S)leep, do (H)omeowrk or (W)atch some YouTube?
Do you want to (G)o to a different location?
w
OMG!! CATS!!!! From your actions changed your stats by... Energy: --2, Entertainment: 20,
Smartness: --1. You have 0 hours left until graduation...
You graduate from college.
(Press enter to advance an hour)
Solution
#include
#include
using namespace std;
class Room {
private:
// letters outline where the location is
char mapLetter;
// locations are rectangles....
int topLeftX;
int topLeftY;
int bottomRightX;
int bottomRightY;
// all good things have a name, right?
string roomName;
// constructor to make a room! need all the above information
public:
Room();
Room(string name, char symbol, int tlx, int tly, int brx, int bry);
// Below: get functions to get all the information about a room
string getName();
char getLetter();
int getTopLeftX();
int getTopLeftY();
int getBottomRightX();
int getBottomRightY();
};
Room::Room()
{
roomName="The Void";
mapLetter='?';
topLeftX=-1;
topLeftY=-1;
bottomRightX=-1;
bottomRightY=-1;
}
Room::Room(string name, char symbol, int tlx, int tly, int brx, int bry)
{
roomName=name;
mapLetter=symbol;
topLeftX=tlx;
topLeftY=tly;
bottomRightX=brx;
bottomRightY=bry;
}
string Room::getName()
{
return roomName;
}
char Room::getLetter()
{
return mapLetter;
}
int Room::getTopLeftX()
{
return topLeftX;
}
int Room::getTopLeftY()
{
return topLeftY;
}
int Room::getBottomRightX()
{
return bottomRightX;
}
int Room::getBottomRightY()
{
return bottomRightY;
}
/* ABOVE ROOM */
/* BELOW MAP */
class Map {
private:
// size of the world
static const int MAX_ROWS = 20;
static const int MAX_COLUMNS = 40;
// characters for blank space and you, the player
static const char BLANK = ' ';
static const char PLAYER = 'Y';
// stores all the characters on the world
char grid[MAX_ROWS][MAX_COLUMNS];
// list of the possible locations to go to
Room mapRooms[100];
int usedRooms;
// current place you are
Room currentLocation;
void generateMap();
public:
Map();
void addRoom(Room r);
void displayMap(); // this simply shows the map on the screen...
Room getPlayerLocation();
int getLocations(Room changeMe[100]); // copies rooms into changeMe, returns the size
void moveToRoom(Room destination);
};
Map::Map()
{
usedRooms = 0;
// initialize the map to be blank
for(int i=0; i < MAX_ROWS; i++)
{
for(int j=0; j < MAX_COLUMNS; j++)
{
grid[i][j] = BLANK;
}
}
// make 3 rooms
Room outside("Outside", 'O', 0,0, 39,19);
Room university("University", 'U', 5,5, 15,15);
Room dorm("Dorm", 'D', 25,5, 30,10);
// add them to our arrayList
addRoom(outside);
addRoom(university);
addRoom(dorm);
// start out in your room
currentLocation = dorm;
moveToRoom(currentLocation);
// generate the map (rooms)
generateMap();
}
void Map::addRoom(Room r)
{
mapRooms[usedRooms] = r;
usedRooms++;
}
void Map::generateMap()
{
// for all the rooms we have in our list...
for(int i=0; i < usedRooms; i ++)
{
Room place = mapRooms[i];
// Fill in top and bottom of rectangle with characters
for(int i = place.getTopLeftX(); i <= place.getBottomRightX(); i++)
{
grid[place.getTopLeftY()][i] = place.getLetter();
grid[place.getBottomRightY()][i] = place.getLetter();
}
// fill in left and right side...
for(int i = place.getTopLeftY(); i <= place.getBottomRightY(); i++)
{
grid[i][place.getTopLeftX()] = place.getLetter();
grid[i][place.getBottomRightX()] = place.getLetter();
}
}
}
// this simply shows the map on the screen...
void Map::displayMap()
{
for(int i=0; i < MAX_ROWS; i++)
{
for(int j=0; j < MAX_COLUMNS; j++)
{
cout << " " << grid[i][j];
}
cout << endl;
}
}
// get where we are
Room Map::getPlayerLocation()
{
return currentLocation;
}
// get the possible locations to go to
int Map::getLocations(Room changeMe[100])
{
for(int i=0; i < usedRooms; i++)
{
changeMe[i] = mapRooms[i];
}
return usedRooms;
}
// update the map so the player symbol moves to the a new location
void Map::moveToRoom(Room destination)
{
// if were somewhere before
if(currentLocation.getTopLeftY() != -1) // if this is false, the room does not exist
{
// remove the mark from the center of the previous location
grid[currentLocation.getTopLeftY() + (currentLocation.getBottomRightY() -
currentLocation.getTopLeftY())/2]
[currentLocation.getTopLeftX() +(currentLocation.getBottomRightX() -
currentLocation.getTopLeftX())/2]
= BLANK;
}
// update where we are
currentLocation = destination;
// add player mark to center of new location
grid[currentLocation.getTopLeftY() + (currentLocation.getBottomRightY() -
currentLocation.getTopLeftY())/2]
[currentLocation.getTopLeftX() + (currentLocation.getBottomRightX() -
currentLocation.getTopLeftX())/2]
= PLAYER;
}
class Player
{
private:
// character has 3 stats: entertainment, energy and smartness
Map world;
int entertainment;
int energy;
int smartness;
int totalHours;
public:
Player();
Player(Map world);
int removeSmartness(int amount);
void doAction(char action, int time);
int addSmartness(int amount);
int removeEnergy(int amount);
int getSmartness();
int addEnergy(int amount);
int getEnergy();
int removeEntertainment(int amount);
int addEntertainment(int amount);
int getEntertainment();
void displayStats();
void travel();
char requestAction();
void displayMap();
void decrementHour();
};
// Tell them where they are and what actions they can take (and ask them as the method says)
char Player::requestAction()
{
// get where you are
Room location = world.getPlayerLocation();
// display where you are
cout << "You are at the " + location.getName() + ". ";
// if at uni
if(location.getName().compare("University") == 0)
{
cout << "Do you want to (A)ttend class or (S)leep through lecture? ";
}
// if at dorm
else if(location.getName().compare("Dorm") == 0)
{
cout << "Do you want to (S)leep, do (H)omeowrk or (W)atch some YouTube? ";
}
// if outside
else if(location.getName().compare("Outside") == 0)
{
cout << "Do you want to (S)ocialize or (P)lay Rugby? ";
}
// if you are not in any of the above, we have a problem
else
{
cout << "You are lost in the abyss... ";
}
// they can also change locations by 'G'
cout << "Do you want to (G)o to a different location? ";
// let them enter a choice
string answer;
getline(cin,answer);
// if they entered something, give back the first character (capitalized)
if(answer.length() > 0)
{
return toupper(answer[0]);
}
// otherwise they just hit enter (trying to crash me!), so they do nothing
else
{
return ' ';
}
}
// chage locations
void Player::travel()
{
// destionations the names of possible destinations
Room destinations[100];
// to do this, we need to copy in each name manually
int roomCount = world.getLocations(destinations);
// show the possible destinations
cout << "Where do you want to travel to: (";
if(roomCount>0)
{
cout << destinations[0].getLetter();
}
for(int i=1; i < roomCount; i++)
{
cout << ", " << destinations[i].getLetter();
}
cout <<")? ";
// read from the keyboard where they want to go
string response;
getline(cin, response);
// if they didn't enter anything (shame on them) they go nowhere
if(response.length() == 0)
{
cout << "You go nowhere... ";
return;
}
// otherwise pull out the first character
char r = toupper(response[0]);
// find the room that matches this character
Room destination;
for(int i=0; i < roomCount; i++)
{
Room place = destinations[i];
if(place.getLetter() == r)
{
destination = place;
}
}
// if we didnt find the room, they entered a bad character!
if(destination.getBottomRightX() == -1 ) // not a valid room
{
cout << "Invalid location, you go nowhere... ";
}
// otherwise go to that location
else
{
cout << "You go to " + destination.getName() + ". ";
world.moveToRoom(destination);
}
}
// display stats... yes what the methods says it does...
void Player::displayStats()
{
cout << "Current stats are: ";
cout << "Energy = " << energy <<", ";
cout << "Entertainment = " << entertainment <<", ";
cout << "Smartness = " << smartness <<", ";
cout << "Current hours left = "< 0:00)
dayTime = (dayTime+1)%24;
}
bool updatePlayer()
{
// default: keep on player
bool gameOver = false;
// all work and no play...
if(player.getEntertainment() == 0)
{
cout << "Your life is sapped of color and you become a mindless cog in the population. ";
gameOver = true;
}
// dum dum dummmm!
else if(player.getSmartness() == 0)
{
cout << "You drop out of college and are forced to drive taxis for the rest of your life. ";
gameOver = true;
}
return gameOver;
}
// hack!
void clearScreen()
{
cout << "                  ";
}
int main()
{
// hey! its a map
Map world;
// player needs to know about the map
player = Player(world);
// not over yet!
bool gameOver = false;
while(!gameOver)
{
// methods names should be informative enough
clearScreen();
player.displayMap();
player.displayStats();
displayTime();
// get the action after showing a list of options
char action = player.requestAction();
cout << " ";
// find out the effects of that action
player.doAction(action, dayTime);
// process what happened and end the game if we lose
gameOver = updatePlayer();
// wait so the person can
cout << "(Press enter to advance an hour)";
string temp;
getline(cin, temp);
}
// ruh roh
cout << "Game Over! ";
return 0;
}

More Related Content

Similar to C++ Programming (Please help me!! Thank you!!)Problem A Win SimU.pdf

I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdf
archanaemporium
 
I am trying to create a program That works with two other programs i.pdf
I am trying to create a program That works with two other programs i.pdfI am trying to create a program That works with two other programs i.pdf
I am trying to create a program That works with two other programs i.pdf
fortmdu
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdf
Rahul04August
 
Here is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdfHere is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdf
anithareadymade
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdf
asif1401
 
Hi there I am having difficulty in finalizing my Tetris game , below.pdf
Hi there I am having difficulty in finalizing my Tetris game , below.pdfHi there I am having difficulty in finalizing my Tetris game , below.pdf
Hi there I am having difficulty in finalizing my Tetris game , below.pdf
fonecomp
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
alish sha
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
alish sha
 
Im trying again -Okay, Im in need of some help - this is the c.pdf
Im trying again -Okay, Im in need of some help - this is the c.pdfIm trying again -Okay, Im in need of some help - this is the c.pdf
Im trying again -Okay, Im in need of some help - this is the c.pdf
eyeonsecuritysystems
 

Similar to C++ Programming (Please help me!! Thank you!!)Problem A Win SimU.pdf (20)

Bootcamp Code Notes - Akshansh Chaudhary
Bootcamp Code Notes - Akshansh ChaudharyBootcamp Code Notes - Akshansh Chaudhary
Bootcamp Code Notes - Akshansh Chaudhary
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdf
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional Programming
 
I am trying to create a program That works with two other programs i.pdf
I am trying to create a program That works with two other programs i.pdfI am trying to create a program That works with two other programs i.pdf
I am trying to create a program That works with two other programs i.pdf
 
[SI] Ada Lovelace Day 2014 - Tampon Run
[SI] Ada Lovelace Day 2014  - Tampon Run[SI] Ada Lovelace Day 2014  - Tampon Run
[SI] Ada Lovelace Day 2014 - Tampon Run
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdf
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
 
Here is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdfHere is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdf
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdf
 
Hi there I am having difficulty in finalizing my Tetris game , below.pdf
Hi there I am having difficulty in finalizing my Tetris game , below.pdfHi there I am having difficulty in finalizing my Tetris game , below.pdf
Hi there I am having difficulty in finalizing my Tetris game , below.pdf
 
Tech-1.pptx
Tech-1.pptxTech-1.pptx
Tech-1.pptx
 
Introduction to Processing
Introduction to ProcessingIntroduction to Processing
Introduction to Processing
 
Technology: A Means to an End with Thibault Imbert
Technology: A Means to an End with Thibault ImbertTechnology: A Means to an End with Thibault Imbert
Technology: A Means to an End with Thibault Imbert
 
FITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an endFITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an end
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
 
Jeop game-final-review
Jeop game-final-reviewJeop game-final-review
Jeop game-final-review
 
Im trying again -Okay, Im in need of some help - this is the c.pdf
Im trying again -Okay, Im in need of some help - this is the c.pdfIm trying again -Okay, Im in need of some help - this is the c.pdf
Im trying again -Okay, Im in need of some help - this is the c.pdf
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
The java language cheat sheet
The java language cheat sheetThe java language cheat sheet
The java language cheat sheet
 

More from aromalcom

In java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdfIn java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdf
aromalcom
 
How the U.S. Banking Structure Compares to the Rest of the WorldFo.pdf
How the U.S. Banking Structure Compares to the Rest of the WorldFo.pdfHow the U.S. Banking Structure Compares to the Rest of the WorldFo.pdf
How the U.S. Banking Structure Compares to the Rest of the WorldFo.pdf
aromalcom
 
Human cells contain two different types of genes. Most of our genes a.pdf
Human cells contain two different types of genes. Most of our genes a.pdfHuman cells contain two different types of genes. Most of our genes a.pdf
Human cells contain two different types of genes. Most of our genes a.pdf
aromalcom
 
Businesses combine for many reasons. The rationale for combining som.pdf
Businesses combine for many reasons. The rationale for combining som.pdfBusinesses combine for many reasons. The rationale for combining som.pdf
Businesses combine for many reasons. The rationale for combining som.pdf
aromalcom
 
9. Elaborate why materials have tendency to be corrodedSolution.pdf
9. Elaborate why materials have tendency to be corrodedSolution.pdf9. Elaborate why materials have tendency to be corrodedSolution.pdf
9. Elaborate why materials have tendency to be corrodedSolution.pdf
aromalcom
 
5. What are the main factors that affect the demand for the following.pdf
5. What are the main factors that affect the demand for the following.pdf5. What are the main factors that affect the demand for the following.pdf
5. What are the main factors that affect the demand for the following.pdf
aromalcom
 
1. Research Topic Research the problem of livelock in a networked e.pdf
1. Research Topic Research the problem of livelock in a networked e.pdf1. Research Topic Research the problem of livelock in a networked e.pdf
1. Research Topic Research the problem of livelock in a networked e.pdf
aromalcom
 
While George travels for two months, Mary agrees to house and care f.pdf
While George travels for two months, Mary agrees to house and care f.pdfWhile George travels for two months, Mary agrees to house and care f.pdf
While George travels for two months, Mary agrees to house and care f.pdf
aromalcom
 

More from aromalcom (20)

One goal of EHRs is to facilitate providers’ sharing of clinical inf.pdf
One goal of EHRs is to facilitate providers’ sharing of clinical inf.pdfOne goal of EHRs is to facilitate providers’ sharing of clinical inf.pdf
One goal of EHRs is to facilitate providers’ sharing of clinical inf.pdf
 
Mutations during which of the following processes in animals will af.pdf
Mutations during which of the following processes in animals will af.pdfMutations during which of the following processes in animals will af.pdf
Mutations during which of the following processes in animals will af.pdf
 
Let E, F and G be three sets. State expressions for the eventsonl.pdf
Let E, F and G be three sets. State expressions for the eventsonl.pdfLet E, F and G be three sets. State expressions for the eventsonl.pdf
Let E, F and G be three sets. State expressions for the eventsonl.pdf
 
In java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdfIn java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdf
 
In humans, the sickle-cell trait is caused by a single detective alle.pdf
In humans, the sickle-cell trait is caused by a single detective alle.pdfIn humans, the sickle-cell trait is caused by a single detective alle.pdf
In humans, the sickle-cell trait is caused by a single detective alle.pdf
 
Identify three examples of how U.S. society is heteronormative.S.pdf
Identify three examples of how U.S. society is heteronormative.S.pdfIdentify three examples of how U.S. society is heteronormative.S.pdf
Identify three examples of how U.S. society is heteronormative.S.pdf
 
How the U.S. Banking Structure Compares to the Rest of the WorldFo.pdf
How the U.S. Banking Structure Compares to the Rest of the WorldFo.pdfHow the U.S. Banking Structure Compares to the Rest of the WorldFo.pdf
How the U.S. Banking Structure Compares to the Rest of the WorldFo.pdf
 
Human cells contain two different types of genes. Most of our genes a.pdf
Human cells contain two different types of genes. Most of our genes a.pdfHuman cells contain two different types of genes. Most of our genes a.pdf
Human cells contain two different types of genes. Most of our genes a.pdf
 
Growth of Bacteria Bacteria grown in a laboratory are inoculated .pdf
Growth of Bacteria Bacteria grown in a laboratory are inoculated .pdfGrowth of Bacteria Bacteria grown in a laboratory are inoculated .pdf
Growth of Bacteria Bacteria grown in a laboratory are inoculated .pdf
 
Businesses combine for many reasons. The rationale for combining som.pdf
Businesses combine for many reasons. The rationale for combining som.pdfBusinesses combine for many reasons. The rationale for combining som.pdf
Businesses combine for many reasons. The rationale for combining som.pdf
 
You dont know the length, the width is four feet less than twice t.pdf
You dont know the length, the width is four feet less than twice t.pdfYou dont know the length, the width is four feet less than twice t.pdf
You dont know the length, the width is four feet less than twice t.pdf
 
A polypeptide chain contains an amphipathic helix, with arginine and.pdf
A polypeptide chain contains an amphipathic helix, with arginine and.pdfA polypeptide chain contains an amphipathic helix, with arginine and.pdf
A polypeptide chain contains an amphipathic helix, with arginine and.pdf
 
9. Elaborate why materials have tendency to be corrodedSolution.pdf
9. Elaborate why materials have tendency to be corrodedSolution.pdf9. Elaborate why materials have tendency to be corrodedSolution.pdf
9. Elaborate why materials have tendency to be corrodedSolution.pdf
 
5. What are the main factors that affect the demand for the following.pdf
5. What are the main factors that affect the demand for the following.pdf5. What are the main factors that affect the demand for the following.pdf
5. What are the main factors that affect the demand for the following.pdf
 
1. Research Topic Research the problem of livelock in a networked e.pdf
1. Research Topic Research the problem of livelock in a networked e.pdf1. Research Topic Research the problem of livelock in a networked e.pdf
1. Research Topic Research the problem of livelock in a networked e.pdf
 
While George travels for two months, Mary agrees to house and care f.pdf
While George travels for two months, Mary agrees to house and care f.pdfWhile George travels for two months, Mary agrees to house and care f.pdf
While George travels for two months, Mary agrees to house and care f.pdf
 
What law mandate SMEs in Ghana; Small and Medium-size Enterprises to.pdf
What law mandate SMEs in Ghana; Small and Medium-size Enterprises to.pdfWhat law mandate SMEs in Ghana; Small and Medium-size Enterprises to.pdf
What law mandate SMEs in Ghana; Small and Medium-size Enterprises to.pdf
 
What is the leader’s role when a substitute such as a routine job an.pdf
What is the leader’s role when a substitute such as a routine job an.pdfWhat is the leader’s role when a substitute such as a routine job an.pdf
What is the leader’s role when a substitute such as a routine job an.pdf
 
What function is associated with skeletal muscle cellsA. Some can.pdf
What function is associated with skeletal muscle cellsA. Some can.pdfWhat function is associated with skeletal muscle cellsA. Some can.pdf
What function is associated with skeletal muscle cellsA. Some can.pdf
 
What is ATP and how does it work Using what youve learned about c.pdf
What is ATP and how does it work  Using what youve learned about c.pdfWhat is ATP and how does it work  Using what youve learned about c.pdf
What is ATP and how does it work Using what youve learned about c.pdf
 

Recently uploaded

SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 

Recently uploaded (20)

ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 

C++ Programming (Please help me!! Thank you!!)Problem A Win SimU.pdf

  • 1. C++ Programming: (Please help me!! Thank you!!) Problem A: Win SimUniversity (20 points) Currently there is not way to “win” the game. Modify the SimUniversity.cpp file to have a “hours until graduation” variable that starts at 48 (you may change this number for testing, but ensure you the code you submit has it at 48). In addition to the normal output, give the time left to graduate as shown in the example below. When you have graduated, end the game and tell them they have won. If you are expected to graduate right when you would normally lose the game, you should graduate anyways and win the game (see 2nd example). Please ensure you follow the sample output exactly This is my program named SimUniversity.cpp to modify (you copy and paste to C++ to modify) This is an example that I should get Example 1 (user input is bold, board is not displayed because it is too big... do not change it): Current stats are: Energy = 70, Entertainment = 70, Smartness = 70. Current time: 8:00. You are at the Dorm. Do you want to (S)leep, do (H)omeowrk or (W)atch some YouTube? Do you want to (G)o to a different location? g Where do you want to travel to: (O, U, D)? u You go to University. From your actions changed your stats by... Energy: -4, Entertainment: 0, Smartness: 0. You have 47 hours left until graduation... (Press enter to advance an hour) Current stats are: Energy = 66, Entertainment = 70, Smartness = 70. Current time: 9:00. You are at the University. Do you want to (A)ttend class or (S)leep through lecture? Do you want to (G)o to a different location? a You take copious notes and pay close attention to the material. From your actions changed your stats by... Energy: --4, Entertainment: --8, Smartness: 3. You have 46 hours left until graduation... (Press enter to advance an hour) ... (skipping some time, this line is not actually output!) Current stats are: Energy = 67, Entertainment = 50, Smartness = 73. Current time: 9:00. You are at the Dorm. Do you want to (S)leep, do (H)omeowrk or (W)atch some YouTube?
  • 2. Do you want to (G)o to a different location? h You break out the books and pound through some problems. From your actions changed your stats by... Energy: --3, Entertainment: --20, Smartness: 3. You have 1 hours left until graduation... (Press enter to advance an hour) Current stats are: Energy = 64, Entertainment = 30, Smartness = 76. Current time: 10:00. You are at the Dorm. Do you want to (S)leep, do (H)omeowrk or (W)atch some YouTube? Do you want to (G)o to a different location? w OMG!! CATS!!!! From your actions changed your stats by... Energy: --2, Entertainment: 20, Smartness: --1. You have 0 hours left until graduation... You graduate from college. (Press enter to advance an hour) Solution #include #include using namespace std; class Room { private: // letters outline where the location is char mapLetter; // locations are rectangles.... int topLeftX; int topLeftY; int bottomRightX; int bottomRightY; // all good things have a name, right? string roomName; // constructor to make a room! need all the above information public: Room(); Room(string name, char symbol, int tlx, int tly, int brx, int bry);
  • 3. // Below: get functions to get all the information about a room string getName(); char getLetter(); int getTopLeftX(); int getTopLeftY(); int getBottomRightX(); int getBottomRightY(); }; Room::Room() { roomName="The Void"; mapLetter='?'; topLeftX=-1; topLeftY=-1; bottomRightX=-1; bottomRightY=-1; } Room::Room(string name, char symbol, int tlx, int tly, int brx, int bry) { roomName=name; mapLetter=symbol; topLeftX=tlx; topLeftY=tly; bottomRightX=brx; bottomRightY=bry; } string Room::getName() { return roomName; } char Room::getLetter() { return mapLetter; } int Room::getTopLeftX() {
  • 4. return topLeftX; } int Room::getTopLeftY() { return topLeftY; } int Room::getBottomRightX() { return bottomRightX; } int Room::getBottomRightY() { return bottomRightY; } /* ABOVE ROOM */ /* BELOW MAP */ class Map { private: // size of the world static const int MAX_ROWS = 20; static const int MAX_COLUMNS = 40; // characters for blank space and you, the player static const char BLANK = ' '; static const char PLAYER = 'Y'; // stores all the characters on the world char grid[MAX_ROWS][MAX_COLUMNS]; // list of the possible locations to go to Room mapRooms[100]; int usedRooms; // current place you are Room currentLocation; void generateMap(); public:
  • 5. Map(); void addRoom(Room r); void displayMap(); // this simply shows the map on the screen... Room getPlayerLocation(); int getLocations(Room changeMe[100]); // copies rooms into changeMe, returns the size void moveToRoom(Room destination); }; Map::Map() { usedRooms = 0; // initialize the map to be blank for(int i=0; i < MAX_ROWS; i++) { for(int j=0; j < MAX_COLUMNS; j++) { grid[i][j] = BLANK; } } // make 3 rooms Room outside("Outside", 'O', 0,0, 39,19); Room university("University", 'U', 5,5, 15,15); Room dorm("Dorm", 'D', 25,5, 30,10); // add them to our arrayList addRoom(outside); addRoom(university); addRoom(dorm); // start out in your room currentLocation = dorm; moveToRoom(currentLocation); // generate the map (rooms) generateMap(); } void Map::addRoom(Room r) {
  • 6. mapRooms[usedRooms] = r; usedRooms++; } void Map::generateMap() { // for all the rooms we have in our list... for(int i=0; i < usedRooms; i ++) { Room place = mapRooms[i]; // Fill in top and bottom of rectangle with characters for(int i = place.getTopLeftX(); i <= place.getBottomRightX(); i++) { grid[place.getTopLeftY()][i] = place.getLetter(); grid[place.getBottomRightY()][i] = place.getLetter(); } // fill in left and right side... for(int i = place.getTopLeftY(); i <= place.getBottomRightY(); i++) { grid[i][place.getTopLeftX()] = place.getLetter(); grid[i][place.getBottomRightX()] = place.getLetter(); } } } // this simply shows the map on the screen... void Map::displayMap() { for(int i=0; i < MAX_ROWS; i++) { for(int j=0; j < MAX_COLUMNS; j++) { cout << " " << grid[i][j]; } cout << endl; } } // get where we are
  • 7. Room Map::getPlayerLocation() { return currentLocation; } // get the possible locations to go to int Map::getLocations(Room changeMe[100]) { for(int i=0; i < usedRooms; i++) { changeMe[i] = mapRooms[i]; } return usedRooms; } // update the map so the player symbol moves to the a new location void Map::moveToRoom(Room destination) { // if were somewhere before if(currentLocation.getTopLeftY() != -1) // if this is false, the room does not exist { // remove the mark from the center of the previous location grid[currentLocation.getTopLeftY() + (currentLocation.getBottomRightY() - currentLocation.getTopLeftY())/2] [currentLocation.getTopLeftX() +(currentLocation.getBottomRightX() - currentLocation.getTopLeftX())/2] = BLANK; } // update where we are currentLocation = destination; // add player mark to center of new location grid[currentLocation.getTopLeftY() + (currentLocation.getBottomRightY() - currentLocation.getTopLeftY())/2] [currentLocation.getTopLeftX() + (currentLocation.getBottomRightX() - currentLocation.getTopLeftX())/2] = PLAYER;
  • 8. } class Player { private: // character has 3 stats: entertainment, energy and smartness Map world; int entertainment; int energy; int smartness; int totalHours; public: Player(); Player(Map world); int removeSmartness(int amount); void doAction(char action, int time); int addSmartness(int amount); int removeEnergy(int amount); int getSmartness(); int addEnergy(int amount); int getEnergy(); int removeEntertainment(int amount); int addEntertainment(int amount); int getEntertainment(); void displayStats(); void travel(); char requestAction(); void displayMap(); void decrementHour(); }; // Tell them where they are and what actions they can take (and ask them as the method says) char Player::requestAction() { // get where you are Room location = world.getPlayerLocation();
  • 9. // display where you are cout << "You are at the " + location.getName() + ". "; // if at uni if(location.getName().compare("University") == 0) { cout << "Do you want to (A)ttend class or (S)leep through lecture? "; } // if at dorm else if(location.getName().compare("Dorm") == 0) { cout << "Do you want to (S)leep, do (H)omeowrk or (W)atch some YouTube? "; } // if outside else if(location.getName().compare("Outside") == 0) { cout << "Do you want to (S)ocialize or (P)lay Rugby? "; } // if you are not in any of the above, we have a problem else { cout << "You are lost in the abyss... "; } // they can also change locations by 'G' cout << "Do you want to (G)o to a different location? "; // let them enter a choice string answer; getline(cin,answer); // if they entered something, give back the first character (capitalized) if(answer.length() > 0) { return toupper(answer[0]); } // otherwise they just hit enter (trying to crash me!), so they do nothing else { return ' ';
  • 10. } } // chage locations void Player::travel() { // destionations the names of possible destinations Room destinations[100]; // to do this, we need to copy in each name manually int roomCount = world.getLocations(destinations); // show the possible destinations cout << "Where do you want to travel to: ("; if(roomCount>0) { cout << destinations[0].getLetter(); } for(int i=1; i < roomCount; i++) { cout << ", " << destinations[i].getLetter(); } cout <<")? "; // read from the keyboard where they want to go string response; getline(cin, response); // if they didn't enter anything (shame on them) they go nowhere if(response.length() == 0) { cout << "You go nowhere... "; return; } // otherwise pull out the first character char r = toupper(response[0]); // find the room that matches this character Room destination; for(int i=0; i < roomCount; i++) {
  • 11. Room place = destinations[i]; if(place.getLetter() == r) { destination = place; } } // if we didnt find the room, they entered a bad character! if(destination.getBottomRightX() == -1 ) // not a valid room { cout << "Invalid location, you go nowhere... "; } // otherwise go to that location else { cout << "You go to " + destination.getName() + ". "; world.moveToRoom(destination); } } // display stats... yes what the methods says it does... void Player::displayStats() { cout << "Current stats are: "; cout << "Energy = " << energy <<", "; cout << "Entertainment = " << entertainment <<", "; cout << "Smartness = " << smartness <<", "; cout << "Current hours left = "< 0:00) dayTime = (dayTime+1)%24; } bool updatePlayer() { // default: keep on player bool gameOver = false; // all work and no play... if(player.getEntertainment() == 0) {
  • 12. cout << "Your life is sapped of color and you become a mindless cog in the population. "; gameOver = true; } // dum dum dummmm! else if(player.getSmartness() == 0) { cout << "You drop out of college and are forced to drive taxis for the rest of your life. "; gameOver = true; } return gameOver; } // hack! void clearScreen() { cout << " "; } int main() { // hey! its a map Map world; // player needs to know about the map player = Player(world); // not over yet! bool gameOver = false; while(!gameOver) { // methods names should be informative enough clearScreen(); player.displayMap(); player.displayStats(); displayTime(); // get the action after showing a list of options char action = player.requestAction(); cout << " "; // find out the effects of that action player.doAction(action, dayTime);
  • 13. // process what happened and end the game if we lose gameOver = updatePlayer(); // wait so the person can cout << "(Press enter to advance an hour)"; string temp; getline(cin, temp); } // ruh roh cout << "Game Over! "; return 0; }