Consider the following equations. 𝐴 = 2𝑥 𝐵 = 2 cos 𝑥 , 𝑤ℎ𝑒𝑟𝑒 𝑥 𝑖𝑠 10° , 20° , 30° … 180° 𝐶 = ∑ 𝑛 + 5 5 100 𝑛=0 Construct a C++ program to calculate and print out the value of A, B and C by considering the following conditions; 1- User must keyed-in “start” and “stop” to control the program. 2- Use function to display all the above equations. 3- If user keyed-in “function1”, calculate the value of A divided by C for the value of x from 1 to 100. 4- If user keyed-in “function1”, calculate the value of B divided by A for the value of x from 2 to 200.
#include <cmath>
#include<dos.h>
#include <bits/stdc++.h>
using namespace std;
/*
Consider the following equations. A = 2x,
B = 2 Cos x, Cx = 10, 20, 30 , --- 180
C = Sum (n), n = = ?? = 2?? ?? = 2 cos ?? , ??h?????? ?? ???? 10° , 20° , 30° … 180° ?? = ? ?? + 5 5 100 ??=0
Construct a C++ program to calculate and print out the value of A, B and C by considering the following conditions;
1- User must keyed-in “start” and “stop” to control the program.
2- Use function to display all the above equations.
3- If user keyed-in “function1”, calculate the value of A divided by C for the value of x from 1 to 100.
4- If user keyed-in “function1”, calculate the value of B divided by A for the value of x from 2 to 200.
*/
void Display(void)
{
cout<<"\n\tFunction-1:\tA = 2x";
cout<<"\n\tFunction-2:\tB = 2 Cos (x)";
cout<<"\n\tFunction-3:\tC = Sum (n) + 55";
}
float Func_A(void)
{
float u=0;
for(float x=0;x<=180;x=x+10) u = u + 2*x;
return(u);
}
float Func_B(void)
{
float u=0;
for(float x=0;x<=180;x=x+10) u = u + 2*cos(x);
return(u);
}
float Func_C(float Start, float End)
{
float c=0;
for(float n=Start;n<=End;n++) c= c+n;
return(c);
}
int main()
{
int Flag=-1;
float x,A, B, C;
float Start=0,End=0,val;
while(Flag<0 || Flag>4)
{
cout<<"\n\tPress-1 to ebnter Start and End values:";
cout<<"\n\tPress-2 to Display the Equations";
cout<<"\n\tPress-3 to “function1”, calculate the value of A divided by C for the value of x from 1 to 100";
cout<<"\n\tPress-4 to “function1”, calculate the value of B divided by C for the value of x from 2 to 200";
cout<<"\n\tPress-0 to QUIT";
while(Flag<0 || Flag>4)
{
cout<<"\n\tEnter Option (0 to 4): "; cin>>Flag;
}
if(Flag==1)
{
cout<<"\n\tEnter Start: "; cin>>Start;
while(End <= Start)
{
cout<<"\n\tEnter End (> Start) : "; cin>>End;
}
}
if(Flag==2) Display();
if(Flag==3)
{
val = Func_A()/Func_C(Start,End);
cout<<"\n\n\tValue: A/C = "<<val;
}
if(Flag==4)
{
val = Func_B()/Func_C(Start,End);
cout<<"\n\n\tValue: B/C = "<<val;
}
Flag=-1;
}
}
Comments