0% found this document useful (0 votes)
48 views29 pages

Muhammad Hassan Irshad Roll 26

The document contains C++ programs written by Muhammad Hassan Irshad to demonstrate various programming concepts like data types, arithmetic operations, pattern printing, user input, limits of data types, and calculating volume of a cube. The programs are submitted to Sir Usman Ahmed as part of an assignment on programming fundamentals. The document contains the C++ code and output for each program.

Uploaded by

hassan Irshad
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)
48 views29 pages

Muhammad Hassan Irshad Roll 26

The document contains C++ programs written by Muhammad Hassan Irshad to demonstrate various programming concepts like data types, arithmetic operations, pattern printing, user input, limits of data types, and calculating volume of a cube. The programs are submitted to Sir Usman Ahmed as part of an assignment on programming fundamentals. The document contains the C++ code and output for each program.

Uploaded by

hassan Irshad
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/ 29

NFC Institute Of Engineering &

Fertilizer Research, Faisalabad.

Name: - Muhammad Hassan Irshad


Roll No: - 26

Department: - Computer Science


Subject: - Programming Fundamentals

Assignment: - No#3
Date: - 14/Nov/2022

Submitted To: - Sir Usman Ahmed


Programming Fundamentals
Write a C++ program to print Sunday, Monday and Tuesday on separate lines on the screen.
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
cout<<"Sunday\n";
cout<<"Monday"<<endl<<endl;
cout<<"Tuesday";
return 0;
}

Output:

Write a C++ program to print integer data type values on the screen.
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int a=5, b=26;
cout<<"a="<<a<<" b="<<b<<"\n\n"; cout<<"a="<<a<<"\n"<<"b="<<b;
return 0;
}

Output:

Write a C++ program to print float data type values on the screen.
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
float a=5.23, b=26.14;
cout<<"a="<<a<<" b="<<b;
return 0;
}
Output:

Write a C++ program to print double data type values on the screen
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
double a=18.413, b=57.273;
cout<<"a="<<a<<" b="<<b;
return 0;
}
Output:

Write a C++ program to print a char data type value on the screen.
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
char a='#';
cout<<a;
return 0;
}

Output:
Write a C++ Program to Perform Addition Subtraction Multiplication Division
#include<iostream>
using namespace std;
int main()
{
int num1, num2, res;
cout<<"Enter Two Numbers: ";
cin>>num1>>num2;
res = num1+num2;
cout<<endl<<"Addition Result = "<<res<<endl;
res = num1-num2;
cout<<endl<<"Subtraction Result = "<<res<<endl;
res = num1*num2;
cout<<endl<<"Multiplication Result = "<<res<<endl;
res = num1/num2;
cout<<endl<<"Division Result = "<<res<<endl;
return 0;
}
Output:

Write a C++ Program to Swap Two Numbers


#include <iostream>
using namespace std;

int main()
{
int a = 5, b = 10, temp;

cout << "Before swapping." << endl;


cout << "a = " << a << ", b = " << b << endl;

temp = a;
a = b;
b = temp;

cout << "\nAfter swapping." << endl;


cout << "a = " << a << ", b = " << b << endl;

return 0;
}

Output:
Write a C++ Program to Swap Numbers Without Using Temporary Variables
#include <iostream>
using namespace std;

int main()
{

int a = 5, b = 10;

cout << "Before swapping." << endl;


cout << "a = " << a << ", b = " << b << endl;

a = a + b;
b = a - b;
a = a - b;

cout << "\nAfter swapping." << endl;


cout << "a = " << a << ", b = " << b << endl;

return 0;
}
Output:

Write a C++ Program to Print Number Entered by User


#include <iostream>
using namespace std;

int main() {
int number;

cout << "Enter an integer: ";


cin >> number;

cout << "You entered " << number;


return 0;
}
Output:
Write a C++ Program to Find Size of int, float, double and char in Your System
#include <iostream>
using namespace std;

int main()
{
cout << "Size of char: " << sizeof(char) << " byte" << endl;
cout << "Size of int: " << sizeof(int) << " bytes" << endl;
cout << "Size of float: " << sizeof(float) << " bytes" << endl;
cout << "Size of double: " << sizeof(double) << " bytes" << endl;

return 0;
}

Output:
Write a program in C++ to print the following pattern.

#include <iostream>
using namespace std;

int main()
{
cout << "\n\n Print the following pattern:\n";
cout << "--------------------------------\n";
cout << " xxxxx\n";
cout << "x x x x\n";
cout << "x x x\n";
cout << "x xxxxxxx xxxxxxx\n";
cout << "x x x\n";
cout << "x x x x\n";
cout << " xxxxx\n";
}
Output:
Write a program in C++ to print the result of the specified operations.
#include <iostream>
using namespace std;

