Uploaded by asadh8464

Assignment Fop 2

advertisement
DEPARTMENT OF ELECTRICAL ENGINEERING
COLLEGE OF E&ME, NUST, RAWALPINDI
Subject Name:
Fundamental of Programming
Lab Number
Cs-114
SUBMITTED TO:
Instructor Name: Prof. Dr Wasi Hadir Butt
SUBMITTED BY:
Student Name: Asad Hussain
Reg #463990
DE- 45 Dept EE (Syndicate C)
Submission Date:
10/4/2023
Objectives:
To Understand and learn arithmetic operations such as
addition, subtraction, multiplication, division and more
operations within C++ language.
Related Topic/Chapter in theory class:
None
Hardware/Software required:
Hardware: PC/Laptop
Software Tool: Visual Studio, C++
Tasks:
1. Question statement
Solution:
#include<iostream>
using namespace std;
int main() {
int i = 5, j = 7,k= 6, n = 3;
cout << i + j * k - k % n << endl;
cout << i / n << endl;
system("PAUSE");
return 0;
}
Output:
2. Question statement:
Declare two integers, one float variable and
assign 10, 15, and 12.6 to them respectively and
display.
Solution:
#include <iostream>
using namespace std;
void main() {
int a = 10;
int b = 15;
float c = 12.6;
cout << a << endl;
cout << b << endl;
cout << c <<endl;
Output:
3. Question Statement:
#include <iostream>
Using namespace std;
void main() {
int a, b = 2;
float c = 4.2;
a = b * c;
cout << a ;
}
Output:
4.Question Statement:
Write a program which prints cube of an integer. Save the
result in a variable and display.
#include <iostream>
using namespace std;
void main() {
int a, b = 3;
a = b * b * b;
cout << a;
}
Output:
5.Question Statement:
Write a program that calculates and displays the sum of three
floating-point numbers.
Solution:
#include <iostream>
using namespace std;
void main() {
float a, b = 3.2;
float c = 4.7;
float d = 8.9;
a = b + c + d;
cout << a;
}
Output:
6. Question Statement:
Create a program that calculates and displays the average of five
predefined test scores. Use appropriate data types and ensure the average
is displayed with two decimal places.
Solution:
#include <iostream>
using namespace std;
void main() {
double avg;
double a, q = 91.65;
double e = 76.43;
double w = 56.98;
double t = 47.76;
double k = 65.45;
a = q + e + w + t + k;
avg = a / 5;
cout << " The Average of these 5 numbers is
"; cout << avg;
}
Output:
Conclusion:
We gained practical knowledge of C++ syntax and
programming concepts. Execute numerical variables,
Arithmetic Operations, and Data types
Download