cs201p assignment no1 solution

608

 

CS201p Assignment Soultion:

download complete solution of cs201p assignment no1 2022, after downloading lease change your subjects, id and name and run code on dev c++.for downloading first attempt cs201p quiz after quiz link will be open if there is issue feel free to contact us

 

Operator Precedence is a very interesting topic in programming. It becomes important when the programmer wants to write code that involves calculations of mathematical equations or complex expressions.  Operator precedence determines the grouping of terms in an expression and decides how an expression is evaluated. In programming, certain operators have higher precedence than others: for example, the multiplication operator has higher precedence than the addition operator. This means when a program encounters an expression involving both the multiplication and addition operator, the multiplication operator will take priority over the addition operator, and it will be calculated first.

 

Now keeping in mind, the Operator Precedence rule, you are required to write a C++ program that will calculate the value of equations given below:

 

 

 

 

To calculate the value of above equations, you need to declare a function, called calculateEquationResult(), that will display the calculated Results of Equations on the screen based on values of “Iteration 1” mentioned in Table 1.

 

Sample Output:

 

 

You also need to declare a function name maxResult (), which will receive the results of three equations as arguments and displays the equation with the maximum Result.

After calculating the Equations Result, the program will prompt the user to select an option whether he/she wants to perform another calculation (Y/N), if the user selects the option “Y”, the program should calculate equations result and find maximum result based on values of “Iteration 2” given in Table 1.

 

 


 

 

 

 



solution   code

#include <iostream>

#include <cmath>

using namespace std;
float eq1,eq2,eq3;
float a = 2 ,b=3, x=10,c = 4, d = 5;

float calEquationRculateesult(float a,float b, float c, float d, float x){

eq1 = x+(b/((3*a)));
cout<< “equation 1 :” << eq1 << “\n”;

eq2 = (((3*a*c)-(b*b)))/((3*a*a));
cout<< “equation 2 :” << eq2 << “\n”;
eq3 =(((2*b*b*b)-(9*(a+b+c))+(27*a*a*d)))/((27+(a*a*a)));
cout<< “equation 3 :” << eq3 << “\n”;

return 0;
}
float maxResult(float s, float y, float z)
{

s=eq1; y= eq2; z= eq3;

if(s >= y && s >=z)
cout << “Equation 1 Result is Maximum: ” << s << “\n\n”;

if(y >= s && y >= z)
cout << “Equation 2 Result is Maximum : ” << y << “\n\n”;

if(z >= s && z >= y)
cout << “Equation 3 Result is Maximum : ” << z << “\n\n”;
return 0;
}



int main()
{

char again ;
calEquationRculateesult(2,3,4,5,10);
maxResult(eq1,eq2,eq3);

cout << “do you want perform any other calculation (y/n): “;
cin >>again;

while(again==’y’){
float a = 6, b = 7 , x = 11 , c = 8, d = 9 ;
calEquationRculateesult(6,7,8,9,11);
maxResult(eq1,eq2,eq3);

cout << “Are you want to to try again (y/n): “;
cin >>again;

}
return 0;
}

 to download file first attempt quiz cs201 QUIZ