103 pages found:
ASCII Codes
Every character you can type on the keyboard is represented by a number. Here's a link to show what number goes with what character. http://www.lookuptables.com/


---Acceptable Network Use Policy
Students are responsible for understanding and following the Duxbury Internet Connection Acceptable Use Guidelines. (http://www.duxbury.k12.ma.us/District/TechStudAUG.pdf) For clarity, several points from that document are highlighted and explained below:

Use of the Duxbury Internet Connection is limited to academic research and projects conducted by students and faculty of the district. This means that any use of the network not directly related to an academic project is considered a violation of school policy. So playing computer games, sending or receiving non-school-related emails, accessing ebay, using instant messenger services, and checking out sports information, etc., are all considered a violation of the acceptable use policy.

Users must respect other’s privacy and intellectual property. This means that you must not use the network to damage, snoop around in, or plagiarize from the work of others stored on the network.

Users will accept the responsibility of keeping all inappropriate material or files dangerous to the integrity of the network from entering the school through the Internet. This means that you must not download or install any software without the express consent of your teacher. It also means that you have a responsibility to report to your teacher any inappropriate files, for example, gaming software, on the networked computers in the school.

The classroom teacher is responsible for monitoring usage of the network within his/her instructional areas and for reporting incorrect use of the network to the network administrator or to the technology director. This means that your classroom teacher has an obligation to report student violations of these policies for disciplinary action.

The Duxbury Public Schools reserve the right to deny, revoke or suspend specific user privileges and/or to take other disciplinary action, up to and including suspension, or expulsion for violations of these Guidelines. This means that the penalties for violations of these guidelines may be severe.

My signature below indicates that I have read and understood the Duxbury Internet Connection Acceptable Use Guidelines and that I agree to follow these guidelines at all times in my use of the networked computers in Mr. Webster's classroom.

Student name (printed):_____________________________________

Student signature: _____________________________________ Date:_________________

My signature below indicates I have read and understood the Duxbury Internet Connection Acceptable Use Guidelines and that I have discussed with my son or daughter the importance of following these guidelines.

Parent name (printed):_____________________________________

Parent signature: _____________________________________ Date:_________________



Adding Line Numbers
Use this perl program to add line numbers to .cpp source code files.

#!/usr/bin/perl

$infile = $ARGV0 . ".cpp";
$outfile = $ARGV0 . ".txt";

#open(IN,"payroll.txt");

open(IN,$infile);
@F = ;
close(IN);

open(OUT,">$outfile");

$count = 1;

foreach $line (@F)
{

print OUT $count++ . "\t";
print OUT $line;

}

close(OUT);


Adding TC To The Path
* Let's suppose that you copied the TURBOC directory from the Giant CD the root of your C: hard drive.
* Click Start > Control Panel > System > Advanced (tab) > Environment Variables (button on bottom)
* In the bottom System Variables window, highlight the Path variable (scroll to find it if necessary)
* With the Path variable highlighted, click Edit.
* The Edit System Variable dialog box pops up with the current path highlighted. Click on the highlighted Path. Be careful not to delete it! If you do, click Cancel and try again.
* Use the right arrow key to move your cursor to the very end of the Path variable.
* Add this ;c:/turboc/bin to the end of the Path variable. Note the semi-colon.
* Click OK on the Edit System Variable dialog box, click OK on Environment Variables box, and click OK on Systems Properties box.
* To test, open a DOS window and type tc and press Enter. If Turbo C starts, you're done.


Adding Up Integers
Write a program that adds up integers that the user enters. First the programs asks how many numbers will be added up. Then the program prompts the user for each number. Finally it prints the sum.

Sample Input / Output:

How many integers will be added:
5
Enter an integer:
3
Enter an integer:
4
Enter an integer:
-4
Enter an integer:
-3
Enter an integer:
7

The sum is 7

Be careful not to add the number of integers (in the example, 5) into the sum.


Area Of A Circle
Write a program that calculates the area of a circle from its radius. The radius will be an integer read in from the keyboard. The user dialog will look like this:

Input the radius:
3
The radius is: 3 The area is: 28.274333882308138

You will need to use the constant PI which you approximate as 3.1416


Assessment Questions
What does it mean to say that C++ is case sensitive? What are some advantages and disadvantages of a case sensitive language?
Average Rainfall
Write a program that asks the user for the rain fall for three months, April, May, and June and then prints out the results in a table as shown below. Declare and initialize a variable to the rain fall for each month. Compute the average, and write out the results, something like:

Rainfall for April: 12
Rainfall for May : 14
Rainfall for June: 8
Average rainfall: 11.333333

To get the numerical values to line up use the tabulation character '\t' as part of the character string in the output statements. Check that your program prints the correct results.



Baby Steps
Do the simplest thing that could possibly work.
Ball 0
Make a pong directory and go into it. Open tc and start a new file called ball.cpp for the ball class.

class Ball
{

private:

public:

};

All this says is that you want to design a Ball class which will have some private stuff (usually its data) and some public stuff (usually its methods).

You should try to compile at this stage. If this won't compile, why add to it? Compile after every little baby step to test your work.

Now try Ball 1


Ball 1
Here's our Ball class, so far:

class Ball
{

private:

public:

};

I want every Ball to know its location and its velocity (which physics student's know includes direction). How can a Ball know things? It can have places in memory to hold information in variables. If those variables are private, they can only be changed be code inside the Ball. That's good.

class Ball
{

private:
int X;
int Y;
int Vx;
int Vy;

public:

};

So we add four private variables. You should be able to guess what each stands for.

Now, compile again. Why add more if this doesn't work?

Then go on to Ball 2


Ball 2
Here's our Ball class so far:

class Ball
{

private:
int X;
int Y;
int Vx;
int Vy;

public:

};


Bell Schedule
Block 1: 7:30 - 8:38 (Includes attendance, pledge, bulletin @ 8:35)

Block 2: 8:42 - 9:50

Block 3: 9:54 - 11:02

Block 4A: (A Lunch: 11:06 - 11:36) 11:40 - 12:48

Block 4B: 11:06 - 11:40 (B Lunch: 11:44 - 12:10) 12:14 - 12:48

Block 4C: 11:06 - 12:14 (C Lunch: 12:18 - 12:48)

Block 5: 12:52 - 2:00


Bells And Whistles Last
Resist the temptation to add bells and whistles to your program early on. Save them until the end.

Coding for bells and whistles is usually pretty easy. And bells and whistles are cool. So the temptation is to do them early in the project. Resist this temptation.

If you do the bells and whistles early, it often makes the code harder to read, longer to compile, and harder to test and debug.

So do the bells and whistles last.



Book Index
Write a program that asks the user to enter two words. The program then prints out both words on one line. The words will be separated by enough dots so that the total line length is 30:

Sample Input / Output:

Enter first word:
turtle
Enter second word
153

turtle....................153

This could be used as part of an index for a book. To print out the dots, use cout inside a loop body.


Changing Lines In DOS Mode
To put the DOS screen into 25 line mode use this command:

mode con: lines=25


Check Charges
A bank has the following rule: if a customer has more than $1000 dollars in their checking account or more than $1500 dollars in their savings account, then there is no service charge for writing checks. Otherwise there is a $0.15 charge per check. Write a program that asks for the balance in each account and then writes out the service charge. (4 points)

To get a full 5 points for this problem, make your program repeat over and over until the user types in a balance of 0 for BOTH checking and savings accounts.


Class Box
General Idea: We want to write a class for making rectangular boxes on the screen.

* It takes four ints to define the top left and bottom right corners of the box.
* We want to give the box its coordinates in the constructor when the box is created. For example, the biggest box we could create would be this:

Box BigBox?(1,1,80,25);

* The Box should have a draw() function that would draw the box on the screen.

The void draw() function:

* First, go to each of the four corners and print the correct corner character to the screen. Here's the code for the lower right corner:

gotoxy(X2,Y2); cout << char(188);

* Now you have to draw the horizontal and vertical lines connecting the corners. The easiest way to do this is with two separate for loops, one for the two horizontal lines, and a second for the two vertical lines.
* Here's the loop for the horizontal lines:

for(int x=X1+1; x {

gotoxy(x,Y1); cout << char(205);
gotoxy(x,Y2); cout << char(205);

}

* You can write the loop for the vertical lines.
* Use the main( ) function to test the draw() function.
* Now create and draw several different sized boxes on the screen.

The hide() function:

* If you can create a draw() function, you can certainly create a hide() function.

Now see if you can create grow() and shrink() functions.


Class Cat
Project: Write a class to make Cat objects and a main() function to test the class. Make a new cat folder under your own folder on the T: drive.

How to Start: Of course, you will start like this:

class Cat
{

};

Don't forget the semi-colon! And compile.

Privacy Issues: Now add the private and public parts. Don't forget the colons. And compile.

What does a Cat have in mind? Not much. Maybe just a couple of integers, myX and myY. Should they be public or private? Can people see what you have in mind?

The Cat constructor? Cat should have a constructor. And the constructor should probably take two ints in the envelope so that when you create Cat objects, you can place them on the screen. Check how you did it with the Paddle constructor. When you write the code for the constructor, all it has to do is set the Cat's myX and myY equal to the x and y from the envelope. Don't forget to compile.

The Cat has to be able to show itself: Writing the show() method for the Cat requires some creativity. Like the Ball and Paddle, you have to use gotoxy(someX, someY) and then cout << "Some crazy stuff to look like a cat" Your Cat should look totally different than the Cat on the computer next to you.

ASCII Art: Here's a link to some ASCII art. Check out the cats. http://www.chris.com/ascii/

ASCII Art Line-by-Line: Making your program print ASCII art is not as easy as you might think. When the art requires more than one line of print on the screen, you can do something like this:

gotoxy(myX,myY+0); cout << "====";
gotoxy(myX,myY+1); cout << " + + ";
gotoxy(myX,myY+2); cout << " ^ ";
gotoxy(myX,myY+3); cout << " < > ";
gotoxy(myX,myY+4); cout << " ****** ";

A Weird ASCII Art Problem: Here's a problem you will likely have if you try to make your program print much ASCII art. The backslash character (this guy: \) has a special meaning in C++ and in many other computer languages. It means something like ignore the next character's actual value and print something special instead. That means when you try to print a backslash character using cout << the backslash itself doesn't acutally print and the character following it is apt to print as something weird.

The solution to this problem is also weird. For every backslash character you want to print on the screen, add an extra backslash character.

To see how this works, just make a simple little Test Tube Program that does this: cout << "\\";

Hiding the Cat: hide() and be just like show() but with a bunch of spaces instead of characters.

Moving the Cat: Just like we did with the Ball and the Paddle. Just hide(), then change the x and y coordinates, and show()

Make your Cat speak: Add a speak() method.

The main() test program: Use the main() function to test each part of the Cat as you create it. In the end, set up your test program so that Mr. Lackey can see that you can create a Cat named sue. Have sue show herself, then speak, then move to another place on the screen.

Extra Credit: Set up the arrow keys so that sue can move to the right, left, up, and down.


Class Constructors
When you create a class in C++, it's common to write one or more Class Constructors. Suppose, for example, you wanted to create a Ball class to be used in a game of pong.

class Ball
{

private:
int myX;
int myY;

public:
Ball(int X, int Y);
move();

};

This Ball has only two private ints to hold its coordinates, a public constructor, and public move() method.

The constructor has to have the exact same name as the class itself, Ball. This constructor takes two integer parameters, probably intended to set the coordinates of Ball objects when they are created.

Code for the constructor might look like this:

Ball::Ball(int X, int Y)
{

myX = X;
myY = Y;

}

So all this constructor does is set its myX to the same value as the first parameter to the constructor and its myY to the value of the second parameter.

Here's how you might use this in a pong program:

#include "ball.cpp"

void main()
{

Ball myBall(5,5);
Ball yourBall(75, 20);
// now write a bunch of lines of code to play pong

}

As usual, this is not a complete program. Just enough to show you how the constructor is used.



Class Destructors
C++ classes can also have Class Destructors. Destructors are code that can be called when the object is no longer needed.

Here are some facts about Class Destructors

* They have the same name as the class, but with a tilde in front of it.
* If you don't write your own destructor code, C++ will write a basic destructor for you. You'll never see the code, but it will be used when the object is destroyed.
* If you don't explicitly call a destructor, C++ will do it automatically when the object is destroyed.

Try this simple object-oriented Hello, World program:

#include
#include

class Hello
{

public:
Hello();
~Hello();

};

Hello::Hello()
{

cout << "Hello, Sweet World" << endl;

}

Hello::~Hello()
{

cout << "Goodbye, Cruel World";

}

void main()
{

clrscr();
Hello myHello;
getch();

}

After you run the program, check the user screen. You might be surprised at the results!


Class Microwave
Project: A microwave oven manufacturer recommends that when heating two items, add 50% to the single-item heating time, and when heating three items, double the single-item heating time. Heating more than three items at once is not recommended.

Write a C++ class simulating such a microwave. Write a main() function to test the Microwave class.

Simple Sample: upload:micro.exe You can download and run this to get an idea of what your Microwave class might do.

Private Data: Give your Microwave class two private ints to store the x and y coordinates of its location on the screen, another private int to store the number of items being cooked, and two private ints to keep track of the single-item cook time and the total cook time in seconds.

The Default Constructor: Make a constructor that takes two integer parameters for the X and Y coordinates of the top left corner of the oven on the screen. Have the constructor set the initial values for the number of items and the single item cook time to zero.

Showing and hiding: Make a public show() method that shows the number of items in the oven, the single item cook time, and the recommended total cooking time. Make a hide() to erase the oven from the screen.

How you show the oven is up to you. The simplest (and probably the best to get started) would be to just go to the coordinates and print out the word "OVEN" and show the necessary data. For example:

RADAR RANGE:
# Items: 3
Single Item Time: 12 seconds
Total Cook Time: 24 seconds

You could write that code in a minute or two and it would be good enough to use while you are building the rest of the Microwave class. The corresponding hide() method would be just as easy to write.

Later, when you've gotten the rest of the Microwave working correctly, you can make a much fancier show(), maybe using box parts and some fancy ASCII art.

Getting user input: The Microwave oven needs a way to get information from the user. Write a public void method called askForInfo?() will do the following tasks:

* Prompt the user for the number of items and the single-item cooking time.
* Determine the correct total cooking time according to the manufacturer's recommendations.
* Set the private data members to the appropriate values.
* Call the show() method to re-display the oven with correct data.

Calculating the total time: Add a private method called calculateTime() that can set the total cook time based on the number of items and the single item cook time according to the manufacturer's recommendations.

Your calculateTime() method should use if-statements to decide what total time is appropriate. If the number of items is less than 1 or greater than 3, set the total time to zero.

References:

* Teach Yourself C++ in 10 Minutes: Lesson 5, pages 33 - 38.
* The Essence of Programming Using C++: Chapter 3, pages 22 - 31.

Add a cook() method that does the following:

* Somehow indicates that the oven is cooking.
* Shows a countdown of the number of seconds remaining to cook.
* Stops itself when the total cook time is reached.

Building a menu into the Mircrowave: Add a public method called menu() that returns a char. Here's an example of a simple menu method for the microwave. Your's might be a little different:

char Microwave::menu()
{

char key = '?';
gotoxy(myX,myY+5);
cout << "Press \"I\" for Info or \"C\" to cook: ";
key = toupper(getch());
if(key == 'C') cook();
if(key == 'I') askForInfo();
return key;

}

main() Test Function: Write a main() test function that does the following:

* Clears the screen.
* Creates and displays a Microwave object with reasonable coordinates.
* Calls the Microwave's menu() function in a loop like this:

while(myOven.menu() != 27);

* Clears the screen again before quitting.


Class Participation
One-fourth of your grade will be based on class participation demonstrating these behaviors:

* Don't waste class time.
o Come to class on time or with a pass explaining why you are tardy.
o Come to class prepared to work. Bring your textbook, writing implements, etc.
o Get right to work as soon as you get class.
o Work right through to the end of class. Do not line up at the door waiting for the bell to ring.
o Don't leave the classroom without asking permission and signing out before you leave.
* Contribute to class discussion.
o Pay attention to your teacher: Don't be chatting when you should be listening.
o Pay attention to your classmates when they are asking or answering questions.
* Be polite and courteous.
o Respect the feelings and property (both intellectual and physical) of others.
o Do not use rude language.
o Respect all school property.
o Clean up after yourself.
o Help other students when the opportunity arises.
* Understand and follow all school guidelines for use of the Internet.
o Use the Internet only for course-related work.
o No games, no chat, no mail, etc., etc.

Your grade will be determined according to the following rubric:

5 points: Consistently demonstrates these behaviors.

4 points: Occasionally fails to demonstrate one or two of these behaviors.

3 points: Persistently fails to demonstrate one or two of the behaviors despite prompting from the teacher.

Less than 3 points: Persistenly fails to demonstrate several of the behaviors despite prompting from the teacher.

Class Participation relates to these three Learning Expectations:

* Speak effectively
* Listen and view critically
* Demonstrate responsibility for learning and behavior.
* Treat others with respect and understand similarities and differences among people.
* Demonstrate the ability to work collaboratively and independently.


Class Payroll
Project: Write a C++ class called Payroll and a main() function to test it.

Private Data Members: Your Payroll class should have four private data members:

* An apstring to hold the worker's name. (Example: "Benjamin Franklin")
* A double to hold the worker's pay rate. (Example: 12.75)
* An int to hold the numbers of hours worked that week. Assume no partial hours worked. (Example: 40)
* A double to hold the total week's pay. (example: 510.00)

Chose good programming names for the variables and compile the class to make sure everything works so far. You'll have to include apstring.cpp to use the apstring data type.

The Constructor: Make a constructor for the Payroll class that takes three pieces of information in its envelope: an apstring for the name, a double for the pay rate, and an int for the number of hours worked that week.

When you implement the constructor, first have it set the worker's name, pay rate, and hours worked form it's three paramenter. Then make it calculate the week's pay and fill in that variable.

Another public method: Add a public method called printPayStub?() that will print out a pay stub for the worker for that week. The pay stub should include the worker's name, the rate of pay, hours worked, and total pay for the week.

The main() test function: Use your main() function to create a couple of Payroll objects and print out their pay stubs to make sure everything works as expected.

Extra for experts: Assume your workers get "time and half" for every hour they work over 40. Figure out how to make your Payroll class take this into account when calculating the total pay for the week. Print out a pay stub for a worker who works more than 40 hours to be sure that it works.


Class Person
Project: Write a class to make Person objects and a main() function to test the class. Make a new person' folder under your own folder on the T: drive.

How to Start: Of course, you will start like this:

class Person
{

};

Don't forget the semi-colon! And compile.

Privacy Issues: Now add the private and public parts. Don't forget the colons. And compile.

What does a Person have in mind? Maybe just a couple of integers, myX and myY. Should they be public or private? How about adding an age. That could be another int.

The Person constructor? The Person class should have a constructor. And the constructor should probably take two ints in the envelope so that when you create Person objects, you can place them on the screen. The Person constructor should also set the Person's age to zero. Check how you did it with the Paddle constructor. When you write the code for the constructor, all it has to do is set the Person's myX and myY equal to the x and y from the envelope. Don't forget to compile.

The Person has to be able to show him or herself: Writing the show() method for the Person requires some creativity. Like the Ball and Paddle, you have to use gotoxy(someX, someY) and then cout << "Some crazy stuff to look like a Person" See if you can figure out a way for Person to show its age when it shows itself. Or maybe you could have the Person speak and say its age.

Your Person should look totally different than the Person on the computer next to you. (Well, you know what I mean!)

ASCII Art: Here's a link to some ASCII art. Check out the people (but not the naked ones). http://www.geocities.com/SouthBeach/Marina/4942/ascii.htm

ASCII Art Line-by-Line: Making your program print ASCII art is not as easy as you might think. When the art requires more than one line of print on the screen, you can do something like this:

gotoxy(myX,myY+0); cout << "====";
gotoxy(myX,myY+1); cout << " + + ";
gotoxy(myX,myY+2); cout << " ^ ";
gotoxy(myX,myY+3); cout << " < > ";
gotoxy(myX,myY+4); cout << " ****** ";

A Weird ASCII Art Problem: Here's a problem you will likely have if you try to make your program print much ASCII art. The backslash character (this guy: \) has a special meaning in C++ and in many other computer languages. It means something like ignore the next character's actual value and print something special instead. That means when you try to print a backslash character using cout << the backslash itself doesn't acutally print and the character following it is apt to print as something weird.

The solution to this problem is also weird. For every backslash character you want to print on the screen, add an extra backslash character.

To see how this works, just make a simple little Test Tube Program that does this: cout << "\\";

Hiding the Person: hide() and be just like show() but with a bunch of spaces instead of characters.

Moving the Person: Just like we did with the Ball and the Paddle. Just hide(), then change the x and y coordinates, and show()

Changing the age of the Person: If your Person knows its own age, maybe you can have your Person say its age. Then you could add a void growOlder() and a void sayAge() methods to your person class. Maybe bind them to

The main() test program: Use the main() function to test each part of the Person as you create it. In the end, set up your test program so that Mr. Lackey can see that you can create a Person named adam (or eve). Have adam or eve show him or herself, then grow older, then move to another place on the screen.

Extra Credit: Set up the arrow keys so that adam or eve can move to the right, left, up, or down.


Class Rainfall
Project: Write a C++ Rainfall class that averages the rain fall for three months, April, May, and June, and writes out the results, something like:

Rainfall for April: 12
Rainfall for May : 14
Rainfall for June: 8
Average rainfall: 11.333333

Write a main() function to test the Rainfall class with several sets of data.

Private Data: Store each month's rainfall and the average in variables of type double .

The Constructor: Have the constructor take three double parameters, one for each month's rainfall. The constructor should set the values of each month's rainfall and calculate the average.

Public Methods: You only need one public method, printResults(). To get the numerical values to line up use the tab character '\t' as part of the character string in the output statements like this:

cout << "Rainfall for April:\t" << april;

In the code above, the \t will be replaced by a "tab" character.

Check that your program prints the correct results.


Class StopWatch
Design and build a stopwatch class that can be used to accurately time an event to 0.01 seconds.

* Your stopwatch should be able to display itself on the screen.
* When you press "R" for RESET, the stopwatch should reset itself to all zeros, like this: 00:00:00
* When you press "G" for GO, the stopwatch should start counting intervals of 0.01 seconds.
* When you press "S" for STOP, the stopwatch should stop counting and display the time since the last GO.

Extra Credit: Make your stopwatch display giant numbers that you can see on the screen from a distance.


Class Thermo
Project: Write a C++ class called Thermo (short for Thermometer) and a main() function to test it. Private: The Thermo class should know its own x and y coordinates on the screen. These can be ints. It should also know its temperature in both Fahrenheit and Celsius. The temps can't be ints or your thermometer will not be very accurate. Use float instead. Constructor: The constructor should take two int parameters (in the envelop) which it will use to position itself on the screen.

Have the constructor set each Thermo to room temperature (68° F.) when it is created. Use the conversion formula to calculate the Celsius equivalent of 68° F.

It probably also makes sense to have the constructor call the show() method so that the thermometer appears on the screen the instant it is created.
show() and hide(): Although it may never need to move, the Thermo should have show() and hide() methods. I would start with a simple show() that just writes something like this on the screen:

C = 37
F = 98.6

Later you could use the Box class to fancy it up a little.
The main() function: Obviously, your main function will have to create a Thermo object at a certain position on the screen. For example:

Thermo T(38,11);

This should pop a thermometer called T showing room temperature in both scales somewhere near the middle of the screen.
Heating up and cooling down: So far, your thermometer doesn't do much. It just sits on the screen showing room temperature in both Fahrenheit and Celsius scales. Add public methods to add or subtract one degree to or from the Fahrenheit temperature.

Of course, if you don't do anything else, the two temperature scales will soon get out of synch. So you'd better use the conversion formula again in each of these methods.
Key Bindings: After you've tested everything to this point, alter your main() test function so that your thermometer heats up when you press the up arrow key and cools down when you hit the down arrow key.


Class Tire Pressure
Project: An automobile manufacturer has designed an electro-mechanical device to measure the pressure in the tires of an automobile while the car is moving. Now they need some software to convert the tire pressure measurements to warning messages to be displayed on the car's dashboard. You've been hired to write a C++ class to do that job.

Sample Executable: upload:tires.exe

Private Data: Ideally, the two front tires would always have exactly the same pressure and it would always be exactly the correct pressure. The same would be true for the back tires. But the correct pressure for the back would usually be different than for the front. Of course, the ideal situation hardly ever exists. If you write your class to only check for the ideal situation, then the driver will constantly get error messages about bad tire pressure.

So let's say we need four private ints for the maximum and minimum pressure in the front and in the rear: Fmin, Fmax, Rmin, Rmax.

And we need another four private ints for the actual pressure in each of the four tires: LF, RF, LR, RR.

The Constructor: Make a contructor that takes four integer parameters and uses them to set max and min data. You can also have your constructor set some default values for the four pressure numbers.

show() method: Make a show() method that simulates an LCD display of the four tires and shows the current pressure in each tire. Also, if the pressure in any tire is out of the acceptable range, display some sort of warning message to the user. This could be as simple as having the number for any pressure that's out of range be displayed with an exclamation point after the number.

getPressure() method: You need a way to get the pressure readings into the class. In a real application, this would have to be some sort of interface with the electro-mechanical pressure sensing devices. But we don't really have any pressure sensing devices, so let's just make a method that will use cin >> to get the information from the keyboard.

menu() method: Make a menu() method that will allow you to get new data when you want it and quit when you want to.

main() method: Make a main() method to test your class. In the beginning, just use main() to test as you go. When you think everything is working properly, you can change main() to look something like this:

void main()
{
clrscr();
P Tpressure(28,32,25,30);
while(P.menu() != 27);
clrscr();
}

Remember, you shouldn't start with a main() like the above!


Class Truck
Project: Write a class to make Truck objects and a main() function to test the class. Make a new truck folder under your own folder on the T: drive.

How to Start: Of course, you will start like this:

class Truck
{

};

Don't forget the semi-colon! And compile.

Privacy Issues: Now add the private and public parts. Don't forget the colons. And compile.

What does a Truck have in mind? Not much. Maybe just a couple of integers, myX and myY. Should they be public or private? How about adding a speed? That could be another int.

The Truck constructor? The Truck class should have a constructor. And the constructor should probably take two ints in the envelope so that when you create Truck objects, you can place them on the screen. The Truck constructor should also set the speed to zero. Check how you did it with the Paddle constructor. When you write the code for the constructor, all it has to do is set the Truck's myX and myY equal to the x and y from the envelope. Don't forget to compile.

The Truck has to be able to show itself: Writing the show() method for the Truck requires some creativity. Like the Ball and Paddle, you have to use gotoxy(someX, someY) and then cout << "Some crazy stuff to look like a truck" See if you can figure out a way for Truck to show its speed when it shows itself. You could even have a separate place on the screen for your speedomter, something like this:

gotoxy(60,25);
cout << "Speed: " << mySpeed;

Your Truck should look totally different than the Truck on the computer next to you.

ASCII Art: Here's a link to some ASCII art. Check out the trucks. http://sharonb.hypermart.net/ascii.htm

ASCII Art Line-by-Line: Making your program print ASCII art is not as easy as you might think. When the art requires more than one line of print on the screen, you can do something like this:

gotoxy(myX,myY+0); cout << "====";
gotoxy(myX,myY+1); cout << " + + ";
gotoxy(myX,myY+2); cout << " ^ ";
gotoxy(myX,myY+3); cout << " < > ";
gotoxy(myX,myY+4); cout << " ****** ";

A Weird ASCII Art Problem: Here's a problem you will likely have if you try to make your program print much ASCII art. The backslash character (this guy: \) has a special meaning in C++ and in many other computer languages. It means something like ignore the next character's actual value and print something special instead. That means when you try to print a backslash character using cout << the backslash itself doesn't acutally print and the character following it is apt to print as something weird.

The solution to this problem is also weird. For every backslash character you want to print on the screen, add an extra backslash character.

To see how this works, just make a simple little Test Tube Program that does this: cout << "\\";

Hiding the Truck: hide() and be just like show() but with a bunch of spaces instead of characters.

Moving the Truck: Just like we did with the Ball and the Paddle. Just hide(), then change the x and y coordinates, and show()

Changing the speed of the Truck: If your Truck knows its own speed, maybe you can put the speedometer in the show. Then you could add a void speedUp() and a void slowDown() methods to your truck class. Maybe bind them to the plus and minus keys so that when you type + the speedometer shows a higher number and - makes it lower.

The main() test program: Use the main() function to test each part of the Truck as you create it. In the end, set up your test program so that Mr. Lackey can see that you can create a Truck named reo. Have reo show itself, then speed up, then move to another place on the screen.

Extra Credit: Set up the arrow keys so that sue can move to the right, left, up, and down and the + and - keys control the speed.


Computer Science Humor
---Correct Change
---Cpp Wiki
---Declaring A Class
---Do The Simplest Thing That Could Possibly Work
---Dummy Function
---Dummy Functions
---Elements Of Computer Programming
---English Height To Metric
---Essential Questions
---Fantasy Game
---Fibonaccii Series
---Fixing The Giant CD
---Gauss Program
---Getters And Setters
---Grading System
---Hangman Dot Cpp
---Home Page
---Independent Projects
---Integer Cruncher
---Internet Deli
---Journal Entries
---Journal Entry Format
---Journal Format
---Last Chance Gas
---Learning Expectations
---Letter Counter
---Magic Number
---Making A Box
---Menu Driven Programs
---Microwave Oven
---More Tire Pressure
---Multiplication Table
---Occasionally Asked Questions
---Open House
---Open House Notes
---Order Checker
---Paddle Dot Cpp
---Parent Teacher Communication
---Passing Data To Functions
---Pong
---Pong Code
---Pong Dot Cpp
---Pong Rubric
---Private Class Data
---Programming Projects
---Quiz 1
---Quiz 2A
---Quiz 2B
---Reading From A File
---Recent Changes
---Returning Data From Functions
---Screen Coordinates
---Sentinel Controlled Loops
---Snake
---Snake Dot Cpp
---Snake Quiz
---Some Looping Programs
---Splash Screen
---Steam Engine Efficiency
---Talbot's Rule
---Test Tube Program
---Testing
---Testing Apstring
---Tests And Quizzes
---The Letter E
---Tire Pressure
---True Or False
---Tutorial Links
---Tutorial Pages
---Wedge Of Stars
---What Is A Function
---Writing To A File


Page Information

  • 6 months ago [history]
  • View page source
  • You're not logged in
  • No tags yet learn more

Wiki Information

Recent PBwiki Blog Posts