0% found this document useful (0 votes)
40 views7 pages

Lab Report 2 (Muhammad Abdullah Zafar Ghauri ME-14 (C) CMS 405642

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)
40 views7 pages

Lab Report 2 (Muhammad Abdullah Zafar Ghauri ME-14 (C) CMS 405642

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/ 7

Fundamentals of Programming Lab

Lab Report 02

1st SEMESTER

Submitted to: Engr. Ali Hassan


Session: Section: A Group: 2
SUBMITTED BY
Sr. Lab
No. Names CMSID Report Lab work Lab Tasks Total
(Theory)
1 Muhammad Abdullah 405642
Zafar Ghauri

School of Mechanical and Manufacturing Engineering


Objectives:

• Learn about Different Data Types in C++


• Understand the scenarios when to use a particular data type
• Understand “Boolean “ Data Type
• Get used to String Function
• Introduction to concept of user-defined function

Theory:

1. Data Types:
A particular type of data item, as defined by the values it takes, the
programming language used , or the operations that can be performed on it.

The table below shows the fundamental data types, their meaning, and their sizes (in bytes):

Data Type Meaning Size (in Bytes)

int Integer 2 or 4

float Floating-point 4

double Double Floating-point 8

char Character 1

wchar_t Wide Character 2

bool Boolean 1

void Empty 0

2. Understanding the scenario of using very Data Type:


• Integer Data Type: Used when whole numbers are used

• Float Data Type: Used when decimal numbers are used.


• Character Data Type: Used for Alphabets
3. “Boolean Data Type:

The Boolean Data Type has one of the two possible values(
Usually denoted True or False) , intended to represent the two truth values of the logic
and Boolean Algebra.

A boolean data type is declared with the” bool” keyword and can only take the
values true or false.

When the value is returned, true = 1 and false = 0.

4. String () Function:
In C languages(C or C++), string is a class that is used to represent
a group of characters. It is used when the assigned name exceeds a capacity. It is
similar to character data type with the exception of length.
5. User-Defined Functions:
C++ allows the programmer to create his very own
functions. A user-defined function groups code to perform a specific task and that
group of code is given a name (identifier). When the function is invoked from any
part of program, it all executes the codes defined in the body of function.

Home Task:
Q. Write a user-defined function that takes in two numbers from the user and
calculates the sum, difference, product and modulus (division) .

Program: #include<iostream>
using namespace std;

void calculator()
{
a:
int x, y;
int sum, difference, product, modulus;

cout << "\n Enter the first number=" << endl;


cin >> x;

cout << "\n Enter the Second Number=" << endl;


cin >> y;

sum = x + y;
difference = x - y;
product = x * y;
modulus = x / y;

cout << "\n The Sum of Two Numbers is=" << sum << endl;
cout << "\n The Difference of Two Numbers is=" << difference << endl;
cout << "\n The Product of Two Numbers is= " << product << endl;
cout << "\n The Modulus of Two Numbers is=" << modulus << endl;
goto a;
}
void main()
{
calculator();
}

[ I have used the goto() function to understand more in depth about the very
function.]

Output:

Lab Task
Q. Write a Program in C++ that takes in First and Second Name from user and prints
the message on screen about administering COVID Vaccines.
Input:

#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
string firstName, secondName;
cout << "\n Please enter Your First Name= ";
cin >> firstName;
cout << "\n Please enter your Second Name= ";
cin >> secondName;

cout << "\n\rYour complete name = " << firstName << " " << secondName;
cout << "\nPlease admister COVID Vaccines, namely Pfizer BioNTech!" << endl;
cin >> firstName; //for holding the screen for delayed output
return 0;
}

Output:

Q. Write a C++ program that takes in an input character from user and prints the
ASCII code.
Input:

#include<iostream>
using namespace std;

int main()
{
x:
cout << "\n Please Enter a Character=" << endl;

char character;
cin >> character;

cout << "\nThe ASCII code for " << character << " is : " << int(character);
goto x;
return 0;

}
Output:

Q. Write a program utilizing Boolean function taking an input from user and
printing a credential on the screen
Input:

#include<iostream>
using namespace std;

int main()
{
d:
bool xy;
xy = false;

int age;
cout << "\nPlease Enter Your Age=";
cin >> age;

xy = age > 18;


cout << "\nYou haveSucceeded!" << xy;
goto d;
return 0;
}
Output:

You might also like