Ask C/C++ Expert


Home >> C/C++

Assignment

Description

Convert your C version of the hoarding game into a C++ version

Changes

Input and output are for the C and C++ versions are the same EXCEPT for the following

? Users will enter their names at the beginning of the program. These will be displayed instead of 0, 1, 2, 3, ...

? Displaying the gamestate has been changed and follows this pattern

- Space Number | Space Name | Owner | Players

- If no one owns the property the Owner is None
- Players are displayed as [player_name : $cash_held]
- When multiple players are on the same space they are displayed based on the order they were created in

? Users can only roll dice and leave the game now as the player details are now constantly visible

Requirements

1. Your code must have at LEAST the following classes. You may have more but you must have at least these

? Gamestate
? Board
? Player
? Space
? Property
? DiceRoller
? Rules

2. All of your classes and free standing functions must be inside of a namespace named Monopoly. For some reason CLion has issues autocompleting the members when inside the namespace but the members are still there. You just have to type them out manually.

3. Any dynamic space you allocate must be managed by a smart pointer.

Restrictions

You may not use the following in your code

? Structs
? Global variables

- Class static variables are ok

? Regular enums

- You can still use class enums

? Arrays either dynamically or statically allocated except for argv

? C strings except for those located in argv

- String literals strings in your code that appear inside "" are still ok

? Any C functions except for printf, scanf, fopen, fclose, fscanf, and sscanf

- If you are looking for an equivalent to atoi see stoi

? using namespace std;

? new or delete

- Your dynamic memory allocation is being managed by smart pointers so there is no need to call these function

Hints and Advice

Think about your design before coding

A little bit of thought about how you want to structure your solution goes a long way in producing neat, understandable code. Think about how you want to structure your classes.

What is each made up of? What do you want each to be able to do?

That being said you'll encounter problems that you didn't consider when you start coding so your design will need to change to handle them. That's ok and a natural part of programming just update your design accordingly but don't forget the big picture when doing so.

Break your problems down

Break your problems down. Break your problems down. Break your problems down. You really want to be doing this as it makes solving this problem and any others much much easier. Start with our big steps. For each one of those big steps, break it into slightly smaller but still big steps.Each of these steps will eventually become a function call. Keep doing this until you finally get down to a step that can be solved in a few lines of code (around 1 - 20 lines) and then put your solution there.

Each of your functions should probably be nore more than 25 lines of code. There might be some exceptions but if you are going over 25 then you really should start breaking down the parts of your problem into more functions. Trust me when I say this as I say it from a place of experience, that it is much easier to read, understand, maintain, and update small functions then it is with large functions. This is true even if you create hundreds of small functions as each of those functions on their own will be really easy to understand because they are small. If you've been writing really long functions use this project as place to break those bad habits and start reaping the benefits of small functions.

Avoid Circular Inclusions

It's very likely that your code will have circular references in it. For example a player owns Properties but your Property could have a Player* to reference who their owner is. This is completely fine, normal, and a good design. What you need to be careful with in our design is not to have circular inclusions, either direct or indirect. A circular inclusion is when a .h file, say A.h, includes another file, say B.h, that includes A.h. This could either be direct, B.h has a #include "A.h" in it or it includes another file that includes A.h. For example B.h could include C.h which includes D.h which includes A.h.

Code with circular includes like this will not compile correctly. To get this to work you should define a strict order of when you will include files in your header and when you will use a forward declaration of the class. For me I said that if two classes were mutually dependent on each other then if one class is made of the other it would include that class. If the other class only referenced the first class it would have only a forward reference. For example a Player has Properties but a Property only refers to a player, so Player would include Property and Property would have a forward reference to Player. Then since I needed to use Player methods in Property.cpp I would include Player.h in Property.cpp to get access to them.

What rule you pick to break circular inclusions doesn't really matter, the important part is that you are consistent following.

And as a reminder forward declarations of classes only needed when circular referencing starts happening in your code.

Consider using a vector of Player* instead of just Player

When storing your players it might be easier to have a vector > instead of just a vector as under this setup you know that your players won't move locations in memory if you have to remove elements from your array and you get to control precisely when the elements are deleted. To add a unique pointer to a vector don't forget to use std::move. For example if I have a unique pointer up and and want to add it to the end of a vector, v, I would do v.push_back(std::move(up)).

Attachment:- Original-C-File.rar

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M92687111

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As