PF Y8 Lab 4
PF Y8 Lab 4
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.
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.