Write a C++ program to compute the value of x * (x + 1) + y * y + z * (z - 1) where x, y, and z are 3 floating point numbers entered by the user. Requirements: • You should have a function get3numbers() that asks the user to enter 3 numbers. • You should have a function computeExp() that computes the value of the expression. • Your main function should call the above 2 functions and get the job done. • You must determine the parameters and returning values of all those functions.
#include<iostream> using namespace std; void get3numbers(float& x, float& y, float& z){ cout<<"Enter value for x: "; cin>>x; cout<<"Enter value for y: "; cin>>y; cout<<"Enter value for z: "; cin>>z; } float computeExp(float x, float y, float z){ return x * (x + 1) + y * y + z * (z - 1); } int main(){ float x, y, z, res; get3numbers(x,y,z); res = computeExp(x,y,z); cout<<"Result = "<<res<<endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.