int main()
{
cout << "\n\n Print the result of some specific operation :\n";
cout << "--------------------------------------------------\n";
cout << " Result of 1st expression is : "<< (-1+4*6) <<"\n" ; //-1 + 24 = 23
cout << " Result of 2nd expression is : "<< ((35+5)%7) <<"\n" ; //40 % 7 = 5 (remainder of 40/7)
cout << " Result of 3rd expression is : "<< (14+-4*6/11) <<"\n" ; //14 - (24/11)= 14 - 2 = 12
cout << " Result of 4th expression is : "<< (2+15/6*1-7%2) <<"\n\n" ; //2 + (15/6) - remainder of (7/2) = 2 + 2 - 1 = 4 - 1
=3

Output:

Write a program in C++ to add two numbers accept through keyboard.


#include <iostream>
using namespace std;

int main()
{
int num1, num2, sum;
cout << "\n Sum of two numbers :\n";
cout << "-------------------------\n";
cout << " Input 1st number : ";
cin >> num1 ;
cout << " Input 2nd number : ";
cin >> num2;
sum = num1 + num2;
cout <<" The sum of the numbers is : " << sum << endl;
cout << endl;
return 0;
}

Output:
Write a program in C++ to display various type or arithmetic operation using mixed data type.

#include <iostream>
#include <iomanip> // formatting floating-point numbers with 1 decimal place
using namespace std;

int main()
{
int m1 = 5, m2 = 7;
double d1 = 3.7, d2 = 8.0;

cout << "\n\n Display arithmetic operations with mixed data type :\n";
cout << "---------------------------------------------------------\n";
cout << fixed << setprecision(1);

cout <<" "<< m1 << " + " << m2 << " = " << m1+m2 << endl;
cout <<" "<< d1 << " + " << d2 << " = " << d1+d2 << endl;
cout <<" "<< m1 << " + " << d2 << " = " << m1+d2 << endl;

cout <<" "<< m1 << " - " << m2 << " = " << m1-m2 << endl;
cout <<" "<< d1 << " - " << d2 << " = " << d1-d2 << endl;
cout <<" "<< m1 << " - " << d2 << " = " << m1-d2 << endl;

cout <<" "<< m1 << " * " << m2 << " = " << m1*m2 << endl;
cout <<" "<< d1 << " * " << d2 << " = " << d1*d2 << endl;
cout <<" "<< m1 << " * " << d2 << " = " << m1*d2 << endl;

cout <<" "<< m1 << " / " << m2 << " = " << m1/m2 << endl;
cout <<" "<< d1 << " / " << d2 << " = " << d1/d2 << endl;
cout <<" "<< m1 << " / " << d2 << " = " << m1/d2 << endl;
cout << endl;
return 0;
}
Output:

Write a program in C++ to check whether the primitive values crossing the limits or not.
#include <iostream>
using namespace std;

int main()
{
cout << "\n\n Check whether the primitive values crossing the limits or not :\n";
cout << "--------------------------------------------------------------------\n";
char gender = 'M'; // char is single-quoted
bool isEmployed = true; // true(non-zero) or false(0)
unsigned short numOfsons = 2; // [0, 255]
short yearOfAppt = 2020; // [-32767, 32768]
unsigned int YearlyPackage = 2000000; // [0, 4294967295]
double height = 79.48; // With fractional part
float gpa = 4.69f; // Need suffix 'f' for float
long totalDrawan = 12047235L; // Suffix 'L' for long
long long balance = 995324987LL; // Need suffix 'LL' for long long int

cout << " The Gender is : " << gender << endl;
cout << " Is he Employed? : " << isEmployed << endl;
cout << " Number of sons he has : " << numOfsons << endl;
cout << " Year of his Appointment : " << yearOfAppt << endl;
cout << " Salary for a year : " << YearlyPackage << endl;
cout << " Height is : " << height << endl;
cout << " GPA is " << gpa << endl;
cout << " Salary drawn upto : " << totalDrawan << endl;
cout << " Balance till : " << balance << endl;
return 0;
}

Output:

Write a program in C++ to check the upper and lower limits of integer.
#include <iostream>
#include <climits> // integer limits in header file
using namespace std;

int main()
{
cout << "\n\n Check the upper and lower limits of integer :\n";
cout << "--------------------------------------------------\n";
cout << " The maximum limit of int data type : " << INT_MAX << endl;
cout << " The minimum limit of int data type : " << INT_MIN << endl;
cout << " The maximum limit of unsigned int data type : " << UINT_MAX << endl;
cout << " The maximum limit of long long data type : " << LLONG_MAX << endl;
cout << " The minimum limit of long long data type : " << LLONG_MIN << endl;
cout << " The maximum limit of unsigned long long data type : " << ULLONG_MAX << endl;
cout << " The Bits contain in char data type : " << CHAR_BIT << endl;
cout << " The maximum limit of char data type : " << CHAR_MAX << endl;
cout << " The minimum limit of char data type : " << CHAR_MIN << endl;
cout << " The maximum limit of signed char data type : " << SCHAR_MAX << endl;
cout << " The minimum limit of signed char data type : " << SCHAR_MIN << endl;
cout << " The maximum limit of unsigned char data type : " << UCHAR_MAX << endl;
cout << " The minimum limit of short data type : " << SHRT_MIN << endl;
cout << " The maximum limit of short data type : " << SHRT_MAX << endl;
cout << " The maximum limit of unsigned short data type : " << USHRT_MAX << endl;
cout << endl;
return 0;
}
Output:

Write a program in C++ to calculate the volume of a cube.


#include <iostream>
using namespace std;

int main()
{
int sid1;
float volcu;
cout << "\n\n Calculate the volume of a cube :\n";
cout << "---------------------------------------\n";
cout<<" Input the side of a cube : ";
cin>>sid1;
volcu=(sid1*sid1*sid1);
cout<<" The volume of a cube is : "<< volcu << endl;
cout << endl;
return 0;
}

Output:
Write a program in C++ to find the Area and Perimeter of a Rectangle.

#include <iostream>
using namespace std;

int main()
{
int width, lngth, area, peri;
cout << "\n\n Find the Area and Perimeter of a Rectangle :\n";
cout << "-------------------------------------------------\n";
cout<<" Input the length of the rectangle : ";
cin>>lngth;
cout<<" Input the width of the rectangle : ";
cin>>width;
area=(lngth*width);
peri=2*(lngth+width);
cout<<" The area of the rectangle is : "<< area << endl;
cout<<" The perimeter of the rectangle is : "<< peri << endl;
cout << endl;
return 0;
}

Output:
Write a program in C++ to find the area and circumference of a circle.

#include <iostream>
#define PI 3.14159
using namespace std;

int main()
{
float radius, area, circum;
cout << "\n\n Find the area and circumference of any circle :\n";
cout << "----------------------------------------------------\n";
cout<<" Input the radius(1/2 of diameter) of a circle : ";
cin>>radius;
circum = 2*PI*radius;
area = PI*(radius*radius);
cout<<" The area of the circle is : "<< area << endl;
cout<<" The circumference of the circle is : "<< circum << endl;

cout << endl;


return 0;
}
Output:
Write a program in C++ to convert temperature in Fahrenheit to Celsius.
#include <iostream>
using namespace std;

int main()
{
float frh, cel;
cout << "\n\n Convert temperature in Fahrenheit to Celsius :\n";
cout << "---------------------------------------------------\n";
cout << " Input the temperature in Fahrenheit : ";
cin >> frh;
cel = ((frh * 5.0)-(5.0 * 32))/9;
cout << " The temperature in Fahrenheit : " << frh << endl;
cout << " The temperature in Celsius : " << cel << endl;
cout << endl;
return 0;
}
Output:

Write a program in C++ to convert temperature in Celsius to Fahrenheit.


#include <iostream>
using namespace std;

int main()
{
float frh, cel;
cout << "\n\n Convert temperature in Celsius to Fahrenheit :\n";
cout << "---------------------------------------------------\n";
cout << " Input the temperature in Celsius : ";
cin >> cel;
frh = (cel * 9.0) / 5.0 + 32;
cout << " The temperature in Celsius : " << cel << endl;
cout << " The temperature in Fahrenheit : " << frh << endl;
cout << endl;
return 0;
}

Output:
Write a program in C++ that converts kilometers per hour to miles per hour.

#include <iostream>
using namespace std;

int main()
{
float kmph, miph;
cout << "\n\n Convert kilometers per hour to miles per hour :\n";
cout << "----------------------------------------------------\n";
cout << " Input the distance in kilometer : ";
cin >> kmph;
miph = (kmph * 0.6213712);
cout << " The "<< kmph <<" Km./hr. means "<< miph << " Miles/hr." << endl;
cout << endl;
return 0;
}
Output:

You might also like