Lab 2 Chapter 1 & 2
By Dr. Yingwu Zhu @ SeattleU
[Objectives]:
- To learn the basic components of a C++ program
- To gain a basic knowledge of how memory is used in programming
- To understand the basic data types:
- Integer
- Character
- Float
- Boolean
- String (the string class is treated as a data type here)
- To introduce the five fundamental instructions and to use the assign and output statements
- To develop a small program using simple C++ instructions
[Assumptions]:
- Students have a basic knowledge of the programming environment. They can open, edit, compile and run simple programs.
- Students are familiar with the output and assignment statements in C++
- Students are familiar with the general basic outline of a C++ program that they can generate a simple program
- Students are familiar with the basic data types including character and string (class treated as a data type)
[Tasks]:
Task #1 -- Compiling a Program with a Syntax Error
This lab gives the student experience in bringing in a program and detecting a simple syntax error. The program source file is Lab2_semiprob.cpp.
After you successfully put the program in the directory, you need to compile it. See what happens. If an error occurs, you need to correct it. In the end, you need to create the executable for the program and run it.
Task #2: --Working with the cout Statement
This is a simple lab that works with the cout statement. Copy the program Lab2_name.cpp and edit it to make it complete such that the program will print the programmer’s name, address, and phone number as indicated in the program Lab2_name.cpp.
Task #3: -- A small Program using cout
Write a program named Lab2_pattern.cpp, which produces a diamond-shaped pattern as shown below:
*
/*\
//*\\
///*\\\
\\\*///
\\*//
\*/
*
Task #4: --Working with Constants, Variables and Arithmetic Operators
This lab continues to work with the cout statement and introducesthe assignment statement.
Copy the program Lab2_circlearea.cpp and edit it to make it complete such that the program will output the circumference and areaof the circle with a given radius.
Task #5: --Working with Characters and Strings
This lab introduces characters and the string class which is treated as a data type. Copy the program Lab2_stringchar.cpp, and edit it to make it complete such that the program will display the messages as indicated in the file.
Task #6: -- Independently Develop a Small Program
This lab requires you to create a program from a scratch. The program, named Lab2_rectangle.cpp, will print out the perimeter and area of a rectangle with length of 8 and width of 3. At the first glance, it appears a daunting task to most of you, if not all. However, you should not find it too difficult since it is so similar to Task #4. You must declare the length and width of the rectangle const integers in your program.