Question

In: Computer Science

C++ , please answer both 1) Code a function object class which can scale data toward...

C++ , please answer both

1) Code a function object class which can scale data toward a desired maximum given the actual maximum and the desired maximum. (Reminder: to scale a value v use v*desired/actual.)

then after this

2) Show how to use your function object class from above to fix the following test scores. (What kind of loop would be most appropriate?) (Hint: What is the desired maximum of a typical test?)

double scores[MAX] = { 42, 55.5, 82, 74.5, 62 };

Solutions

Expert Solution

In the given question the desired maximum value and the actual maximum value are not given therefore I am taking these value as inputs and assume their values as desired maximum = 100 and actual maximum = 90 respectively.

Both the part of the question are combined together and solve in a single program.

In the scores array the variable MAX is not defined therefore I am assuming it as the numbers of test scores which will be provided by the user, in such case all the loops will be appropriate to execute it but I for simplicity I am using for loop.

The C++ code of the given question is as follows:-

#include <iostream>
using namespace std;
class Scale
{
public:
double desired=100;
double actual=90;
Scale(double d,double a)
{
desired=d;
actual=a;
}
double ScaleUp(double i)
{
i=i*desired/actual;
return i;
}
};
int main()
{
int MAX,i;
double desired,actual;
cout<<"Enter desired maximum value"<<endl;
cin>>desired;
cout<<"Enter actual maximum value"<<endl;
cin>>actual;
cout<<"Enter maximum number of test scores to be scaled"<<endl;
cin>>MAX;
double scores[MAX]={42,55.5,82,74.5,62};
float result;
Scale obj(desired,actual);
for(i=0;i<MAX;i++)
{
result=obj.ScaleUp(scores[i]);
cout<<"After scaling "<<scores[i]<<" the new value is "<<result<<endl;
}
return 0;
}

The output of the above code is as follows:-

Enter desired maximum value
100
Enter actual maximum value
90
Enter maximum number of test scores to be scaled
5
After scaling 42 the new value is 46.6667
After scaling 55.5 the new value is 61.6667
After scaling 82 the new value is 91.1111
After scaling 74.5 the new value is 82.7778
After scaling 62 the new value is 68.8889

The screenshot of the above code is as follows:-

If you have further any doubts then feel free to ask me in the comment section.


Related Solutions

Can you please check for the error in my code?: #data object is created text_data =...
Can you please check for the error in my code?: #data object is created text_data = {"the_final_output": [{"abs": ""}, {"abs": ""}, ..., {"abs": ""}]} #a list is created main_terms = [] #iterating every data in the_final_output for i in range(len(text_data["the_final_output"]): blob = TextBlob(text_data["the_final_output"][i]["abs"]) main_terms.append(blob.polarity)    #sentiment analysis sorts the text into positive, neutral, and negative. tp = sum(main_terms) #if tp is less than 0, it's negative if tp < 0: print("Negative") #if tp is greater than 0, it's positive elif...
Write code in C please. #1 Write a function multiples() which will take an integer input...
Write code in C please. #1 Write a function multiples() which will take an integer input and it will print out all the multiples of this number starting from 2 but not including itself. For example, multiples(10) will print 2, 5 and multiples(100) will print 2, 4, 5, 10, 20, 25, 50 #2 Write and test a Fibonacci() function that uses a loop instead of recursion to calculate Fibonacci numbers.
Note- can you rewrite the code in C++. Circle Class c++ code Write a circle class...
Note- can you rewrite the code in C++. Circle Class c++ code Write a circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument . • setRadius. A mutator function for the radius variable. • getRadius. An acccssor function...
C++ How to make this code take a class object instead of int for the vector...
C++ How to make this code take a class object instead of int for the vector queue and be able to enqueue and dequeue the object? #include <iostream> #include <float.h> #include <bits/stdc++.h> using namespace std; void print_queue(queue<int> Q) //This function is used to print queue { while (!Q.empty()) { cout<< Q.front() << " "; Q.pop(); } } int main() { int n = 10; vector< queue<int> > array_queues(n); //Create vector of queues of size 10, each entry has a queue...
C++ Please complete based on the code below. Declare another stack object to the code in...
C++ Please complete based on the code below. Declare another stack object to the code in main(). Add a stack operator called CopyStack to the Stack class which, when executed, copies the contents of the first stack into the second stack. Modify your menu so that this option is available. The menu should also allow the second stack to be printed, pushed, popped, and so forth, just like with the first stack. #include using namespace std; #define MAXSize 10 class...
Can someone please convert this java code to C code? import java.util.LinkedList; import java.util.List; public class...
Can someone please convert this java code to C code? import java.util.LinkedList; import java.util.List; public class Phase1 { /* Translates the MAL instruction to 1-3 TAL instructions * and returns the TAL instructions in a list * * mals: input program as a list of Instruction objects * * returns a list of TAL instructions (should be same size or longer than input list) */ public static List<Instruction> temp = new LinkedList<>(); public static List<Instruction> mal_to_tal(List<Instruction> mals) { for (int...
Can you please code in C the Lagrangian function. If you have any questions please let...
Can you please code in C the Lagrangian function. If you have any questions please let me know.
Note- can you please rewrite the code in C++ Write a class declaration named Circle with...
Note- can you please rewrite the code in C++ Write a class declaration named Circle with a private member variable named radius. Write set and get functions to access the radius variable, and a function named getArea that returns the area of the circle. The area is calculated as 3.14159 * radius * radius
A Bookstore Application C++ Design the class Book. Each object of the class Book can hold...
A Bookstore Application C++ Design the class Book. Each object of the class Book can hold the following information about a book: title, authors, publisher, ISBN Include the member functions to perform the various operations on the objects of Book. For example, the typical operations that can be performed on the title are to show the title, set the title. Add similar operations for the publisher, ISBN , and authors. Add the appropriate constructors and a destructor (if one is...
Class object in C++ programming language description about lesson Overloading function example.
Class object in C++ programming language description about lesson Overloading function example.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT