Assignment 4 Due Tuesday, October 11 at 3:20pm on Catalyst
Assignment 4.1: My Student Information (10 pts)
- Open up a new C++ file in Codeblocks. If you need help remembering how to open a file in CodeBlocks, see the Tutorials page.
- Name the file info.cpp.
- Write your name and section info at the very top of the file by placing them inside of a multi-line comment, like so:
/** * Your Name Here
* CIS 22A Section
*/ - The objective of your program is to store some values in a variable and then print those values to the console.
- Below your multi-line comment, write the lines of code to include the iostream library and the standard namespace.
- Then create a new main function
- Note that main might have a return 0 statement like the one below:
int main() { return 0; }
- This
statement is optional. If you do not place this line of code inside of
main, the compiler will automatically do it for you (without your
knowledge).
- Now, declare 3 new variables at the top of your program
- One integer
- One char
- One double
- The integer variable will be used to store your student ID number. Give it an appropriate name of your choice.
- The char variable will be used to store the first initial of your last name. Give it an appropriate name of your choice.
- The
double variable will be used to store the number of years you have been
at de Anza. Give it an appropriate name of your choice.
- Next,
assign the correct value to each of these variables. You many do this
on the same line in which you declared the variables, or on a separate
line.
- For example, you might have a statement that looks like this:
int id = 555999; - Or, you might have 2 statements that look like this:
int id; id = 555999;- Both options are correct.
- Next, you will print out the contents of these variables using cout statements.
- You need one cout statement per variable and one \n or endl per cout statement.
- cout statement 1 should say: My student id #: <your student id here>
- cout statement 2 should say: The initial of my last name: <your initial here>
- cout statement 3 should say: Number of years at de Anza: <your number of years here>
- Thus,
when your program is run, the output should be identical to the
following (except your information will be below, not my sample
information):
My student id #: 5559999 The initial of my last name: P Number of years at de Anza: 1.5- When you are finished, and your output is identical to the sample output above, submit your info.cpp file to Catalyst
Assignment 4.2: Area of a Football Field (10 pts)
- Note that this assignment was originally Activity 4.1 from Thursday's class. It is renamed here and will now be due on Tuesday at 3:20pm.
- Open up CodeBlocks.
- Create a new file called football.cpp.
- Put a block comment at the start of your program with your name and section information
- Add the library and namespace
- Create a main function
- Create a variable called length and assign it the value 360 (pro football fields are 360 feet in length)
- Create a variable called width and assign it the value 160 (pro football fields are 160 feet in length)
- Create a variable called area and assign it the value of length * width;
- Run the program and verify that there are no errors.
- Is this program satisfactory?
- Now, alter the program to print out the value of the variables, including the area along with a message.
- Below is one of the cout statements you will need.
cout << "The length of a football field is " << length << " ft\n"; //add two more cout statements like the one above
- When you are finished and run your program, you should see the following messages print to the console:
The length of a football field is 360 ft. The width of a football field is 160 ft. Therefore, the area is 57600 ft2. - Submit your program to Catalyst when you are finished.
|
|