Menu

[solved]-Assignment Introduction C Classes Learn Basic Class Design Put Use Creating Couple Advance Q39038685

This assignment is an introduction to the C++ classes.We will learn the basic of class design, and we will put it to usecreating a couple of more advanced classes.

Part B: Create Point Class – Milestone One

Source File: lab8/point_class.cpp

Problem Statement:

Copy the point_class.cpp file for the Point class. Itimplements operator overloading so you can use cin/cout with pointobjects. (Provided below)

Complete the provided “Point” class which allows aprogrammer to store an x, y coordinate pair. It should have atleast two constructors, at least one set function, and getfunctions for x and y.

The overloaded I/O (cin/cout) functions have beenprovided for your use.

Please create proper test cases for this in main() toverify proper functioning.

Part C: Line Class

Source File: lab8/line_class.cpp

Problem Statement:

Copy the line_class.cpp for the Line class. Itimplements operator overloading so you can use cin/cout with lineobjects. (Provided below)

A line will be made up of two points.

Create an object to implement a “line” class whichallows the programmer to store a line. This class must use the“point” class developed in Part B. The object should have twoconstructors, appropriate set/get functions, and overloaded I/O(cin/cout) functions. It should include functions the return theproper value for the following:

  • Determine the slope of a line

  • Determine the length of a line

  • Determine the y-intercept of a line

  • Determine if the line is vertical

  • Determine if the line is horizontal

  • Determine if the line is parallel to anotherline

Please create proper test cases for this in main() toverify proper functioning.

Note: You should make it easy on yourself and use fourintegers representing the two ends of the line for the secondconstructor

Part D: Let’s Practice Strings with classes

Source File: lab8/string_manip.cpp

Copy the string_manip.cpp for the stringManip class.(Provided below)

Please review the “cctype” and string review given onthe last page of this document.

It will give you a shell to implement the followingclass prototype:

class stringManip {

    public:

stringManip();

stringManip(string input);

string retrieve();

void setString(string input);

void chop();

void padString(int n);

void center(int length);

void truncate(int n);

void removeNonAlpha();

void convertToUpperCase();

void convertToLowerCase();

    private:

     string tobeEdited;

};

All functions act on the tobeEdited string inside of theclass unless indicated otherwise.

Please implement the functions indicated plus theconstructors, and set/get (retrieve and setString)functions.

Function/method descriptions.

  1. chop() – remove both leading and trailing spaces fromthe string.

  1. padString(int n) – Write a function to make sure thatthe string is at least “n” bytes in length. Please add a space orspaces Add blanks toAdd blanks toto the end of the string toaccomplish this. If the string length is already equal to or largerthan “n”, do not modify the string.

  1. center(int length) – Write a function to center thestring within the space specified by length. You should remove anyexisting leading and trailing spaces in the string before centeringit.

Add blanks to the front and back of the string. If anodd number of blanks have to be added, put the extra blank on theright. You should store the result back in the “tobeEdited”string.

  1. truncate(int n) is a function which shortens the stringto n characters.

If the string is already shorter than n, the functionshould not change the string. The characters should be removed fromthe end of the string.

  1. removeNonAlpha() is function that removes all characters(including spaces) that are not alphabetical from the string. Theisalpha function may be helpful for this purpose.

  1. convertToUpperCase() is a function that converts alllowercase characters in the string to uppercase. All othercharacters remain the same.

  2. convertToLowerCase() is a function that converts alllowercase characters in the string to uppercase. All othercharacters remain the same.

To receive full credit for this assignment your programshould follow these guidelines:

  • Milestone signed off during recitationsession

  • Implement all .cpp files  

  • Assignment uploaded to blackboard

  • Only use global variables for constants

  • Appropriate use of classes and/or functions

  • You must format the code properly using properindentation, descriptive variable and function names, and propercommenting.

point_class.cpp code:

// Add your information here#include <iostream>#include <string>#include <vector>#include <cctype>using namespace std;// Please complete this Point class.// The cin/cout operators have been overloaded for youclass Point { // cout implementation for Point class friend ostream & operator<<( ostream &output, const Point &P ){ output << “x: ” << P.x << ” y: ” << P.y; return output; } // cin implementation for Point class friend istream & operator>>( istream &input, Point &P ){ input >> P.x >> P.y; return input; }public: Point(){ x = 0; y = 0; } Point(int in_x, int in_y){ x = in_x; y = in_y; } // Add your functions hereprivate: int x,y;};int main(){ Point P1; Point P2(7,6); cout << “Point P1 should have 0,0 as values” << endl; cout << P1 << endl; cout << “Point P2 should have 7,6 as values” << endl; cout << P2 << endl; cout << “Enter x and y points: ie 3 4 “; cin >> P1; cout << P1 << endl; return 0;}

line_class.cpp code:

// Add your information here#include <iostream>#include <string>#include <vector>#include <cctype>using namespace std;// Please replace this Point class with your version from Part Bclass Point { friend ostream & operator<<( ostream &output, const Point &P ){ output << “x: ” << P.x << ” y: ” << P.y; return output; } friend istream & operator>>( istream &input, Point &P ){ input >> P.x >> P.y; return input; }public:private: int x,y;};class Line { // implement cout for Line classes objects friend ostream & operator<<( ostream &output, const Line &L ){ output << “Point 1: ” << L.P1 << endl << “Point 2: ” << L.P2; return output; } // implement cin for Line classes objects friend istream & operator>>( istream &input, Line &L ){ input >> L.P1 >> L.P2; return input; }public: // Add your functions/methods here // Line(){ }private: Point P1, P2;};int main(){ Line L1; // Line L2(5,6,7,8); cout << “L1: should have all zeros for values” << endl; cout << L1 << endl; cout << “Enter Two Points For Line: “; cin >> L1; cout << L1 << endl; return 0;}

string_manip.cpp code:

// Please place your information here//#include <iostream>#include <string>#include <cctype>using namespace std;// This prototype is completeclass stringManip { public: stringManip(); stringManip(string input); string retrieve(); void setString(string input); void chop(); void padString(int n); void center(int length); void truncate(int n); void removeNonAlpha(); void convertToUpperCase(); void convertToLowerCase(); private: string tobeEdited;};// Not all functions are defined here// Default ConstructorstringManip::stringManip(){ // finish me}// Overloaded ConstructorstringManip::stringManip(string in_string){ // finish me}// retrieve functionstring stringManip::retrieve(){ // finish me return “please replace return”;}// padString() functionvoid stringManip::padString(int length){ // finish me}// Add rest of functions here// Add test cases to main()int main(){ stringManip S1; stringManip S2(“testing 123”); // Test case for padString() You should correct some of your own. cout << “S2 before padString(20): <” << S2.retrieve() << “>” << endl; S2.padString(20); cout << “S2 after padString(20): <” << S2.retrieve() << “>” << endl; cout << “Should be: <testing 123 >” << endl; return 0;}

Expert Answer


Answer to This assignment is an introduction to the C++ classes. We will learn the basic of class design, and we will put it to us… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *