- SAVE EVERY PROGRAM YOU WRITE ON THE H DRIVE.
- Regular 100/80/60 Quizzes
- Final Exam
Code::Blocks is the IDE (Integrated Development Environment) that we will be using to write C++ programs. It is open source and can be downloaded for Windows or Mac.
- Download from codeblocks.org. Download the
version with
mingw-setup
in its name. The filename will be something likecodeblocks-##.##mingw-setup.exe
. - Hello World with Code::Blocks
- C::B User Manual
- In class notes: Intro to Programming. Compile "Hello World".
- Hello World with Code::Blocks
- In class notes: Explanation of "Hello World".
Topics:
- int, double, string
- creating variables
- assigning values
- cin
+, -, *, /
The four steps are:
- Understand the problem completely.
- Design the program using a flow chart.
- Double check the logic of your design.
- Code.
if statements and if..else
- Write a calculator program.
- First ask the user to choose between +, -, *, and /. (Hint, use a string variable)
- Second then asks the user to enter two numbers (hint, use two doubles).
- Third then displays the result of the arithmetic calculation in a user friendly manner.
For inspiration, look at some of the calculator examples in the Pickup box > Wear > INT 910 > calculator examples
Topics:
In-Class Challenge: Write a program that asks the user to enter an integer between 1 and 1,000,000. Then print the answer to the number divided by 10 and the number modulus 10.
- integer division
- modulus
- casting
In-Class Challenge: Write a program that asks the user to enter an integer between 1 and 1,000,000. Then print the answer to the number divided by 10 and the number modulus 10.
- Create a new project in codeBlocks and call it calculator2.
- Copy the code from your first calculator and save it as
calculator2.cpp
. - Add the file
calculator2.cpp
to your new project. - Add modulus (%) as an option to your menu
-
Modify the calculator program so that the user can enter their name:
- Put this line of code with your other variable declarations:
string name;
- At the beginning of the program ask them to enter their name:
cout << "Please enter name: ";
getline(cin, name); - Later in the program, address them by name:
cout << "Hello " << name << "\n";
- Put this line of code with your other variable declarations:
- Learn about do..while loops:
- Read Tutorial 1,
- Tutorial 2,
- Video Tutorial (use headphones)
- Add a do...while loop to your menu, so that if the user chooses an option not on the menu, it prints an error and repeats the menu.
- Test your new program.
- Copy
Calculator 2
and save it as a new project calledCalculator3
. - Add
fabs(), sqrt(), ceil(), floor(), pow()
frommath.h
to the next version of your calculator. - Using a do...while loop, modify your program so that it asks the user if they want to do another calculation. If they answer "Y", it does.
- Add a cool ASCII Art splash screen.
- Test your new program.
do { cout << "Please enter the number: "; cin >> num1; cout << "\n"; if(cin.good() == 0) { cout << "You must enter a NUMBER!!!\n"; cin.clear(); cin.ignore(80, '\n'); continue; } break; } while (true);
Add color to your calculator program. Download colours.h and colours.cpp
Today you are going to make your Calculator more user friendly. Here is how
to do it:
- Add a splash screen using ascii art.
- Go to Chris.com or Ascii Text Title Generator to look for ascii art. Choose art that is less than 25 lines long and less than 80 characters wide.
- Paste it into the program
- Add
cout "
at the beginning of each line,\n";
at the end of each line. - If the ascii art has any
\
characters in it, replace it with\\
. This will print one backslash. - If the ascii art has any
"
characters in it, replace it with\"
. This will print one double quote. - Run the program and make sure the ascii art looks good. If not, fix it.
- Improve the look of your menu. Here are some screen shots of nice looking menus.
- Clear the screen occasionally using
system("CLS");
. You have to add at the top of your program. - Run some old calculators under Examples to see how to use blank space and lines to make output easier to read.
- Your calculator must work.
- Offers the following functions: +, -, *, /, %, absolute value, square root, power, ceiling and floor.
- If the user chooses a symbol NOT on the menu, it displays an error message, clears the screen, and displays the menu again.
- It allows the user to repeat the program.
- It asks for and uses the user's name.
- It has a splash screen.
- It has color.
- It is as user-friendly as possible.
- It accepts both uppercase and lowercase characters in the menu.
- If the user types a character when a number is expected, it prints an error and allows the user to reenter a number.
- Basic Requirements ( /20)
- Awesomeness of the Design ( /5)
Useful Links
Today you will design the Splash Screen (the start up screen at the beginning of your program) for the upcoming project: The Lemonade Stand.
The splash screen can earn you up to 2 out of 10 marks for your personalized Lemonade Stand.
- Create a new project in CodeBlocks. Instructions can be found here.
- Add colors.h as a new file to your project. Instructions can be found here.
- Play a selection of the Lemonade Stands found here: Examples
- Go to Chris.com and Ascii Title Generator for ascii art.
- Use creative colour.
- Recall to animate ASCII Art, first include
windows.h
and use the command Sleep to pause for a certain number of milliseconds, followed by a clear screen as shown:
Sleep(500); // sleeps for 1/2 second
system("CLS");
To animate ASCII Art, first include
and use the command Sleep to pause for a certain number of milliseconds, followed by a clear screen as shown:
windows.h
and use the command Sleep to pause for a certain number of milliseconds, followed by a clear screen as shown:
Sleep(1000); // sleeps for 1 second
system("CLS");
In windows.h
Beep(523,500); // 523 hertz (C5) for 500 milliseconds Beep(587,500); Beep(659,500); Beep(698,500); Beep(784,500);
In windows.h
//allows ShowWindow to work, put at top of program, before main #define _WIN32_WINNT 0x0500 // put at top of main ShowWindow(GetConsoleWindow(), SW_MAXIMIZE);
- Download this template.
- Complete as shown in class.
- Make it your own by adding extras.
Basic Stand Completed /5 - can play a complete game (given in class) without errors - all numbers are accurate - no bugs / errors User-Interface Improvements: /10 1 mark per improvement that works without errors. ** with up to 3 bonus marks for exceptional creativity and programming ** Examples: Awesome Splash Screen Address the User by Name Awesome use of color Appropriate use of sound Error checking on: maxDays (not less than 0) incomeGoal (not less than 0) price (not less than 0, max price) buyAmounts (not less than 0, OR allows user to sell inventory) Play Again Win/Lose Screens Levels (easy, hard, presets #days and income goal) Weather Burglars/Allowance Improved interface
25 multiple choice questions.