Using c++ create a library with following functions (prototypes are given along
ID: 3593424 • Letter: U
Question
Using c++ create a library with following functions (prototypes are given along with a description):
- void increasing (double& A, double& B, double& C); //Arranges A, B, and C in increasing order.
- void decreasing (double& A, double& B, double& C); //Arranges A, B, and C in decreasing order.
- void mmm (double& A, double& B, double& C); //Replaces A with the minimum of A, B, and C; replaces B with the average of A, B, and C; replaces C with the maximum of A, B, and C.
Use the library in a program where the user is asked to enter three numbers. The program calls all three functions above and outputs the new values of A, B, and C for each case. Do not just output numbers. Display a message with each result.
Explanation / Answer
HI,
I have added 3 sections
1.Main file containing the main programme(main.cpp)
2.Header file for function declration.(calculate.h)
3.Source file containing the definition of the functions(calculate.cpp)
===============================================================
//main.cpp
#include <iostream>
#include "calculate.h"
using namespace std;
int main()
{
double a,b,c;
cout << "Enter the value of a b and c ";
cin >> a;
cin >> b;
cin >> c;
increasing(a,b,c);
decreasing(a,b,c);
mmm(a,b,c);
return 0;
}
=============================================================================
//save as calculate.cpp
//Src file (calculate.cpp)
#include <iostream>
#include "calculate.h"
using namespace std;
void increasing(double &a, double &b, double &c){
if((a>=b)&&(a>=c)){
if(b>=c){
cout<<" "<<"Ascending order :" <<c<<","<<b<<","<<a;
}
else{
cout<<" "<<"Ascending order :" <<b<<","<<c<<","<<a;
}
}
else if((b>=a)&&(b>=c)){
if(a>=c){
cout<<" "<<"Ascending order :" <<c<<","<<a<<","<<b;
}
else{
cout<<" "<<"Ascending order :" <<a<<","<<c<<","<<b;
}
}
else if((c>=a)&&(c>=b)){
if(a>=b){
cout<<" "<<"Ascending order :" <<b<<","<<a<<","<<c;
}
else{
cout<<" "<<"Ascending order :" <<a<<","<<b<<","<<c;
}
}
}
void decreasing(double &a, double &b, double &c){
if((a>=b)&&(a>=c)){
if(b>=c){
cout<<" "<<"Discending order :" <<a<<","<<b<<","<<c;
}
else{
cout<<" "<<"Discending order :" <<a<<","<<c<<","<<b;
}
}
else if((b>=a)&&(b>=c)){
if(a>=c){
cout<<" "<<"Discending order :" <<b<<","<<a<<","<<c;
}
else{
cout<<" "<<"Discending order :" <<b<<","<<c<<","<<a;
}
}
else if((c>=a)&&(c>=b)){
if(a>=b){
cout<<" "<<"Discending order :" <<c<<","<<a<<","<<b;
}
else{
cout<<" "<<"Discending order :" <<c<<","<<b<<","<<a;
}
}
}
void mmm(double &a, double &b, double &c){
double smallest,largest,avg;
int check=1;
avg=(a+b+c)/3;
if( b<=a && b<=c ){
smallest=b;
check=0;
}
if( c<=a && c<=b && check){
smallest=c;
}
check=1;
if( a>=b && a>=c ){
largest=a;
check=0;
}
if( b>=a && b>=c && check){
largest=b;
}
a=smallest;
b=avg;
c=largest;
cout<<"Thank you a is replaced by min(a,b,c)="<<a<<" ";
cout<<"Thank you b is replaced by avg(a,b,c)="<<b<<" ";
cout<<"Thank you c is replaced by max(a,b,c)="<<c<<" ";
}
============================================================================
//save as calculate.h
//Header file(calculate.h)
void increasing(double &a, double &b, double &c);
void decreasing(double &a, double &b, double &c);
void mmm(double &a, double &b, double &c);
#endif
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.