Any help writing all the parts for this program would be greatly appreciated. I
ID: 3687958 • Letter: A
Question
Any help writing all the parts for this program would be greatly appreciated. I am completely lost as to what needs to be done.
A class Coord has two attributes of x and y coordinates. The class has two member functions as defined below.
#include <cstdlib>
class Coord {
private:
int x, y;
public:
Coord (int i1, int i2) : x(i1), y(i2) {
}
friend Coord operator- (Coord const& c1, Coord const& c2) {
return Coord(c1.x-c2.x, c1.y-c2.y);
}
Coord abs() {
return Coord(std::abs(x),std::abs(y));
}
int getX() {return x};
int getY() {return y};
};
/*Note int abs (int n); Returns the absolute value of parameter n*/
A base class GeoObj is for geometric objects.
class GeoObj {
public:
// return center of gravity of geometric object.
virtual Coord center_of_gravity() const ;
//...
private:
Coord center; // center_of_gravity;
};
a) A geometric class Circle and class Line is derived from GeoObj. Define and provide implementation of class Circle class and Line [10 Marks]. Define and provide implementation of a function template called distance that processes the distance of center of gravity between two objects of GeoObj [10 Marks]. The calculation is supposed to use the operator – for the center of gravity of two objects. The usage of this distance function is shown below.
int main()
{
Line l;
Circle c, c1, c2;
Coord d1 = distance(c1,c2);
Coord d2 = distance(l,c);
}
b) Define and provide implementation of operator << that outputs the type and center_of_gravity. For example, for a Circle object, the operator << outputs the type “Circle” followed by the X and Y coordinate of center_of_gravity. Likewise, for a Line object, the operator << outputs “Line” followed by the X and Y coordinate of center_of_gravity. You need to decide where (e.g. class GeoObj, class Circle or class Line) this operator << should be defined. This operator allows outputs to standard display such as the console or to a file.
c) Define a driver to test the class Circle, Line, function template distance and operator << overloaded for both cout and file streams.
Explanation / Answer
import JaCoP.constraints.*; import JaCoP.core.*; import JaCoP.search.*; import java.io.*; import java.util.*; import java.text.*; public class CrossWord { Store store; String letters = "abcdefghijklmnopqrstuvwxyz"; String[] letters_array; public void model() { store = new Store(); letters.trim(); letters_array = letters.split(""); int a = 1 ; int b = 2; int c = 3; int d = 4; int e = 5; int f = 6 ; int g = 7; int h = 8; int i = 9; int j = 10; int k = 11; int l = 12; int m = 13; int n = 14; int o = 15; int p = 16; int q = 17; int r = 18; int s = 19; int t = 20; int u = 21; int v = 22; int w = 23; int x = 24; int y = 25; int z = 26; int zero = 0; // // The words that may be used // int num_words = 15; int word_len = 5; int[][] words = { {h, o, s, e, s}, // HOSES {l, a, s, e, r}, // LASER {s, a, i, l, s}, // SAILS {s, h, e, e, t}, // SHEET {s, t, e, e, r}, // STEER {h, e, e, l, zero}, // HEEL {h, i, k, e, zero}, // HIKE {k, e, e, l, zero}, // KEEL {k, n, o, t, zero}, // KNOT {l, i, n, e, zero}, // LINE {a, f, t, zero, zero}, // AFT {a, l, e, zero, zero}, // ALE {e, e, l, zero, zero}, // EEL {l, e, e, zero, zero}, // LEE {t, i, e, zero, zero} // TIE }; // // Some trickery: // We use the _transpose_ of the AX matrix in the // Element constraints below. // int[][] words_t = new int[word_len][num_words]; for(int I = 0; IRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.