0% found this document useful (0 votes)
17 views5 pages

PF Y8 Lab 4

Uploaded by

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

PF Y8 Lab 4

Uploaded by

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

Programming Fundamentals

Lab – Y8

Lab 4
Lab 4 Programming Fundamental Lab Y8

Contents
Data Types............................................................................................................................................... 2
Objective ............................................................................................................................................. 2
Overview ............................................................................................................................................. 2
C++ Data Types:............................................................................................................................... 2
Sample Task ........................................................................................................................................ 2
Lab Tasks ................................................................................................................................................. 3
Task 1: ................................................................................................................................................. 3
Sample Output .................................................................................................................................... 3
Task 2: ................................................................................................................................................. 3
Sample Output .................................................................................................................................... 3
Task 3: ................................................................................................................................................. 4
Formula: .......................................................................................................................................... 4
Sample Output .................................................................................................................................... 4

1
Lab 4 Programming Fundamental Lab Y8

Data Types
Objective
The objective of this lab is to learn the basic structure of the C++ program. At the end of this lab,
students will be able to declare, initialize, input and output a variable and they will also be able to
differentiate between different data types.

Overview
C++ Data Types:
There are only a few basic data types in C++ Like:

• char
• int
• float
• double

Sample Task
Write a program to add two integer numbers.

#include <iostream.h>
using namespace std;
int main()
{
int integer1;
int integer2;
int sum;
cout<<"Enter first integer\n";
cin>>integer1;
cout<<"Enter second integer\n";
cin>>integer2;
sum = integer1 + integer2;
cout<<"Sum ="<<sum;
return 0;
}

2
Lab 4 Programming Fundamental Lab Y8

Lab Tasks
Task 1:
Write a program which takes 2 integers as input from user and prints their sum, product, difference,
product, division and remainder.

Sample Output
Enter first integer 100
Enter second integer 72
Sum is 172
Difference is 28
Product is 7200
Quotient is 1
Remainder is 28

Task 2:
Write appropriate C++ statements to match the description in each of the following comments.

a) Declare a float variable for the radius


b) Declare a float variable for the diameter
c) Declare a float variable for the circumference
d) Declare a float variable for the area
e) Declare a constant float variable for the value of the pie
f) Prompt the user to enter the value of the radius
g) Store that value in the radius
h) Calculate the diameter of the circle and store it in the appropriate variable
i) Calculate the circumference of the circle and store it in the appropriate variable
j) Calculate the area of the circle and store it in the appropriate variable

Sample Output
Enter the radius: 25
Diameter = 50
Circumference = 157
Area = 1963

3
Lab 4 Programming Fundamental Lab Y8

Task 3:
Follow the instructions given below to write a simple program and compile it.

Declare the variable named “Base”, “Height” and “Area” initialized by any value. Your program should
calculate the Area of the Triangle. Hint:

Formula:
Area of Triangle = (base*height)/2.

Sample Output
Base is 2
Height is 4
The area for the triangle with a base of 2 and a height of 4 is
4.0.

You might also like