- Friday C++ example:
Roman Numerals Textbook Problem from page 220.
- Illustrates an IF with an ELSE clause. This is done for error checking.
- Introduces the SWITCH statement.
- Converting Arabic numbers in range 1, 2, ..., 9 10 to Roman Numerals:
Please enter a value between 1 and 10: 8
The Arabic number 8 with Roman Numerals is: VIII
- I, II, III, IV, V, VI, VII, VIII, IX, X are ten of the eleven possible
outputs the program will produce.
- The other output the program can produce is an error message, such as:
Sorry. The number has to be 1, 2, ..., 9 or 10!
- EVEN number 2,3,4,6,8 and 10 vs ODD numbers 1,3,5,7 and 9:
evenOdd.cpp program to illustrate
the if ... else if ... else and variation on the switch statement.
- ASSIGNMENT HANDED OUT:
Programming Assignment #1 -
Magic Dates, Area of Rectangles, and Body Mass Index.
Three programs from chapter four of the textbook.
- The three C++ programs are turned in by using a user friendly
web browser based submit system.
- You will learn and get practice with how to do that in a hands-on class
or classes during week #3 on Wednesday and it will be demonstrated Friday too.
- The programs will be due and can be submitted anytime before 9 pm on
Saturday, January 30th.
- Each of your programs will have a comment block that indicates
who wrote the program (your name) and what the name of the program file is.
The program file names will be:
dates.cpp All lower case letters for the file name
rectangles.cpp All lower case letters for file name
BMI.cpp BMI is an acronym, so all UPPER CASE letters B M I
- Wednesday 01/20 One page Handout -
One Way and Two Way Selection and While loops.
A few examples and explations from our textbook for if, if else and while.
Sequencing (s1; s2; s3; s4; ..., sn)
Selection
One Way Selection Two Way Selection
if ( Boolean condition ) if ( Boolean condition )
{ {
s1; block of statements
s2; often called the
... then clause...
sn; }
} else
{
block of statements
called the else clause
}
Repetition
Not introduced yet:
We will look at while, do while and for loops
----- -------- ---
Subprograms
To be introduced during week #3
- Read and review carefully:
C++/Introduction - Hello World! basic example explained.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
cin.get();
return 0;
}
- C++/Variables
and User Input basics. Declare, Assign, Types (floats versus doubles)...
#include <iostream>
using namespace std;
int main()
{
char myChar;
cout << "Enter a characer. ENTER: ";
cin >> myChar;
cout << "You entered: " << myChar << endl;
return 0;
}
- Simple C++ Math and using the C++ math library.
- Conditional Statements in C++ - the if ... then conditional statement
with a then clause and an else clause.
Note: == is for equality comparison but = is for assignment operator
== is a relational operator as is >=, <=, >, < and !=.
if (x == 7) {
//then clause is executed only if x does indeed contain the integer value 7
}
else {
//else clause is executed if the preceding if condition evaluated to false
}