CS52: Assignment #4 Solved

25.00 $ 12.50 $

Category:

Description

Background:
The purpose of this assignment is to get practice working with classes and objects.  Unlike a C program which is defined by its flow of control, C++ programs are defined by the classes and objects that are a part of it.  Thinking in terms of classes and objects is challenging for those new to these ideas.  It takes times to understand how they work and what is involved in using them.  The purpose of this homework is to introduce these ideas and get you thinking about them.  The first part is to get you thinking about design.  There are many many correct answers to Part A.  What I am looking for is a box diagram that represents a class.  You don’t have to write code for Part 1.  Object-oriented programmers often use diagrams to convey programming ideas.  As they say, a picture is worth a thousand words  (or lines of code…)  Part B introduces the class FlashDrive.  We will be doing a number of different homeworks with the FlashDrive class, so you will get to know it very well…  Similarly, you don’t have to write implementation code for Part B, but I will offer you extra-credit if you do (and do it correctly… 🙂

part_a: mahjong_design

Think of three classes that would be used in a Mahjong solitaire game. At least one of these classes must have multiple instances in the game. For each of these classes, describe two attributes (instance variables) and two operations (methods). A one line, simple description is sufficient for each attribute and operation. Do not worry about all the details that would be involved in finally implementing these classes in C++. Concentrate on modeling the objects.  Represent each class using the class diagram (box) notation described during lecture.

If you are not familiar with Mahjong Solitaire, here is a brief description:
Mahjong is a single-play tile game played in turns.  The object of Mahjong is to remove all the tiles from the board, a pair at a time by matching tiles.   Remove all tiles from the board by finding matching pairs of free tiles.  Two tiles match if they have the same picture and number.  However, only “free” tiles can be removed by a player during their turn.  A free tile is one that has no other tiles on top of it, and is unblocked on either its right or left side.  The game also includes a time and turn counter.  Players should try to finish as quickly as they can in as few turns as possible.

To help you, a screen shot of Mahjong is shown below.  Look at the items in the picture. Almost anything you see on the screen could be an object. Reread the above description of the game. Objects are frequently nouns in the specification of a program.

If the game is quite unfamiliar to you, try playing it!

part_b: flashdrive_driver

I have provided you with a sample class named FlashDrive which has been diagrammed below and described in the online course content.  For this unit, I’d like you to identify additional member variables (data) that would be appropriate for the class FlashDrive.  I would also like you to identify additional methods (functions) that would be appropriate for the class FlashDrive.  Submit a .h file for FlashDrive with the new possible methods and members you have identified commented and explained.  YOU ARE NOT REQUIRED TO CODE UP ANYTHING MORE THAN THE .H FILE, BUT I MAY AWARD YOU EXTRA CREDIT IF YOU DO…

FlashDrive
FlashDrive( );
FlashDrive( int capacity, int used, bool pluggedIn );void plugIn( );
void pullOut( );
void writeData( int amount );
void eraseData( int amount );
void formatDrive( );int getCapacity( );
void setCapacity( int amount );

int getUsed( );
void setUsed( int amount );

bool isPluggedIn( );

int my_StorageCapacity;
int my_StorageUsed;
bool my_IsPluggedIn;
Sample Driver Code
#include <iostream>
#include “FlashDrive.h”void main( )
{
int i;
cout << “Welcome to Howie’s Flash USB Drive Store!”
<< endl;
cout << “How much memory do you need? “;
cin >> i;FlashDrive f( i, 0,false );
cout << “Let’s format the drive…” << endl;
f.formatDrive();
cout << “Let’s plug in the drive…” << endl;
f.plugIn();
cout << “Let’s write some data…” << endl;
f.writeData( 10 );
cout << “Let’s unplug the drive…” << endl;
f.pullOut();

cout << “Enjoy your drive!!” << endl;
}

 

Overall

  • Your submission should follow this organization:
    • part_a
      • mahjong_design.pdf
    • part_b
      • flashdrive.h