Question

For this homework assignment, you will create two classes that will work with each other. The...

For this homework assignment, you will create two classes that will work with each other.

The first is a class you will write is called CQuadratic, which represents a second-order quadratic equation (e.g., 3x2 + 2x + 9).  CQuadratic will only have one constructor (type constructor), which will take the coefficients of the quadratic equation (e.g., 3, 2, 9) and assign them to it’s three private data members (the three coefficient variables). The class also has an Evaluate function that passes a value, say x, and returns the evaluated expression f(x) (e.g., for f(x) = 3x2 + 2x + 9). Lastly, it has a destructor that will display to stdout “CQuadratic destructor!!!”

The second class is called CMathStud which represents a math stud(ent : ). Every CMathStud has his/her own particular quadratic equation. The constructor for CMathStud will only require the first two coefficients (x2 and x) as arguments; the third is optional to provide (default to 0). CMathStud has a getMyValue method, which accepts a value for x and should return f(x) for the math student’s quadratic equation.

All you need to do is fill in the ??? for all files (including main) and make sure you include the proper headers within each file and preprocessor directives. As a note, you’re required to code all implementation in the corresponding .cpp files. All header files are for function prototypes only. Your code should mimic the output below:

CQuadratic constructor!!!

CMathStud constructor!!!

CQuadratic constructor!!!

CMathStud constructor!!!

Stud1 Eval: 16.1528
Stud2 Eval: 47.1751

CMathStud destructor!!!

CQuadratic destructor!!!

CMathStud destructor!!!

CQuadratic destructor!!!

Get all five files (main.cpp, cquadratic.h, cquadratic.cpp, cmathstud.h, and cmathstud.cpp) together in a multi-module project.

main.cpp

???


int main()
{
// Create an object
CMathStud stud1(1,2);
CMathStud stud2(3,4,5);

// Evaluation
cout << "Stud1 Eval: " << stud1.getMyValue(3.14159) << endl;
cout << "Stud2 Eval: " << stud2.getMyValue(3.14159) << endl << endl;

return 0;

} // end of "main"

cmathstud.h

class CMathStud
{
public:
???

private:
CQuadratic QE;
};

cquadratic.h

class CQuadratic
{
public:
???

private:
int c1;
int c2;
int c3;
};

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//========main.cpp====================================
#include<iostream>
using namespace std;
#include "cmathstud.h"
int main()
{
// Create an object
CMathStud stud1(1,2);
CMathStud stud2(3,4,5);

// Evaluation
cout << "Stud1 Eval: " << stud1.getMyValue(3.14159) << endl;
cout << "Stud2 Eval: " << stud2.getMyValue(3.14159) << endl << endl;

return 0;

} // end of "main"
//================================================

//===========cmathstud.h=====================================
#include "cquadratic.h"
class CMathStud
{
public:
CMathStud(){ //default constructor
cout<<"CMathStud constructor!!!"<<endl;
}
CMathStud(int x2,int x,int a=0){ //parametrized constructor
QE=new CQuadratic(x2,x,a);
cout<<"CMathStud constructor!!!"<<endl;
}
float getMyValue(float x){ //evaluate f(x)=ax^2+bx+c
float result;
result=QE->Evaluate(x);
return result;
}
~CMathStud(){ //destructor
cout<<"CMathStud destructor!!!"<<endl;
}

private:
CQuadratic *QE;
};
//================================================

//===========cquadratic.h=====================================
class CQuadratic
{
public:
CQuadratic(){ //default constructor
cout<<"CQuadratic constructor!!!"<<endl;
}
CQuadratic(int z1,int z2,int z3){ //parametrized constructor
c1=z1;
c2=z2;
c3=z3;
cout<<"CQuadratic constructor!!!"<<endl;
}
float Evaluate(float x){ //evaluate f(x)=ax^2+bx+c
return c1*x*x+c2*x+c3;
}
~CQuadratic(){ //destructor
cout<<"CQuadratic destructor!!!"<<endl;
}

private:
int c1;
int c2;
int c3;
};
//================================================

Sample output:

