In: Electrical Engineering
Directly copy the source code and paste into the Word file. Screenshot of running result must be presented.
1. (20 points) Write the “Hello, world!” program.
2. (30 points) Write a program to calculate the sum from -5 to10. Use the for loop to do the calculation.
3. (20 points) Write a complete C++ program that asks the user to enter the necessary information about the cylinder, calculate the volume in a function (named as calculate_vol, using reference to pass the volume value out), then display the cylinder volume in main function. The volume of cylinder is:
Vol_Cylinder = πr2h
Where π is 3.14159265, r is the radius, and h is the height.
4. (30 points) Declare a vector container. Using keyboard to input several integer numbers, say at least six integer numbers; find the smallest number and display the result.
Answer:-1) The program is-
#include <iostream>
using namespace std;
int main()
{
cout <<"Hello World!";
return 0;
}
OUTPUT:- Hello World!
--------------------------------------------------------------------------------------------
Answer:-2) The code in c++ is-
#include <iostream>
using namespace std;
int main()
{
int sum = 0, i;
for(i = -5; i <= 10; i++) {
sum += i;
}
cout <<"The sum of the integers from -5 to 10 is: " <<
sum;
return 0;
}
OUTPUT:- The sum of the integers from -5 to 10 is: 40
--------------------------------------------------------------------------------------------
Answer:-3) The program is-
#include <iostream>
using namespace std;
#define PIE 3.14159265
void calculate_vol (double, double, double *);
int main()
{
double volume, radius, height;
cout <<"Enter the value of the radius: ";
cin >> radius;
cout <<"Enter the value of the height: ";
cin >> height;
calculate_vol(radius, height, &volume);
cout <<"\nThe volume of the cylinder is: " << volume
<< " cubic unit";
return 0;
}
void calculate_vol (double r, double h, double *vol)
{
*vol = PIE * r * r * h;
}
OUTPUT:- Enter the value of the radius: 1
Enter the value of the height: 2
The volume of the cylinder is: 6.28319 cubic unit