Page 1 of 1

SIMPLY ANSWER THE QUESTION IN C++ VS2019 and make the code copy and paste-able make the code as simple but correct as po

Posted: Fri May 20, 2022 2:37 pm
by answerhappygod
SIMPLY ANSWER THE QUESTION IN C++ VS2019 and make the
code copy and paste-able make the code as simple but correct as
possible
Write a full program to include the necessary preprocessor
directives, the function prototypes, the main function, and the
function calls to the defined functions in questions 3 and 4.
3.
#include<iostream>
using namespace std;
class FractionType
{
private:
int nume;
int deno;
public:
FractionType(int numerator = 0, int denominator
= 1)
{
if (denominator == 0)
{
nume =
0;
deno =
1;

exit(0);
}
else
{
nume =
numerator;
deno =
denominator;
}
}
void Input()
{
cout << "Input
NUMERATOR: ";
cin >> nume;
cout << "Input
DENOMINATOR: ";
cin >> deno;
if (deno == 0)
{
cout
<< "ERROR";

exit(0);
}
}
void Display()
{
cout << nume <<
"/" << deno << endl;
}
FractionType add(FractionType f1,
FractionType f2) {
FractionType temp;
temp.nume = f2.nume * f1.deno
+ f2.deno * f1.nume;
temp.deno = f1.deno *
f2.deno;
return temp;
}
};
int main()
{
FractionType f1;
f1.Input();
cout << "Fraction1: ";
f1.Display();
FractionType f2;
f2.Input();
cout << "Fraction2: ";
f2.Display();
cout << "Sum: " <<
endl;
FractionType obj;
obj = obj.add(f1, f2);
obj.Display();
return 0;
}
4.
#include <iostream>
using namespace std;
// findMinMax method which takes an integer array, integer
reference to the minimum value,
// integer reference to the maximum value, and its size as
parameters
void findMinMax(int arr[], int* min, int* max, int size) {
// assign min to arr at index 0
*min = arr[0];
// assign max to arr at arr at index 0
*max = arr[0];
// for each value from 1 till size
for (int i = 1; i < size; i++) {
// if arr at index i is less then
min
if (arr < *min) {
// assign min with arr at
index i
*min = arr;
}
// if arr at index i is greater then
min
if (arr > *max) {
// assign max with arr at
index i
*max = arr;
}
}
}
int main()
{
// array to find min and max value
int arr[] = { 10, 69, 23, 2, 47, 37, 99, 87, 41
};
// variable min and max
int max, min;
// getting size of arr
int size = sizeof(arr) / sizeof(arr[0]);
// calling findMinMax function
findMinMax(arr, &min, &max, size);
// print max and min
cout << "Maximum Value: " << max <<
endl;
cout << "Minimum Value: " << min <<
endl;
return 0;
}
To properly call the previously listed functions, the main
function must declare integer array of size 8, an input file
stream, and three instances of FractionType (frac1, frac2, and
frac3). Include code to initialize the integer array with values
from a file. Initialize the frac1 and frac2 instances with values
from a file. Remember to print the contents of all array structures
and FractionType instances after initialization to the console. Be
sure to call the above listed functions properly with the
appropriate parameters. If the denominator of any of FractionType
objects are zero, display the message: "Cannot perform operation!"
to the console. Otherwise, display the results of the add function
call to the console. (30pts)  
Attach the code and screenshot of a successful run on the
program.
/*PASTE CODE HERE*/