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
  • Create a base class and two derived classes. Also, create and call a member function named...

    Create a base class and two derived classes. Also, create and call a member function named communicate() that behaves differently when called by each class. Create a single C++ project (and CPP source file) named animal_communication as follows: Into this source, type the source code for Program 15-16, "Program Output," in Section 15.6, "Polymorphism and Virtual Member Functions," in Ch. 15, "Inheritance, Polymorphism, and Virtual Functions," of Starting Out With C++ From Control Structures Through Objects. Run and debug the...

  • 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...

  • C++ please! OVERVIEW This homework builds on HW4. We will modify the classes to do a...

    C++ please! OVERVIEW This homework builds on HW4. We will modify the classes to do a few new things We will add copy constructors to the Antique and Merchant classes. We will overload the == operator for Antique and Merchant classes. We will overload the + operator for the antique class. We will add a new class the "MerchantGuild." Please use the provided templates for the Antique and Merchant classes, as we simplified their functionality for this homework. Also, you...

  • 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:...

  • previous assignment code /*C++ test program to test the classes, Animal, Mammal and Cat and print...

    previous assignment code /*C++ test program to test the classes, Animal, Mammal and Cat and print the results on console window.*/ //Main.cpp //include header files #include<iostream> //include Animal, Mammal and Cat header files #include "Animal.h" #include "Mammal.h" #include "Cat.h" using namespace std; int main() {    //create Animal object    Animal animal("Dog","Mammal",4);    cout<<"Animal object details"<<endl;    cout<<"Name: "<<animal.getName()<<endl;    cout<<"Type: "<<animal.getType()<<endl;    cout<<"# of Legs: "<<animal.getLegs()<<endl;          cout<<endl<<endl;    //create Cat object    Cat cat("byssinian cat","carnivorous mammal",4,"short...

  • 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...

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