Add a comment
Know the answer?
Add Answer to:
For this homework assignment, you will create two classes that will work with each other. The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ This exercise will introduce static member variables and static methods in class to you. Class...

    C++ This exercise will introduce static member variables and static methods in class to you. Class Department contain information about universities departments: name students amount in addition it also stores information about overall amount of departments at the university: departments amount class Department { public: Department(string i_name, int i_num_students); ~Department(); int get_students(); string get_name(); static int get_total(); private: string name; int num_students; static int total_departments; }; Carefully read and modify the template. You have to implement private static variable "total...

  • Greetings, everybody I already started working in this program. I just need someone to help me...

    Greetings, everybody I already started working in this program. I just need someone to help me complete this part of the assignment (my program has 4 parts of code: main.cpp; Student.cpp; Student.h; StudentGrades.cpp; StudentGrades.h) Just Modify only the StudentGrades.h and StudentGrades.cpp files to correct all defect you will need to provide implementation for the copy constructor, assignment operator, and destructor for the StudentGrades class. Here are my files: (1) Main.cpp #include <iostream> #include <string> #include "StudentGrades.h" using namespace std; int...

  • 13.21 Lab: Rational class This question has been asked here before, but every answer I have...

    13.21 Lab: Rational class This question has been asked here before, but every answer I have tested did not work, and I don't understand why, so I'm not able to understand how to do it correctly. I need to build the Rational.cpp file that will work with the main.cpp and Rational.h files as they are written. Rational Numbers It may come as a bit of a surprise when the C++ floating-point types (float, double), fail to capture a particular value...

  • // thanks for helping // C++ homework // The homework is to complete below in the...

    // thanks for helping // C++ homework // The homework is to complete below in the stack.h : // 1. the copy constructor // 2. the assignment operator // 3. the destructor // 4. Write a test program (mytest.cpp) to test copy and assignment // 5. Verify destructor by running the test program in Valgrind // This is the main.cpp #include <iostream> #include "stack.h" using namespace std; int main() { Stack<int> intStack; cout << "\nPush integers on stack and dump...

  • create a programn in C++ that creates a class that represents a manufactured part on a...

    create a programn in C++ that creates a class that represents a manufactured part on a bill of material (BOM). with the following attributes: identifier (The parts identifier as an alpha numeric string), drawing (The AutoCAD drawing file that represents the part), quantity (The number of parts that are required). implement the functions for the Part class in the file Part.cpp. The file main.cpp will only be used for testing purposes, no code should be written in main.cpp. -part.cpp file:...

  • using C++ language!! please help me out with this homework In this exercise, you will have...

    using C++ language!! please help me out with this homework In this exercise, you will have to create from scratch and utilize a class called Student1430. Student 1430 has 4 private member attributes: lastName (string) firstName (string) exams (an integer array of fixed size of 4) average (double) Student1430 also has the following member functions: 1. A default constructor, which sets firstName and lastName to empty strings, and all exams and average to 0. 2. A constructor with 3 parameters:...

  • C++ programming language: In this program you will create a simplified bag that acts like a...

    C++ programming language: In this program you will create a simplified bag that acts like a stack meaning that the Last item inserted is the First Item that comes out. Your backend implementation must use a linked list. The code should pass the test (there's only 1) and there should be no memory leaks. Note that passing the test does not ensure full credit! The functions are listed in the suggested order of implementation but you may implement them in...

  • Hello, I'm looking to modify my fraction program to include constructors and destructors. Here are all...

    Hello, I'm looking to modify my fraction program to include constructors and destructors. Here are all the instructions: Create constructors default two argument three argument copy constructor Create a destructor. The destructor should set whole and numerator to zero and denominator to one. Add cout statements to the constructors and the destructor so you know when it's getting executed. Add system ("pause") to the destructor so you know when it executes. Only positive values allowed If denominator is 0 set...

  • in c++ please include all of the following " template class, template function, singly linked list,...

    in c++ please include all of the following " template class, template function, singly linked list, the ADT stack, copy constructor, operator overloading, "try catch"and pointers Modify the code named "Stack using a Singly Linked List" to make the ADT Stack that is a template class has the code of the destructor in which each node is directly deleted without using any member function. As each node is deleted, the destructor displays the address of the node that is being...

  • You are given a partial implementation of two classes. GroceryItem is a class that holds the...

    You are given a partial implementation of two classes. GroceryItem is a class that holds the information for each grocery item. GroceryInventory is a class that holds an internal listing of GroceryItems as well as the tax rate for the store. Your inventory could be 100 items it could be 9000 items. You won’t know until your program gets the shipment at runtime. For this you should use the vector class from the C++ standard library. I've completed the GroceryItem.h...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT