
Educators: Earn a free Gold upgrade by joining the PBwiki Back To School Challenge.

Questions? Get live answers at PBwiki's weekly office hours (1 PM Eastern, Weds September 3)
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/
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:_________________
#!/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)
{
}
close(OUT);
Sample Input / Output:
Be careful not to add the number of integers (in the example, 5) into the sum.
You will need to use the constant PI which you approximate as 3.1416
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.
class Ball
{
};
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
class Ball
{
};
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
{
};
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
class Ball
{
};
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
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.
Sample Input / Output:
This could be used as part of an index for a book. To print out the dots, use cout inside a loop body.
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.
The void draw() function:
for(int x=X1+1; x
}
The hide() function:
Now see if you can create grow() and shrink() functions.
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 Ball
{
};
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)
{
}
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()
{
}
As usual, this is not a complete program. Just enough to show you how the constructor is used.
Here are some facts about Class Destructors
Try this simple object-oriented Hello, World program:
#include
#include
class Hello
{
};
Hello::Hello()
{
}
Hello::~Hello()
{
}
void main()
{
}
After you run the program, check the user screen. You might be surprised at the results!
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:
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:
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:
Add a cook() method that does the following:
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()
{
}
main() Test Function: Write a main() test function that does the following:
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:
Private Data Members: Your Payroll class should have four private data members:
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.
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.
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:
In the code above, the \t will be replaced by a "tab" character.
Check that your program prints the correct results.
Extra Credit: Make your stopwatch display giant numbers that you can see on the screen from a distance.
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:
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:
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.
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:
Remember, you shouldn't start with a main() like the above!
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.
Page Information
|
Wiki Information |
Recent PBwiki Blog Posts |