0% found this document useful (0 votes)
12 views6 pages

Exercise CSC425

Uploaded by

2024745461
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views6 pages

Exercise CSC425

Uploaded by

2024745461
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Exercise CSC425 – Week 2

1. Write, run, and test this program:

 Explain the purpose of static_cast in this program.


- Static cast USED IN C++ to convert data type to another. Used for
converting relating types, like pointers or numeric types

 Explain the difference in terms of output if you change static_cast<float>(a) to


static_cast<int>(a) and static_cast<float>(b) to static_cast<int>(b).
- It changes data types from float to integer
- This means any fractional part of these values will be truncated (not
rounded) resulting in integer values
- If a=5.7 then would give 5
- If b=3.9 then would give 3

2. Write, run, and test this program to get the output.


Explain the difference between && and || after testing this program a few times?
&& logical AND operator that returns true if both conditions are true to be executed
|| is a logical operator that returns true if at least one of the conditions is true to get
executed

3. The source code below cannot be compiled and run because of some errors.
Find out what is the error(s) and fix it. Then, run this program correctly.
#include <iostream>
using namespace std;

main()
{
int num;
cout<<"Enter a number :";
cin>>num;
if(num%2==0)
{
cout<<"This is an even number";
}
else
{
cout<<"This is an odd number";
}
return 0;
}

4. Write and run this program.


Then, write a simple code that prompts the user to enter a number to calculate
the cube power of that number.

5. Using your programming knowledge, create a simple program that converts from
meters to centimeters (please draw a flowchart too).
Begin

Read measurement in M

CM = M * 100

Display measurement in CM

End
6. Write, run and test this program:

Unfortunately, program above return some errors. Hence, find the errors and fix
it.

You might also like