Apr 30, 2013

GWC CS G175 C++ Assignment 11 - Due 4/29/2013


Requirements
Write a base class “number” that holds a single integer value (value of intInput) and contains one pure virtual member function, print_it().  This will make the base class abstract in order to prevent its instantiation.  Define three derived classes to print the value in hexadecimal, octal, and binary (overriding the print_it() method). Write a program to demonstrate the use of all the derived classes. The user should enter the value to be converted (intInput).
In order to demonstrate polymorphism, the code in main() should look like:

number* Example;
Example = new hexadecimal(intInput);
Example->print_it();
// compiler takes care of binding and prints the value in hexadecimal
delete Example;
Example = new octal(intInput);
Example->print_it();

GWC CS G175 C++ Assignment 12 - Due 5/13/2013


Requirements

Write a class to handle fractions such as “1/3”. The class should have two private data members (ints) called numerator and denominator.
Create set() and get() functions for the numerator and denominator.  The numerator and denominator should be allowed to have negative values.
The value of denominator should never equal zero (a zero value for the denominator is not acceptable, as it could make the program crash).  To enforce this restriction, use a while loop or an if/else statement in any function that sets the value of the denominator.
Overload the +, -, *, and / operators to perform addition, subtraction, multiplication and division of fraction objects.  For example:
1/3 + 1/2 = 5/6
1/3 – 1/2 = –1/6
1/3 * 1/2 = 1/6
1/3 / 1/2 = 2/3

Apr 19, 2013

GWC CS G153 Java Project 05 - Due 4/26/2013

Requirements
P7.13 Add a method getWinner to the TicTacToe class of Section 7.8. It should return "x" or "o" to indicate a winner, or " " if there is no winner yet. Recall that a winning position has three matching marks in a row, column, or diagonal.
Disclaimer

  • There are many ways to solve a problem.
  • I do not post codes before the due date, since that does not help you.
  • Codes may be incorrect because I am also a learner like you. Use it at your discretion.
 Guidelines 
1. Your method should perform 4 checks
  • Check each row.
  • Check each column.
  • Check top-left to bottom-right diagonal.
  • Check top-right to bottom-left diagonal. 
2. In the game runner
  • Check for occupied space, if a space on the board is occupied, player should be prompted to select new row and column.
  • Check total moves to print a draw result

Apr 16, 2013

GWC CS G175 C++ Assignment 10 - Due 4/22/2013

Requirements
Write a program that reads integers until 0 is entered.  Once input terminates, the program should report the total number of even integers entered (excluding the 0), list the even values, their average (using a float value), the total number of odd integers entered, list the odd values and their average (using a float value).
Hints: create an array of integers where you store the even values entered, and another array where you store the odd values.  Also, make sure that your program does not crash when NO even value has been entered (or no odd value)… 
This exercise does not require to create any custom class.
Disclaimer 
  • I do not post codes before the due date, since that does not help you.
  • Codes may be incorrect because I am also a learner like you. Use it at your discretion.

Apr 8, 2013

GWC CS G175 C++ Assignment 9

Requirement
Create a program that will accept positive integers in decimal and display them in either binary, octal or hexadecimal. Use a switch statement to select the option (binary, octal, or hex) picked from the menu and make use of modulo (%) and divide operators. A sample run of the program is shown:
Enter a number in decimal:
254
Convert the number from decimal into:
0 – Binary
1 – Octal
2 – Hexadecimal
2
The number 254 (decimal) is FE in hexadecimal.
Store the base to convert to chosen by the user as an integer and use a while() loop that performs integer division and modulo operations on the number entered by the user. As the result would be reversed if printed in the order of the computation, your program will need the capability to reverse the order of the digits as part of the number conversion process. To do this, create a stack class based on the “last-in, first-out” concept that allows you to push (write) and pop (read) integers (code for a stack class (myStack) has been posted to the website for you to use). Using a stack object, you will push the results of your computation (loop using % and /) as you get them (one digit at a time, as an integer). You can refer to our document “Number Systems” (pages 4 and 5) that was posted on our website. Once done, you will pop the values from the stack to get them in the right order and use another loop to “cout” them. In this output loop (while “popping” the digits, you will need to handle the values (intBuffer) that may be greater then 9 when dealing with hexadecimal. This can be done using code similar to: 
if (intBuffer > 9)
cout << char('A' + intBuffer - 10); // displays digit > 9 as char
else
cout << intBuffer;
Disclaimer
  • There are many ways to solve a problem.
  • I do not post codes before the due date, since that does not help you.
  • Codes may be incorrect because I am also a learner like you. Use it at your discretion.

GWC CS G175 C++ Assignment 8

Requirement
Create a class rectangle.  The class should have data members length and width of type float, each of which defaults to 1.  The class should have member functions that calculate the perimeter() and the area() of the rectangle.  It should also have separate set() and get() functions for both the length and width (set_length(), get_length(), set_width(), get_width()).

The set_length() and set_width() functions should require the user to enter length or width data values greater than zero and less than or equal to 20.0.  These functions should examine the data entered by the user, and accept the data only if it is in the specified range (0 < data  <= 20.0).  If the data is not in this range, the user should be reminded of the allowed data range and prompted to enter the data again.  This cycle should repeat until the user enters a correct data value.  This can be accomplished by using a do while loop in each set() function.

Add a draw() function to your rectangle class that draws a solid rectangle of the correct length and width.  Since the length and width are floating point numbers, truncate the length and width values for the purpose of drawing the rectangle (for example, if length = 4.3 and width = 11.8, draw a rectangle that is 4 by 11 characters in size).  Truncation can be achieved by converting the floating point value to an integer value.  Use any character you like to draw the rectangle.  Here is an example of a rectangle drawn with + signs:

+++++++++++
+++++++++++
+++++++++++
+++++++++++

The functions get() , perimeter(), area() and draw() should be declared using the const keyword to ensure that these functions can not change private member data of the rectangle class.

Write a short demonstration program that uses the rectangle class you have created.  The program should create a rectangle object, then prompt the user to enter new values for the length and width.  Use the set() functions and the user’s entries to change the private data of the rectangle object you created.  Use the functions perimeter() and area() to display their results.  Finally, call the draw() function to display the resulting rectangle.
Disclaimer
  • There are many ways to solve a problem.
  • I do not post codes before the due date, since that does not help you.
  • Codes may be incorrect because I am also a learner like you. Use it at your discretion.