Add command button objects for "cmdMake" & "cmdExit"
Code the exit button
Variables:
Dim b20, b10, b5, b1, c25, c10, c5, c1 As Integer
'paper bills 20, 10, 5, 1 & coins 25, 10, 5, 1
Dim sngTotal, sngTendered, sngChange As Single
'Total sale price, amount Tendered, Change due
Pseudocode for "cmdMake":
amount in txtTotal must be numeric
amount in txtTendered must be numeric
get sngTotal as a real number
get sngTendered as a real number
sngTendered must be larger than sngTotal
sngChange is the difference between sngTendered & sngTotal
b20 is the integer portion of sngChange divided by 20
recalculate sngChange as the difference between sngChange &
the product of b20 times 20
repeat for each subsequent variable
remembering that a quarter is really 0.25 dollars
remembering that a dime is really 0.1 dollars
remembering that a nickel is really 0.05 dollars
remembering that a penny is really 0.01 dollars
display all variables into the correct textbox object
Microsoft Documented Problem with "getline()" - drexel.edu - Visual C++ 6.0 getline() Fixer
Microsoft Documented Problem with "getline()" - microsoft.com - The getline template function reads an extra character after encountering the delimiter (Please don't try the fix suggested by Microsoft on the school's computers)
Lab Assignment -
Discuss the steps to computer video game design
Create a C++ program "ioDemo" following the steps in the tutorial
On-your-own: Create a C++ program "temperature":
Problem statement: Read a fahrenheit temperature & convert & display the equivalent centigrade tempature
Ideation:
What variables will you need?
What will you name them?
What data type are your variables?
How will you find the proper conversion equation?
Variables:
f // for the fahrenheit number input from the user
c // for the centigrade number result of a conversion
Pseudocode:
Tell the user to enter a fahrenheit temperature number
Read the number into the variable f
Convert from f to c using the conversion equation: (f - 32) / 9 * 5
Display the fahrenheit temperature (in case the user has forgotten)
Display the centigrade temperature (because the user wanted it)
Pause the output so the user can read the results
Compile & fix any errors
Test with numbers you can confirm:
Fahrenheit
Centigrade
32
0
212
100
0
-17.7778
-40
-40
68
20
77
25
86
30
Save to your "Z:/C++/" folder
Save a copy to your "Z/toBeGraded/" folder
02/07/08
Thursday - OCVTS Open House, Toms River Center, 7pm-8:30pm
Voluntary
7:00 p.m. to 8:30 p.m.
Demonstrations of what we're learning & doing
Web sites & PC programming
Games & Prizes
Fun for all ages
Extra-credit available
Not interested? Stop by & see what other students in other classes in Toms River are doing
Friday - SkillsUSA PDP Blue Book & Game Design & C++ Quiz 1
Classroom Discussion -
C++ Quiz 1. Click the link & follow the instructions. You only get one chance - this is not "try until you score 100". Open notes, open internet, open VB IDE (you may try out your answer in a program before you submit it), you may ask me for clarification, you may NOT ask me for the answers, likewise you may NOT ask another student
SkillsUSA - Complete a chapter from the PDP Blue BuuK:
C++ Quiz 1. Click the link & follow the instructions. You only get one chance - this is not "try until you score 100". Open notes, open internet, open VB IDE (you may try out your answer in a program before you submit it), you may ask me for clarification, you may NOT ask me for the answers, likewise you may NOT ask another student
SkillsUSA - Complete a chapter from the PDP Blue BuuK:
Online Tutorial - cplusplus.com - Control Structures: if else
Lab Assignment -
Work on the Women's History Month stamp
Discuss the steps to computer video game design
Begin writing the story
Create a C++ program "ifDemo" following the steps in the tutorial
On-your-own: Create a C++ program "temperature2":
Problem statement: Read a fahrenheit temperature or centigrade & convert & display the equivalent centigrade or fahrenheit tempature
Ideation:
How will you determine what the user wants (fahrenheit to centigrade or centigrade to fahrenheit)?
What variables will you need?
What will you name them?
What data type are your variables?
How will you find the proper conversion equation?
Variables:
d // for character "F" (fahrenheit to centigrade) or "C" (centigrade to fahrenheit)
in // for the number input from the user
out // for the number result of a conversion
Pseudocode:
Ask the user convert from [F]ahrenheit to Centigrade or [C]entigrade to Fahrenheit
Get the user response into variable "d"
Tell the user to enter a fahrenheit temperature number
Read the number into the variable "in"
Use a decision statement to convert using the proper function:
From F to C use: out = (in - 32) * 5 / 9
From C to F use: out = (in * 9 / 5) + 32
Display the input temperature (in case the user has forgotten)
Display the output temperature (because the user wanted it)
Pause the output so the user can read the results
Online Tutorial - cplusplus.com - Control Structures: nested if else
Lab Assignment -
Work on the Women's History Month stamp
Discuss the steps to computer video game design
Continue writing the story of the game
Begin creating a storyboard of the game
Modify a C++ program "ifDemo" following the steps in the tutorial
On-your-own: Create a C++ program "salary":
Problem statement: Read the hours worked & pay rate & calculate & display the weekly salary gross pay, taxes, & net pay. Calculate overtime as time-and-a-half for any hours over 40
Ideation:
How will you get the hours worked & pay rate?
What variables will you need?
What will you name them?
What data type are your variables?
Calculate gross pay as hours worked times pay rate
How will you calculate any overtime pay?
Estimate taxes as 20% of gross pay
Determine net pay as the difference between gross pay & taxes
Get the hours worked from the user
Get the pay rate from the user
Calculate the gross pay - be sure to include any overtime earned
Calculate taxes
Calculate net pay
Display all input & output variables with identifying information ("Hours Worked: 40", etc.)
Pause the output so the user can read the results
Online Tutorial - cplusplus.com - Control Structures: switch case
Lab Assignment -
Complete & hand-in ("Z:/toBeGraded/stamp.jpg")the Women's History Month stamp
Discuss the steps to computer video game design
Continue writing the story of the game
Continue creating a storyboard of the game
Modify a C++ program "ifDemo" following the steps in the tutorial
On-your-own: Create a C++ program "grades":
Problem statement: Read a number grade between 55 & 100, determine & display the letter grade, determine & display the GPA
Ideation:
How will you get the number grade?
Use the OCVTS grading scale:
93-100 = 'A' = 4.0
85- 92 = 'B' = 3.0
75- 84 = 'C' = 2.0
70- 74 = 'D' = 1.0
55- 69 = 'F' = 0.0
What variables will you need?
What will you name them?
What data type are your variables?
Use a nested if else statement to convert from number grade to letter grade
Use a switch case statement to convert from letter grade to GPA
Variables:
num // number grade input
lett // letter grade for output calculated
gpa // number grade for output calculated
Pseudocode:
Get the number grade from the user
Calculate the letter grade
Calculate the GPA
Display the number grade that the user input, the calculated letter grade, the calculated GPA
Pause the output so the user can read the results
Thursday - Math & Game Design & C++ Quiz 2 & C++ "valentine"
Classroom Discussion -
Review C++ Decisions:
Online Tutorial - cplusplus.com - Control Structures
Math - Ms Verde may stop by
Lab Assignment -
C++ Quiz 2. Click the link & follow the instructions. You only get one chance - this is not "try until you score 100". Open notes, open internet, open VB IDE (you may try out your answer in a program before you submit it), you may ask me for clarification, you may NOT ask me for the answers, likewise you may NOT ask another student
On-your-own: Create a C++ program "valentine" to display a Valentine's Day quote based on a number the user selects:
Problem statement: Read a user-entered number between 1 & 5, display a different quote for each number
YOU MUST USE A SWITCH CASE STATEMENT
YOU MUST USE COMMENTS AT THE TOP WITH YOUR NAME & DATE & PROGRAM NAME
Ideation:
How will you get the number?
What variables will you need?
What will you name them?
What data type are your variables?
Use a switch case statement to display the appropriate quote
Variables:
num // number grade input as int
Pseudocode:
Get the number from the user
Check that the number is between 1 and 5
Display an error message if less than 1 or greater than 5
Use a switch statement to determine which Valintine's Day quote to display
Pause the output so the user can read the results
Online Tutorial - cplusplus.com - While Loop Structures
Lab Assignment -
Practice from the online tutorial webpage
On-your-own: Create a C++ program "stars1" to use loops to draw shapes:
Problem statement: The user will enter a number between 5 & 15 & the computer will draw lines, boxes, & triangles using loops & the *asterix* character
Ideation:
What variables will you need?
How will you control that the user enters only numbers between 5 & 15?
How will you use loops to draw a single * character multiple times?
Variables:
int col = 0; // to control how many stars in each row
int row = 0; // to control how many rows of stars
int howMany = 5; // to specify how many the user wants
char again = 'Y'; // to specify if the user wants to go again
Pseudocode:
Main loop
create the int main function
Main loop
while char variable again equals uppercase Y or lowercase y
clear the screen of any existing content
ask the user how many stars between 5 & 15
get the user response into int variable howMany
Input control loop
while howMany is not between 5 & 15
remind the user to enter a number between 5 & 15
get the user response
1st Shape
tell the user line of stars
set col = 0
while col < howMany
output a single star
increment col
output two end-of-line
2nd Shape
tell the user box of stars
set row = 0
while row < howMany
set col = 0
while col < howMany
output a single star
increment col
output one end-of-line
increment row
output two end-of-line
3rd Shape
tell the user right triangle of stars
set row = 0
while row < howMany
set col = 0
while col < row
output a single star
increment col
output one end-of-line
increment row
output two end-of-line
4th Shape
tell the user upside down right triangle of stars
** extra credit **
5th Shape
tell the user backwards right triangle of stars
set row = 0
while row < howMany
set col = 0
while col < howMany - row - 1
output a single blank space
increment col
set col = 0
while col < row + 1
output a single star
increment col
output one end-of-line
increment row
output two end-of-line
6th Shape
tell the user upside down & backwards right triangle of stars
** extra credit **
7th Shape
tell the user isosceles triangle of stars
set row = 0
while row < howMany
set col = 0
while col < howMany - row - 1
output a single blank space
increment col
set col = 0
while col < row * 2 + 1
output a single star
increment col
output one end-of-line
increment row
output two end-of-line
8th Shape
tell the user upside down isosceles triangle of stars
set row = howMany
while row > 0
set col = 0
while col < howMany - row
output a single blank space
increment col
set col = 0
while col < row * 2 - 1
output a single star
increment col
output one end-of-line
increment row
output two end-of-line
9th Shape
tell the user diamond of stars
** extra credit **
End of main loop
ask the user again?
get the user response into char variable again
End of main function
return 0
Completer correct spelling of names form for Tracey
Career:
Unrelated Class Observation - Visit with Health & Fitness class to observe what they do & what skills set they need to do it - complete a 10 question skills survey
Interview with a Computer Video Game Designer - google.com - 22 million pages found
Research & write a one page, single spaced report on a career in the computer video game industry
Write your report as if you had interviewed someone currently working as a computer video designer
Due dates:
Rough idea draft due Wednesday, 03/05/08, I will approve your idea or suggest changes
First draft due Wednesday, 03/12/08, I will proofread & return
Second draft due Wednesday, 03/19/08, I will proofread & return
Final draft due Wednesday, 03/26/08, I will proofread & return
Final version due Wednesday, 04/02/08, at the end of marking period 3
C++ Loops:
Online Tutorial - cplusplus.com - Do While Loop Structures
Unrelated Class Observation - Health & Fitness class will visit with us to observe what we do & what skills set we need to do it - they will complete a 10 question skills survey
English - Ms. Gerick will work with 11th grader students for HSPA practice
C++ Loops:
Online Tutorial - cplusplus.com - For Loop Structures
C++ Quiz 3. Click the link & follow the instructions. You only get one chance - this is not "try until you score 100". Open notes, open internet, open VB IDE (you may try out your answer in a program before you submit it), you may ask me for clarification, you may NOT ask me for the answers, likewise you may NOT ask another student
Online Tutorial - cplusplus.com - Do While & For Loop Structures
A simple yet effective loop to continue a program until the user decides to quit:
char again = 'Y';
while (again == 'Y' || again == 'y')
{
// your code goes here
// before the end of the loop
// ask if the user wants to run the program again
cout << "Again? (Y/N) ";
cin >> again;
}
Lab Assignment -
Practice from the online tutorial webpage
Continue writing the C++ "stars" program using do while & for loops
howstuffworks.com - Aquatic Microbes Solve the Energy Crisis - 3:19 minutes
C++ Loops Review:
Online Tutorial - cplusplus.com - Do While & For Loop Structures
Lab Assignment -
C++ Quiz 3. Click the link & follow the instructions. You only get one chance - this is not "try until you score 100". Open notes, open internet, open VB IDE (you may try out your answer in a program before you submit it), you may ask me for clarification, you may NOT ask me for the answers, likewise you may NOT ask another student
On-your-own: Create a C++ program "summer" to sum numbers:
Problem statement: Continue reading numbers from the user, sum all the numbers, until the user enters a single zero (0), then display the sum to the user
Ideation:
What variables will you need?
What will you tell the user to do?
How will you control the loop?
How will you keep track of all the input numbers?
Do you really need to keep track of all the input numbers?
Functions must have open & close parentheses after the function name
int getGrossPay (double h, double p) { double g = h & p; return g; }
Functions probably have more than one statement
int getGrossPay (double h, double p) { double g = h & p; return g; }
Therefore functions probably have open & close curly braces after the parentheses
int getGrossPay (double h, double p) { double g = h & p; return g; }
Functions may have locally-scope parameter variables inside the open & close parentheses
int getGrossPay (double h, double p) { double g = h & p; return g; }
Functions may declare & use locally-scoped variables
int getGrossPay (double h, double p) { double g = h & p; return g; }
Function locally-scoped variables are only valid while the function is in operation
int getGrossPay (double h, double p) { double g = h & p; return g; }
Functions may read data stored in globally-scoped variables
int getGrossPay () { double g = hw & pr; return g; }
It is BAD FORM to change a globally-scoped variable inside a function & may even cause variable value problems
void getGrossPay (double h, double p) { gp = h & p ; }
It is better to have the function return a value that changes the globally-scoped variable
gp = getGrossPay(hw, pr);
When the function ends, the Random-Access-Memory used by the locally-scoped variables is released back to the operating system allowing other programs to run making for a more effecient system & happier users
Have a Nice Day!
Lab Assignment -
On-your-own: Create a C++ program "numbers" using a programmer-defined function:
Problem statement:
The user will enter a single character
The program will call a programmer-defined function to determine if the character is a single digit number between 0 & 9
If it is, the function will return the text name of the digit ('1' = "one", '2' = "two", etc.)
If it is not, the function will return "Not a number"
Ideation:
What variables will your main function need?
What will you call your programmer-defined function?
What variables will your function need?
How will you determine if the user entry is a digit?
C++ Quiz 4. Click the link & follow the instructions. You only get one chance - this is not "try until you score 100". Open notes, open internet, open VB IDE (you may try out your answer in a program before you submit it), you may ask me for clarification, you may NOT ask me for the answers, likewise you may NOT ask another student
On-your-own: Create a C++ program "fibonacci" to display the famous sequence of numbers:
Problem statement:
The user will enter a number between 1 & 44
The program will display that many digits in the fibonacci sequence
Google "fibonacci" if you don't know how it works
The program will end when the user enters a zero (0)
Ideation:
What variables will you need?
How will you control input between 0 & 44 (not a negative number, not greater than 44)?
How will you determine the next number in the Fibonacci sequence?
int lowNum = 1, highNum = 100;
int howMany = 1, guess = 0, number = 0;
char again = 'Y';
Pseudocode:
function tooHigh(local variable int g, local variable int h)
{
display the user guess
display "Your guess of is too high"
add 1 to h
return h
}
function tooLow(local variable int g, local variable int h)
{
display the user guess
display "Your guess of is too low"
add 1 to h
return h
}
function foundMatch(local variable int g, local variable int h)
{
display the user guess
display "Yes!!! Your guessed my number"
return 111
}
void main(void)
{
local variables int howMany, guess, number
local variable char again = 'Y'
loop while again equals 'Y' or 'y'
{
clear the screen
set local variable howMany to 1
set local variable number to a random number between 1 & 100
display the random number during testing
loop while howMany is smaller than 8
{
display "Enter Guess (1 - 100): "
get user guess into local variable guess
if guess is greater than number run function tooHigh(guess,howMany) save the return to local variable howMany
else if guess is less than number run function tooLow(guess,howMany) save the return to local variable howMany
else run function foundMatch(guess,howMany) save the return to local variable howMany
}
display "Again (Y/N)? "
get the user answer into local variable again;
}
}
Create a C++ program "ttt" to play the game of tic-tac-toe between two players:
Problem statement:
The computer will draw a blank game board
Player1 & player2 will alternate select a position to play
After each play, the computer will determine if there is a winner or a tie game
If there is a winner, the computer will not allow any more plays
After a winner or a tie game, the computer will ask "Play Again (Y/N)?"
Ideation:
What variables will you need?
How will you control input?
How will you track which player plays next?
How will you determine a winner?
Variables:
//global variables:
char t[10], again = 'Y', xory = 'x';
int i, p;
bool w = false;
Pseudocode:
//function to clear the array variable t[]
for 1 to 9 set t[i] to ' '
//function to draw the board
clear the screen
draw the board
//function to get the next play
display player's turn
get the play as a number between 1-9
while the play position is not blank
get the play as a number between 1-9
set the array variable t[play] equal to the player
switch player
//function to check for a winner
check each possible winning condition
if find a winning condition
set winner equal to true
set i equal to a high number
//function main()
while again is 'Y' or 'y'
clear screen
set winner equal to false
clear the array variable t[]
draw the board
for i = 1 to 9
get the next play
draw the board
check for a winner
if no winner
display "tie game"
ask "again (Y/N)"
get again
Online Tutorial - cplusplus.com - Character Sequences
Math Review: 121,000 google.com pages on number divisibility rules
Lab Assignment -
C++ Quiz 5. Click the link & follow the instructions. You only get one chance - this is not "try until you score 100". Open notes, open internet, open VB IDE (you may try out your answer in a program before you submit it), you may ask me for clarification, you may NOT ask me for the answers, likewise you may NOT ask another student
On-your-own: Create a C++ program "numberDivisibility" to easily test if one number can be evenly divided by another:
Problem statement:
The user will enter two (2) integer numbers
The first number will be a positive whole number
The second number will be a positive whole number between 1 & 12 (inclusive)
The computer will determine if the first number is evenly divisible by the second
The computer will display the answer
Ideation:
Divisibility Rules easily test if one number can be evenly divided by another
"Divisible By" means "If you divide one number by another, is the result a whole number?"
Example, 1324 is divisible by 4, because the last two digits are divisible by 4
Example, 1324 is NOT divisible by 5, because the last digit is neither 5 nor 0
Use the complete set of rules Ms. Verde supplied & you practiced with yesterday
Compile & fix any errors
Save to your "Z:/C++/" folder
Save a copy to your "Z/toBeGraded/" folder
I'd like to finish the tic-tac-toe game, if time allows
Pointers are variables that point to an area in memory
You define a pointer by adding an asterisk (*) in front of the variable name (i.e. int *pNumber)
You can get the address of any variable by adding an ampersand (&) in front of it (i.e. pNumber = &my_number)
The asterisk, (unless in a declaration such as int *number), should be read as 'the memory location pointed to by'
The ampersand, (unless in a declaration such as int &number), should be read 'the address of'
Pointers MUST be of the same type as the variables you want them to point to, so int *number will not point to a MyClass
You can pass pointers to functions
Lab Assignment -
Practice C++ functions from web site
Create a C++ program "battleship" to play the game:
Problem statement:
Two player (Human vs. Computer)
Two side-by-side 11-by-11 gameboards
Gameboard is arranged in 11 numerical rows & 11 alphabetic columns
You set your ships on the left board
The computer ships are placed randomly on the right side board
Ships are places horizontally or vertically
You see your own ship placement
You don't see the computer ship placement
Five sizes/types of ship:
Aircraft Carrier - 5 spaces - "AAAAA"
Battleship - 4 spaces - "BBBB"
Cruiser - 3 spaces - "CCC"
Submarine - 3 spaces - "SSS"
Destroyer - 2 spaces - "DD"
Player & computer take turns "shooting" at the other's ships
Shooting occurs alphanumeric by Col (A-K) & Row (1-11)
A player hit on a computer ship displays as the letter of the ship type
A computer hit on a player ship displays as an "X"
Game play ends when either player or computer destroys every part of every opposition ship
Ask the user "Play Again (Y/N)? "
Ideation:
Variables:
int i, r, c, z, startRow = 0, endRow = 0;
// r is row, c is col, z is board position [1-121]
char pBoard[122], cBoard[122], yorn = 'Y', d = ' ';
char startCol = ' ', sType = ' ', endCol = ' ';
// d is direction
string shipType = "";
Declare two (2) additional functions (above the main()):
void getPlayerBoard();
bool getShip(int ship);
Add a call to getPlayerBoard() to main():
getPlayerBoard();
Pseudocode to define function getPlayerBoard() (below the main()):
declare a local bool variable shipNotDone set equal to true
loop while shipNotDone equals true
set shipNotDone = getShip(5); // get Aircraft Carrier
reset bool variable shipNotDone equal to true
loop while shipNotDone equals true
set shipNotDone = getShip(4); // get Battleship
reset bool variable shipNotDone equal to true
loop while shipNotDone equals true
set shipNotDone = getShip(3); // get Cruiser
reset bool variable shipNotDone equal to true
loop while shipNotDone equals true
set shipNotDone = getShip(2); // get Submarine
reset bool variable shipNotDone equal to true
loop while shipNotDone equals true
set shipNotDone = getShip(1); // get Destroyer
Pseudocode to define function getShip() (below the main()):
//create a new local bool variable validShip set equal to true
//clear variables
clear char variable "d" (set to blank)
clear char variable "startCol" (set to blank)
clear int variable "startRow" (set to 0)
//get ship type
use a switch case statement starting with int variable "ship"
to set string variable "shipType" to the name of the ship
also set char variable "sType" to the letter of the ship
case 5: shipType = "Aircraft Carrier"; sType = 'A'; break;
"shipType": 4 is "Battleship", 3 is "Cruiser", 2 is "Submarine",
"sType": 4 is 'B', 3 is 'C', 2 is 'S',
case 1: shipType = "Destroyer"; sType = 'D'; break;
//get ship direction
use a while loop to get char variable "d" as either 'H' or 'V'
tell the user to enter direction Horizontal or Vertical
use cin to get char variable "d"
repeat until the user enters either 'H' or 'V'
//set ship horizontal
if char variable "d" equals 'H':
use a switch case statement starting with int variable "ship"
to set char variable "endCol" to the last possible column
in which the ship type being entered can start
case 5: endCol = 'G'; break;
4 is 'H', 3 is 'I', 2 is 'I',
case 1: endCol = 'J'; break;
use a while loop to get char variable "startCol" as a letter
tell the user to enter a starting column 'A' through "endCol"
use cin to get char variable "startCol"
repeat until the user enters a char 'A' through "endcol"
use a while loop to get int variable "startRow"
tell the user to enter a starting row 1 through 11
use cin to get int variable "startRow"
repeat until the user enters a number 1 to 11
//set ship vertical
else if char variable "d" equals 'V':
use a switch case statement starting with int variable "ship"
to set int variable "endRow" to the last possible column
in which the ship type being entered can start
case 5: endRow = 7; break;
4 is 8, 3 is 9, 2 is 9,
case 1: endRow = 10; break;
use a while loop to get char variable "startCol" as a letter
tell the user to enter a starting column 'A' through 'K'
use cin to get char variable "startCol"
repeat until the user enters a char 'A' through "endcol"
use a while loop to get int variable "startRow"
tell the user to enter a starting row 1 through "endRow"
use cin to get int variable "startRow"
repeat until the user enters a number 1 to "endRow"
end if
//set starting column
use a switch case statement starting with int variable "startCol"
to set int variable c to the last possible column
in which the ship type being entered can start:
case 'A': c is 1; break;
...
case 'K': c is 11; break;
//set starting row
set int variable "r" equal to int variable "startRow"
calculate int variable "z" as equal to (r-1) times 11 plus c
if int variable "ship" equals 2 change "ship" to 3
if int variable "ship" equals 1 change "ship" to 2
if char variable "d" equals 'H'
use a loop to check all elements of char array variable "pBoard[z]"
if the pBoard[z] element is not a dot '.'
set validShip equal to false
increment z (horizontal is add 1)
end if
end loop
recalculate int variable "z" as equal to (r-1) times 11 plus c
if validShip is still equal to true
use a loop to change the correct elements of char array variable "pBoard[z]"
to the char variable "sType"
correctly increment int variable "Z" (horizontal is add 1)
end loop
end if
else if char variable "D" equals 'V'
use a loop to check all elements of char array variable "pBoard[z]"
if the pBoard[z] element is not a dot '.'
set validShip equal to false
increment z (vertical is add 11)
end if
end loop
recalculate int variable "z" as equal to (r-1) times 11 plus c
if validShip is still equal to true
use a loop to change the correct elements of char array variable "pBoard[z]"
to the char variable "sType"
correctly increment int variable "Z" (vertical is add 11)
end loop
end if
end if
call drawBoard()
Compile & fix any errors
Save to your "Z:/C++/" folder
Save a copy to your "Z/toBeGraded/" folder
Continue writing the story of the game
Continue creating a storyboard of the game
Continue learning video game development
03/19/08
Wednesday - NJIT Web Design Competition - 7:30 am to 5:00 pm
Online Tutorial - cplusplus.com - Input/Output with Files
Lab Assignment -
Create a program to read Lincoln's Gettysburg Address from a text file & write a "leetized" version to an output text file:
Open Microsoft Visual C++ & create a new C++ win32 console application called "gettysburg"
Create a new C++ source file called "main"
Copy & Paste the CRectangle source from the C++ tutorial:
#include <iostream>
using namespace std;
class CRectangle
{
int x, y;
public:
void set_values (int,int);
int area () {return (x*y);}
};
void CRectangle::set_values (int a, int b)
{
x = a;
y = b;
}
void main ()
{
CRectangle rect;
rect.set_values (3,4);
cout << "area: " << rect.area();
}
Test it -- 3 * 4 should return 12
Modify to change from a two-dimensional rectangle to a three-dimensional carton
#include <iostream>
using namespace std;
class CRectangle
{
int x, y, z;
public:
void set_values (int, int, int);
int area () {return (x * y * z);}
};
void CRectangle::set_values (int a, int b, int c)
{
x = a;
y = b;
z = c;
}
void main ()
{
CRectangle rect;
rect.set_values (3,4,5);
cout << "area: " << rect.area();
}
In the main(), check that the input file is open or report an error to the user:
if(inFile.is_open()) { }
else { cout << "Unable to open file input.txt" << endl; }
If the input file is open, process all characters in the input file:
while(! inFile.eof()) { }
In the loop, get a single character from the input file:
inFile.get(a);
In the loop, change some characters from normal to 133+:
switch(a)
{
case 'a': case 'A': a = '4'; break;
case 'e': case 'E': a = '3'; break;
case 'i': case 'I': a = '1'; break;
case 'o': case 'O': a = '0'; break;
case 't': case 'T': a = '+'; break;
case 's': case 'S': a = '&'; break;
// add any others if you want to
}
In the loop, write the character to both screen & output file:
cout << a;
outFile << a;
Close both input & output file:
inFile.close();
outFile.close();
Extra Credit: Count & report how many words & sentences the input file contains
In the main() display the menu until the user selects [Q]uit:
char yorn = ' ';
while (yorn != 'Q' && yorn != 'q')
{
yorn = showMenu();
switch (yorn)
{
case 'A':
case 'a': add(); system("pause"); break;
case 'C':
case 'c': change(); system("pause"); break;
case 'D':
case 'd': deleter(); system("pause"); break;
case 'S':
case 's': show(); system("pause"); break;
}
}
cout << "Thank You for Using the Music Menu\n";
Close both input & output file:
inFile.close();
outFile.close();
Count & report how many words & sentences the input file contains
Compile & fix any errors
Save to your "Z:/C++/" folder
Save a copy to your "Z/toBeGraded/" folder
Continue learning video game development
04/18/08
Friday - NJIT Programming Contest - 7:30 am to 5:00 pm