Lab Report 2 (Muhammad Abdullah Zafar Ghauri ME-14 (C) CMS 405642
Lab Report 2 (Muhammad Abdullah Zafar Ghauri ME-14 (C) CMS 405642
Lab Report 02
1st SEMESTER
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):
int Integer 2 or 4
float Floating-point 4
char Character 1
bool Boolean 1
void Empty 0
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.
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;
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;