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

Lab 3 Exercises

Uploaded by

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

Lab 3 Exercises

Uploaded by

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

CCP6114 Programming Fundamentals Page 1

Student ID: 241UC240CT

Student Name: Pravin Raj A/L Sundara Raj

Exercise 2

Write the size of the data types in the following table:

Data type Size (bytes)


int 4
double 8
float 4
char 1
short 2
long 8

Exercise 3

3.1:

Output of this program for a = 3, b =5, c = 2.5


= 15.5

3.2:

Write the C++ expressions in the following table:

Equation Expression A B C Output


a/b - 1 3 5 -0.4

(a+c)/b 3 5 2.5 1.1

b/(a-c) 3 5 2.5 10

(b+c)*(b+c) 5 2.5 56.25


CCP6114 Programming Fundamentals Page 2

Exercise 4

4.1:

Submit the C++ program.

#include <iostream>

using namespace std;

int main() {
const double PI = 3.14;

float radius;

cout << "Enter the radius of the circle: ";


cin >> radius;

double area = PI * radius * radius;


double circumference = 2 * PI * radius;

cout << "Area of the circle: " << area << endl;
cout << "Circumference of the circle: " << circumference << endl;

return 0;
}

Submit a screenshot of your program output.


CCP6114 Programming Fundamentals Page 3
4.2:

Submit the C++ program.

#include <iostream>

using namespace std;

int main() {
int length, width, area, perimeter;

cout << "Enter the length of the rectangle: ";


cin >> length;

cout << "Enter the width of the rectangle: ";


cin >> width;

area = length * width;


perimeter = 2 * (length + width);

cout << "The area of the rectangle is: " << area << endl;
cout << "The perimeter of the rectangle is: " << perimeter << endl;

return 0;
}

Submit a screenshot of your program output.


CCP6114 Programming Fundamentals Page 4
4.3:

Submit the C++ program.

#include <iostream>

using namespace std;

int main() {
int total_seconds;

cout << "Enter the number of seconds: ";


cin >> total_seconds;

int hours = total_seconds / 3600;


int minutes = (total_seconds % 3600) / 60;
int seconds = total_seconds % 60;

cout << hours << " hours, " << minutes << " minutes and " << seconds << " seconds" << endl;

return 0;
}

Submit a screenshot of your program output.

You might also like