Question
My professor provided a very vague description of what he wants us to do with the example code from the book. I have provided the picture of his description and the code from the book we need to alter. I'm already struggling with this course and I'll probably have to post another question on a different problem I'm stuck on.

If you can help it would be highly appreciated.

Description Change code for double, string, C-string with appropriate convert constructors and getter methods...
Contents of Convert.h 1 #include <iostream> 2 using namespace std; 4 class IntClass 5 { 6 private: 7 int value; 8 public: 9 1
11.10 Convert Constructors 12 .. 13 // Prints the int value inside an IntClass 14 I/ object 15 // ....... 16 void print Value
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Thanks for the question, here are the 7 files. For each type there are tow files - 1).h file 2) .cpp file. And the 7th file is the main file

DoubleClass.h file and DoubleClass.cpp file

StringClass.h file and StringClass.cpp file

CStringClass.h file and CStringClass.cpp file

Main.cpp file

=======================================================================

#ifndef STRINGCLASS_H

#define STRINGCLASS_H

#include<string>

using std::string;

class StringClass

{

                public:

                                StringClass(const string&);

                                string getValue() const;

                private:

                                string value;

};

#endif

==================================================================

#include "StringClass.h"

#include<string>

using std::string;

StringClass::StringClass(const string& val) : value(val){}

string StringClass::getValue() const{return value;}

               

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef DOUBLECLASS_H

#define DOUBLECLASS_H

class DoubleClass

{

                public:

                                DoubleClass(double);

                                double getValue() const;

                private:

                                double value;

};

#endif

==================================================================

#include "DoubleClass.h"

DoubleClass::DoubleClass(double val) : value(val){}

double DoubleClass::getValue() const{return value;}

               

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef CSTRINGCLASS_H

#define CSTRINGCLASS_H

class CStringClass

{

                public:

                                CStringClass(const char* );

                                char* getValue() const;

                                ~CStringClass();

                private:

                                char *value;

};

#endif

==================================================================

#include "CStringClass.h"

#include<cstring>

using namespace std;

               

CStringClass::CStringClass(const char* val){

                int length = strlen(val);

                value = new char[length+1];

                strcpy(value,val);

}

CStringClass::~CStringClass(){

               

                delete[] value;

}

char* CStringClass::getValue() const{

                int length = strlen(value);

                char* p_value = new char[length+1];

                strcpy(p_value,value);

               

                return p_value;

               

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Main.cpp file

#include <iostream>

#include "StringClass.h"

#include "CStringClass.h"

#include "DoubleClass.h"

#include<string>

using namespace std;

int main(){

               

                StringClass myStringClass = StringClass("Hello!");

               

                cout<<myStringClass.getValue()<<endl;

               

                DoubleClass myDoubleClass = 3.14159;

                cout<<myDoubleClass.getValue()<<endl;

               

                CStringClass myCStringClass ("Hi How are You?");

                cout<<myCStringClass.getValue()<<endl;

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Add a comment
Know the answer?
Add Answer to:
My professor provided a very vague description of what he wants us to do with 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
  • 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...

  • What are the errors in the following code? My professor gave us this prewritten code and...

    What are the errors in the following code? My professor gave us this prewritten code and asked us to find the errors in it so that it can run properly #include <cstdlib> #include <ctime> #include <iostream> using namespace std; // input: integer // output: none // adds five to the given parameter void addFive( int x ) { x += 5; } // input: none // output: a random number int generateRandomNumber() { srand( time(0) ); return rand() % 100;...

  • 5. (7 pts) What wil display on the output screen after following program is executed? includeciostream...

    5. (7 pts) What wil display on the output screen after following program is executed? includeciostream using namespace std int b 40 int A function(int a) int main (void) int c 7, b 15 cout<cA function (e) <cendla return 6 int A function (int a) int i cout<<b<<endl; if (a>-0) else return i i-ai i--ai Ans5 6. (7 pts) Show what will appear on the output screen after the following program is executed tincludeciostream> using namespace std; void A function...

  • I'm kind of new to programming, and I am having trouble figuring out why my program...

    I'm kind of new to programming, and I am having trouble figuring out why my program isn't running. Below is the code that I wrote for practice. I will comment where it says the error is. So the error that I'm getting is "error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' ". I'm not sure why I'm getting this because I added the library <iostream> at the top. Thank you. Code: #include <iostream> using namespace std; class...

  • 1 // This program will input the value of two sides of a right triangle and...

    1 // This program will input the value of two sides of a right triangle and then 2 // determine the size of the hypotenuse. 3 4 // PLACE YOUR NAME HERE 5 6 #include <iostream> 7 #include <cmath> Il needed for math functions like sqrt() 8 using namespace std; 9 10 int main() 11 { 12 float a, b; // the smaller two sides of the triangle 13 float hyp; // the hypotenuse calculated by the program 14 15...

  • Convert the below code into if else selection: #include <iostream> using namespace std; int main() {...

    Convert the below code into if else selection: #include <iostream> using namespace std; int main() { int num; sin. >> num; switch (num) { case 1: cout << "Casel: Value is: << num << endl; break; case 2: break; case 3: cout << "Case3: Value is: " << num << endl; break; default: cout << "Default: Value is: << num << endl; break; } return; }

  • I have to type and explain in class each code in every detail filled with //...

    I have to type and explain in class each code in every detail filled with // commentary. Explains how does work in every codes. 1) What does the below print #include <iostream> using namespace std ; int main() {    int var1 = 20 ;    int var2 = 30 ;    int* ptr1 ;    int* ptr2 ;    int* temp ;    ptr1 = &var1 ;    ptr2 = &var2 ;    cout << *ptr1 << endl ;...

  • Write a C++ Program. You have a following class as a header file (dayType.h) and main()....

    Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public:     static string weekDays[7];     void print() const;     string nextDay() const;     string prevDay() const;     void addDay(int nDays);     void setDay(string d);     string getDay() const;     dayType();     dayType(string d); private:     string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...

  • Subject: Object Oriented Programming (OOP) Please kindly solve the above two questions as soon as possible...

    Subject: Object Oriented Programming (OOP) Please kindly solve the above two questions as soon as possible would be really grateful to a quick solution. would give a thumbs up. Thank you! Q3: Question # 3 [20] Will the following code compile? If it does not, state the errors. If it does compile, write the output. //Function.cpp #include <iostream> using namespace std; void printData (long i) cout<<"In long print Data "«<i<<endl; } void printData(int i) cout<<"In int printData "<<i<<endl; ) void...

  • solve it in c++ 10 note: please do not give me same answer like this 1....

    solve it in c++ 10 note: please do not give me same answer like this 1. Define a Pet class that stores the pet's name, age, and weight. Add appropriate constructors, accessor functions, and mutator functions. Also define a function named getLifespan that returns a string with the value "unknown lifespan." Next, define a Dog class that is derived from Pet. The Dog class should have a private member variable named breed that stores the breed of the dog. Add...

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