0% found this document useful (0 votes)
30 views

Csc425 Lab 4

Uploaded by

iraleayah
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Csc425 Lab 4

Uploaded by

iraleayah
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CSC425 Introduction to Computer Programming

Lab 4: Operator manipulation (addition, subtraction, multiplication,


division, modulus)

Objectives:

1. Writing C++ programs based on problems given.


2. Use operators to solve problems in the C++ codes.

Question 1:

The formula to calculate the Molar Mass (M) of gas is:

0.0821 * P * V * W / T

Where
V is the volume of the gas in cm3,
W is the mass of the gas in gram
T is the temperature in Celsius
P is the pressure of the gas in atom

Write a program to calculate the Molar Mass (M) of a gas. The program should request all the
necessary data from the user. Make sure that you use the appropriate data types as learnt in
class. Save this source code file as Lab4Q1.cpp.

Question 2:

Given the following variables which have been assigned specific values as below:

A = 100, B = 50, C = 25, D = 40, E = 3.

Write a program to display the results of the followings:

i) A plus B minus C
ii) A divide by B times C modulus E
iii) D to the power of E
iv) Sum of squares of A and E

Make sure that you use the appropriate data types as learnt in class. Save this source code file
as Lab4Q2.cpp.

Question 3:

Write a program to ask the user to enter the radius of a circle. Then calculate the area of the
circle and the circumference using the formula:
Area of a circle = 3.142 * radius * radius

Circumference = 2 * 3.142 * radius

Both the value of area and circumference must be displayed to the user.

Make sure that you use the appropriate data types as learnt in class. The value for pi (3.142)
must be declared as constant. Save this source code file as Lab4Q3.cpp.

Question 4:

Given the initial value of x is 36.

Write a program that will produce the output as below:

x is 35
x is 34
x is 34
x is 33
x is 34
x is 35
x is 36
x is 35
x is 30

Use the increment and decrement operator that you have learned in class. Save this source
code file as Lab4Q4.cpp.

Question 5:

Aqil is going to paint the front of the house for her mum and dad. Write a program to find the
area that needs to be painted. You must ask the user to input the width and length of the
windows, door and wall to determine the area that needs to be painted.
To submit your answers, in a new MS Word file, include:
i. A cover page that consists of your
a. name, matric number, group and title: LAB 4 TASK
ii. For every question,
a. Paste a screenshot of the source codes file
b. Paste a screenshot of the input/output screen

Example:

You might also like