Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Use Visual Studio C++ to complete all following) Write a program that prompts t

ID: 3549271 • Letter: #

Question

(Use Visual Studio C++ to complete all following) Write a program that prompts the user input five decimal numbers. The program then should sum the five numbers, average the five numbers, convert the sum and average to the nearest integers and output them. Write a program to write this poem into a file called poem.txt. Then read the file-- poem.txt and output the poem on the screen. Write a program that mimics a calculator. The value of n can be approximated by using the following series write a program to let the user input the n number and your program will give the user the approximate rc value (of course, the bigger the n, the more accurate the pi would be). The distance between two points (xl,yl) and (x2,y2) is If the first point is the center of a circle and the second point is on the circle. Write a program let the user enter center and a point on circle. The program then output the circle's radius, diameter, circumference and area (you should at least have 4 functions, like distance, radius, circumference and area).

Explanation / Answer

// PROGRAM 1
#include<iostream>
using namespace std;
int main()
{
double dec[5];
double sum=0;
double average = 0;
for(int i=0; i<5; i++)
{
cout << "Enter element " << (i+1) << " : ";
cin >> dec[i];
cout << endl;
sum = sum + dec[i];
}
average = sum/5;
cout <<"Sum nearest to ineger is " << static_cast<int> (sum) << endl;
cout <<"average nearest to ineger is " << static_cast<int> (average) << endl;
return 0;
}

// PROGRAM 2
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ofstream outfile("poem.txt");
outfile << " this poem line 1 " << endl;
outfile << " this poem line 2 " << endl;
outfile << " this poem line 3 " << endl;
outfile << " this poem line 4 " << endl;
outfile.close();
ifstream infile("poem.tx");
string str;
while(!infile.eof())
{
getline(infile,str);
cout << str << endl;
}
infile.close();
return 0;
}

// PROGRAM 3
#include<iostream>
using namespace std;
int main()
{
int a,b;
char ch;
cout <<"enter two integers :";
cin >> a >> b;
cout << endl;
cout <<"Enter + for addition " << endl;
cout <<"Enter - for subtraction " << endl;
cout <<"Enter / for division " << endl;
cout <<"Enter * for multiplication " << endl;
cin >> ch;
if(ch=='+')
cout <<"Sum of two numbers is " << (a+b) << endl;
if(ch=='-')
cout <<"Subtraction of two numbers is " << (a-b) << endl;
if(ch=='*')
cout <<"Multiplication of two numbers is " << (a*b) << endl;
if(ch=='/')
cout <<"Division of two numbers is " << (a/b) << endl;
return 0;
}

// PRGORAM 4
#include<iostream>
using namespace std;
int main()
{
int n;
cout <<"Enter number of terms :";
cin >> n;
cout << endl;
double sum = 0;
for(int i=0; i<n; i++)
{
sum = sum + (i%2==0?1:-1)/static_cast<double> (2*i+1);
}
cout <<"PI Approximated by " << 4*sum << endl;
return 0;
}

// PROGRAM 5'
#include<iostream>
#include<cmath>
using namespace std;
double distance(int x1,int y1,int x2,int y2)
{
return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}
double radius(int x1,int y1,int x2,int y2)
{
return distance(x1,y1,x2,y2);
}
double circumference(double r)
{
return 2*3.14159*r;
}
double area(double r)
{
return 3.14159*r*r;
}
int main()
{
int x1,y1;
int x2,y2;
cout <<"Enter Centre (x1,y1) of Circle :";
cin >> x1 >> y1;
cout << endl;
cout <<"Enter Point on Circle :";
cin >> x2 >> y2;
cout << endl;
double rad = radius(x1,y1,x2,y2);
cout <<"Radius of Circle is " << rad << endl;
cout <<"Diameter of Circle is " << 2*rad << endl;
cout <<"Circumference of Circle is " << circumference(rad) << endl;
cout <<"area of Circle is " << area(rad) << endl;
return 0;
}