LAB 1
DCS 5088 OBJECT ORIENTED PROGRAMMING
LAB 1
LAB 1
ObjectiveAt the end of this lab activity, the students should be
able to:
Compile the C ++program using Microsoft Visual C++. Run the
program. Write a simple C++ program. Implement the main concepts in
object-oriented programming.
Introducing compilation C++ using Microsoft Visual C++.Microsoft
Visual C++ 6.0
This section will explain how to edit, compile and run a C++
programme based on object, using Microsoft Visual C++.
To start Microsoft Visual C++:
Choose Start>All Programs>Microsoft Visual Studio 6.0
>Microsoft Visual C++ 6.0
Visual C++ 6.0 interface
When you activate Microsoft Visual C++ 6.0, you will see its
main screen.
The main screen consists of Title Bar, Menu Bar, shortcut keys,
Standard Toolbar, Minimize, Maximize, Close, Close window and
project workspace window.
Main screen of Microsoft Visual C++ Steps in developing,
compiling and executing C++ program.
To develop, compile and run a C++ program, follow these
steps:
i. In the main screen, choose the File menu, then click New
The New Dialogue box will be displayed. Choose C++ source file
and click OK.
A blank window text editor will be displayed.
ii. Type your source code C++ in windows texts editor.
iii. Save your file.
iv. Choose compile [filename] from Build menu. If you dont have
a workspace for your code, a dialogue box will be displayed where
there will a question asking whether you would like to build a
workspace.
This is the dialogue box that will be displayed after the fourth
steps taken
v. If there are any errors or warning messages in the program,
Visual C++ will display it in the output window. If there are no
errors or warning messages, you can execute your program.
Program with no errors
The output window shows the program with free errors and
warningsvi. Choose Execute [File name] from menu Built Output for
program as shown below.
Example of output programIf the program has an error, error
message will be shown on the output window as below. The error
should be corrected before executing the program.
An output window that shows program with errors
Reminder: If you would like to compile a new program, you need
to follow the instructions below.
If you choose the Yes button, thus the previous program file
will be closed accompanying with workspace too. On the other hand,
if you choose No, thus only workspace for of the previous program
will be closed and the file of the previous program will
remain.
LAB EXERCISE 1Compile and run program
i) Type the program below.
The purpose of this program is to show how to include data and
display it on the screen.
ii) Save the program under the name of program1.cpp.
Compile the program. If there is any error, correct it until the
program is free of errors.
iii) Modify your program, so that it can accept two numbers.
After that, compare both numbers to get which one is the biggest
number using selection structure.iv) Display the biggest number
three times using looping structure. LAB EXERCISE 2Create a C++
program that accepts 3 inputs from user to calculate the Volume of
a box.
(Volume = Width * length *height)
i. Create 3 variables of type float in your program
ii. Your output may look something like this:
------------------------------------------
To calculate the volume of a box
------------------------------------------
Enter width, length, height
43.2 33.3 33.5
The volume of a box is 48191.8
Press any key to continue
iii. Also, include proper source codes[use if statement] in your
program so that it will only accept positive values. If the user
enter negative values, the user will receive a message and could
not get the volume displayed. The output may be something as
below:
---------------------------------
To calculate the volume of a box
---------------------------------
Enter width, length, height
-1 3 -22
you've entered negative values!
Please try again another time
Press any key to continue
Answer:#include
using namespace std;
int main()
{
float width,length,height,volume;
cout