Question

In: Computer Science

Make one program in c++ Implement the Point class composed of an ordered pair (?, ?)....

Make one program in c++

Implement the Point class composed of an ordered pair (?, ?). Redefine the operators in your Point class
Calculate the coefficients of a Linear Regression ? = ?? + ? with next data for x and y.
x    y
46  4.7
72  12.3
59  6.5
56  5.9
54  6.6
70  10.3
68  8.4
48  4

Solutions

Expert Solution

HERE IS YOUR CODE,

#include "TwoDPoint.h"
#include <iostream>
using namespace std;
 
int main()
{
   int a,b;
   TwoDPoint ptsArray1[2];  
   cout << "Enter ordered pairs : " << endl;
   for(int i=0; i<2; i++ )
   {
       cin >> a;
       cin >> b;
       ptsArray1[i].setX(a);
       ptsArray1[i].setY(b);
   }
   int sumx=0, sumy=0 ,txy,tx2,ty2;
   double xy[2],x2[2],y2[2];
    for(int i=0; i<2; i++ )
   {
        xy[i] = ptsArray1[i].getX() * ptsArray1[i].getY();
        x2[i] = ptsArray1[i].getX() * ptsArray1[i].getX();
        y2[i] = ptsArray1[i].getY() * ptsArray1[i].getY();
   }
    for(int i=0; i<2; i++ )
   {
       sumx = sumx + ptsArray1[i].getX();
       sumy = sumy + ptsArray1[i].getY();
       txy  = txy + xy[i];
       tx2  = tx2 + x2[i];
       ty2  = ty2 + y2[i];
   }
   
   int A,B;
   A = (sumx*tx2)-(sumx*txy) / 2*(tx2) - (tx2)^2;
   B = 2*(txy) - (sumx)*(sumy) / 2*(tx2) - (tx2)^2;
   
   cout << "Y =" << A << " + " << B <<" x" << endl;
   
    return 0;
}

"TwoDPoint.h" and "TwoDPoint.cpp" are given below,

#ifndef TWODPOINT_H_
#define TWODPOINT_H_

namespace std {

class TwoDPoint {

protected:
        double x;
        double y;

public:
        TwoDPoint();
        TwoDPoint(double a, double b);
        virtual ~TwoDPoint();
        double getX() const;
        void setX(double x);
        double getY() const;
        void setY(double y);
        void print();
};

} /* namespace std */

#endif /* TWODPOINT_H_ */
#include "TwoDPoint.h"
#include <iostream>

namespace std {

TwoDPoint::TwoDPoint() {
        // TODO Auto-generated constructor stub
        x = 0.0;
        y = 0.0;
}
TwoDPoint::TwoDPoint(double a, double b) {
        // TODO Auto-generated constructor stub
        x = a;
        y = b;
}
double TwoDPoint::getX() const {
        return x;
}

void TwoDPoint::setX(double x) {
        this->x = x;
}

double TwoDPoint::getY() const {
        return y;
}

void TwoDPoint::setY(double y) {
        this->y = y;
}
void TwoDPoint::print() {
   cout << "Point @ (" << x << "," << y << ")";
}
TwoDPoint::~TwoDPoint() {
        // TODO Auto-generated destructor stub
}

} /* namespace std */

The output of the code is;


Related Solutions

Implement a class named stack pair that provides a pair of stacks. Make the class a...
Implement a class named stack pair that provides a pair of stacks. Make the class a template class. So, you will have two files: stack pair.h and stack pair.template, following the style of the text. The basic idea is that two stacks can share a single static array. This may be advantageous if only one of the stacks will be in heavy use at any one time. • The class should have various methods to manipulate the stack: T pop...
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
Implement a program as an object using a class (abstract data type) in C++ that does...
Implement a program as an object using a class (abstract data type) in C++ that does the following: 1) reads the firstName, lastName and 3 test scores of at least five students. 2) calculate student test score totals, average, letter grade for each student. 3) Display the results in a table format showing firstName, lastName, test1, test2, test3, total, average, letterGrade, of all the students. 3 files .h, .cpp, main.cpp create an object that can hold records. must get records...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that prompts the user to select a type of coffee she likes and 2) returns the object of what she selected to the console. #include "stdafx.h" #include <iostream> using namespace std; // Product from which the concrete products will inherit from class Coffee { protected:    char _type[15]; public:    Coffee()    {    }    char *getType()    {        return _type;   ...
Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class...
Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class with public and private members and multiple constructors.  Gain a better understanding of the building and using of classes and objects.  Practice problem solving using OOP. Overview You will implement a date and day of week calculator for the SELECTED calendar year. The calculator repeatedly reads in three numbers from the standard input that are interpreted as month, day of month, days...
C++ program homework question 1 1. Create and implement a class called clockType with the following...
C++ program homework question 1 1. Create and implement a class called clockType with the following data and methods (60 Points.): Data: Hours, minutes, seconds Methods: Set and get hours Set and get minutes Set and get seconds printTime(…) to display time in the form of hh:mm:ss default and overloading constructor Overloading Operators: << (extraction) operator to display time in the form of hh:mm:ss >> (insertion) operator to get input for hours, minutes, and seconds operator+=(int x) (increment operator) to...
Overloaded Constructors Add a pair of constructors to the Height class that implement the initializations provided...
Overloaded Constructors Add a pair of constructors to the Height class that implement the initializations provided by the two setHeight operations in Figure 7.11. Minimize the total number of statements by having the one parameter constructor call the one-parameter setHeight method and having the two-parameter constructor call the two-parameter setHeight method. Provide a complete rewritten main method for the HeightDriver class such that the new method uses one of the new constructors from part a) to generate this output: 6.0...
(Write a C# program DO NOT USE CLASS)Implement the merge sort algorithm using a linked list...
(Write a C# program DO NOT USE CLASS)Implement the merge sort algorithm using a linked list instead of arrays. You can use any kind of a linked structure, such as single, double, circular lists, stacks and/or queues. You can populate your list from an explicitly defined array in your program. HINT: You will not be using low, middle and high anymore. For finding the middle point, traverse through the linked list while keeping count of the number of nodes. Break...
Write a C program to implement a queue (FIFO) of characters in a one-way, circular, linked...
Write a C program to implement a queue (FIFO) of characters in a one-way, circular, linked list. One way means that each node has only one pointer, Q, (not both a rear and a front pointer), so the program must use pointers-to-pointers. Include functions to insert(), remove(), for use in main() where the user is prompted "Enter "i" to insert a new element, "r" to remove an element, "q" to quit:"
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT