0% found this document useful (0 votes)
5 views3 pages

Cplab 2 Up

Uploaded by

Syed Iqbal Ahmed
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)
5 views3 pages

Cplab 2 Up

Uploaded by

Syed Iqbal Ahmed
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/ 3

s CSL-113: Computer Programming Lab

Lab02: Variables and Data Types

Objective(s):
1. To be able to use standard data types in C++
2. To be able to Declare and Initialize Variables
3. To be able to apply Declare and Define Constants
4. To be able to use of Arithmetic Operators

Exercises

Exercise 1 (User Input)

Write a program that takes 3 values from user. Two values of integer and one value of float data
type. Print each result on one line.

Exercise 2 (Arithmetic Operations)

Write simple calculator program takes an arithmetic operator +, -, *, / and two operands from the
user. Then, it performs the calculation on the two operands depending upon the operator entered
by the user.

Expected Output:
s CSL-113: Computer Programming Lab

Exercise 3 (Percentage)

Write a C++ program that prompt input roll number, student name and marks of three subjects
1. Computer Programming = CP
2. Introduction to communication Technologies = ICT
3. Data Science = DS
Calculate total marks, percentage of student.
Marks percentage = marks obtained / total * 100

Exercise 4 (Calculating Value of x)

Write a program to solve the following equation. Take value of a and b from user.
X = (a + b)²

Exercise 5 (Word Game)

Write a program that plays a word game with the user. The program should ask the user to enter
the following also display user age in days from current date.

User’s name
Year of birth (eg. 1990)
Name of university
A favorite hobby
A pet’s name

Write a program that will produce an outcome as below:


s CSL-113: Computer Programming Lab

Exercise 6 (Calculating Value of x)

Hypotenuse refers to the right angle in a triangle (as shown in the side opposite right-angled the
diagram below).
Hypotenuse can be calculated using the following formula:

Area of this right-angled triangle can also be calculated using the following formula: a = ½ * x *
y

Note that:
h=Hypotenuse
x= adjacent
y= opposite

Write a C++ program that prompt user to enter value of X and Y. You have to calculate the value
of Hypotenuse (h) and Area(a).

You might also like