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

You must not use any global variables. A program with global variables will not

ID: 3674545 • Letter: Y

Question

You must not use any global variables. A program with global variables will not be graded! Only parameters use to pass information back to the caller should be reference parameters. Follow all guidelines from lectures for creating functions that take reference parameters. Your program must use a single function to greet the use, and ask the user to input mass, acceleration, and displacement. Each will be floating-point value and must be passed back to the main function. In addition, perform input validation in this function to ensure that a negative value is not entered for mass. If a negative value is entered, allow the use to enter a new value until they enter the positive value. Your program must be use a single function to calculate force and work using the equations above and pass both results back to main. Your program must be use a single function that outputs the values of force and work with appropriate units. Both outputs should include four digits of precision after the decimal point. Your program should use while loop to repeat the steps above. After each input/calculation/output cycle, ask the user if they have more data to enter. If 'N' or 'n' is entered, the loop should end (anything else the user enters should continue the loop). After the loop ends, display "Thank you for using the program" and return from main ().

Explanation / Answer

#include <bits/stdc++.h>
using namespace std;

// function to take user input
void unserinput(float &mass, float &acceleration, float &displacement){
cout<<"Enter mass [positive value]: ";
cin>>mass;
while(mass < 0){// try till user enter postitive value
   cout<<"Enter mass [positive value]: ";
   cin>>mass;
   }
cout<<"Enter acceleration: ";
cin>>acceleration;
cout<<"Enter displacement: ";
cin>>displacement;
}
// function to calculate force and work
void calculate(float &force, float &work, float mass, float acceleration, float displacement){
   // calculating force
   force = mass/acceleration;
   //calculating work
   work = force/displacement;
   }
  
//displace function
void output(float force, float work){
   cout<<"Force : "<<fixed<<setprecision(4)<<force<<"N"<<endl;
   cout<<"Work : "<<fixed<<setprecision(4)<<work<<"J"<<endl;
   }
int main() {
  
   float mass, acceleration, display, force, work;
   char c='y';
   while(true){
       unserinput(mass, acceleration, display);
       calculate(force, work, mass, acceleration, display);
       output(force, work);
      
       cout<<"Do you want enter more data: (N/n to exit): ";
       cin>>c;
       if(c=='N' || c=='n')
           break;
       }
   cout<<"Thank you for using program"<<endl;
  
return 0;

}

/*

Output:

Enter mass [positive value]: 54
Enter acceleration: 34
Enter displacement: 12
Force : 1.5882N
Work : 0.1324J
Do you want enter more data: (N/n to exit): 43
Enter mass [positive value]: Enter acceleration: 12
Enter displacement: 56
Force : 0.2500N
Work : 0.0045J
Do you want enter more data: (N/n to exit): n
Thank you for using program

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote