Assignment 1
Assignment 1
Course Title:
Programming fundamentals theory
Submitted to: Sir Junaid Abdullah Mansoor
Submitted by: Misbah Aiman
ID: F20232661169
Section: V24
Course code: CC1021
Program name: BS (CS)
Code:
#include <iostream>
#include <cmath>
int main()
/*Write a program that encourages the user to enter two fractions, and then displays their sum
in fractional form.*/
char op='/';
cout << "Enter the first fraction in the form of a/b: " ;
cout << "Enter the second fraction in the form of a/b: " ;
cout << "The sum of the fractions is: " << answer_numerator << "/" << answer_denumerator << endl;
return 0;
Output:
Enter the first fraction in the form of a/b: 6/7
Question no. 2: If cost price and selling price of an item is input through the keyboard, write
a program to determine whether the seller has made profit or incurred loss. Also determine
how much profit he made or loss he incurred.
Code:
#include <iostream>
#include <cmath>
int main()
/*If cost price and selling price of an item is input through the keyboard, write a program to
determine whether the seller has made profit or incurred loss. Also determine how much profit he made
or loss he incurred.*/
if (sellingPrice>costPrice)
profit = sellingPrice-costPrice;
cout << "The profit made by the seller is $" << profit << endl;
else if (costPrice>sellingPrice)
loss = costPrice-sellingPrice;
cout << "The loss incurred by the seller is $" << loss << endl;
else
cout << "The seller has neither made a profit nor incurred a loss." << endl;
}
return 0;
Output:
Question no. 3: Any integer is input through the keyboard. Write a program to find out
whether it is an odd number or even number.
Code:
#include <iostream>
int main()
/*Any integer is input through the keyboard. Write a program to find out whether it is an odd
number or even
number.*/
int number;
if (number%2==0)
else if (number%2!=0)
else
{
return 0;
Output:
enter the number: 670
Question no. 4:
Code:
#include <iostream>
#include <cmath>
int main()
//program 4
average= (num1+num2+num3)/3;
cout << "average of given values is: " << average <<endl;
return 0;
Output:
average of given values is: 42
Question no. 5:
code:
#include <iostream>
#include <cmath>
int main()
//program 5
float a, b, c, d, e ;
cin >> a;
cin >> b;
cin >> c;
cin >> d;
cin >> e;
cout << "nearest integer for first decimal is: " << (int)a <<endl;
cout << "nearest integer for second decimal is: " << (int)b <<endl;
cout << "nearest integer for third decimal is: " << (int)c <<endl;
cout << "nearest integer for fourth decimal is: " << (int)d <<endl;
cout << "nearest integer for fifth decimal is: " << (int)e <<endl;
average = (a+b+c+d+e)/5;
cout << "sum of all converted integers is: " << sum <<endl;
cout << "average of all converted inetegers is: " << average <<endl;
return 0;
Output:
Enter first decimal: 6.7
6.7
4.6
9.1
5.7
9.3