In: Computer Science
Answer the questions below as indicated.
Note that you have to complete these using Visual Studio 2019.
Upload the source code (.cpp) of your applications. Upload a separate (.cpp) file for each question.
1-Create a C++ program which adds two numbers and displays the sum.
2-Create a C++ program which calculates and displays the area of a rectangle.
3-Create a C++ program which calculates and displays the average of four numbers..
4-Complete questions 3 of the chapter 3 Programming Exercises in pages 182 of the Textbook.
Upload your source codes to this link.
I don't have Visual Studio 2019 the program is the same only compile and running is different.
1- C++ program which adds two numbers and displays the sum
#include <iostream>
using namespace std;
//Declarating Num1/Num2 is an Integer
int addition(int Num1,int Num2);
int main()
{
int Num1,Num2;
int add;
cout<<"Enter first number: ";
cin>>Num1;
cout<<"Enter second number: ";
cin>>Num2;
add=addition(Num1,Num2);
cout<<"Sum of two number is: "<<add<<endl;
return 0;
}
int addition(int Num1,int Num2)
{
return (Num1+Num2);
}
Output:-
2- C++ program which calculates and displays the area of a rectangle.
#include <iostream>
using namespace std;
int main()
{
int width, length, area;
cout << "\n Find the Area of a Rectangle \n";
cout<<" Length of the rectangle : ";
cin>>length;
cout<<" Width of the rectangle : ";
cin>>width;
area=(length*width);
cout<<" The area of the rectangle is : "<< area << endl;
cout << endl;
return 0;
}
Output:-
3- C++ program which calculates and displays the average of four numbers
#include<iostream>
using namespace std;
int main()
{
double num1, num2, num3, num4;
double sum, average;
cout << "Enter Four Numbers :: ";
cin >> num1 >> num2 >> num3>>num4;
sum = num1 + num2 + num3 + num4;
average = sum / 4;
cout << "Sum = " << sum << endl;
cout << "Average = " << average << endl;
return 0;
}
there is no page 182.