Lab #14. Object-oriented programming
Lab #14.1.
Class interval
(lab14.1.cpp)
#include <iostream>
using namespace std;
class interval
{
};
int main()
{
interval i; // sākumā dots intervāls 0..100
i.setX (1);
i.setY (-5.5); //
pārbaude X<=Y!!!
i.setY (5.5);
i.setX (6); // pārbaude X<=Y!!!
cout
<< "Length: " << i.length()
<< endl;
cout
<< "Center: " << i.center() << endl;
return 0;
}
Given part of
code that utilizes class interval. Design code for class interval.
Desired output:
Error: -5.5
Error: 6
Length: 4.5
Center: 3.25
Correct solution: lab14.1a.cpp.
Lab #14.2.
Class triangle
(lab14.2.cpp)
#include <iostream>
using namespace std;
class triangle
{
};
int main ()
{
triangle a
(3,4,5);
a.change (0,0,1); // katras malas izmaiņa
triangle b (2);
// visas trīs malas aizpildās ar 2
triangle *c = new
triangle (a); // aizpilda kā
a
a.print (); // izdrukā 3,4,6
a.perimeter ();
// izdrukā 13
c->change (2);
// visu malu izmaiņa vienādi
c->perimeter
(); // izdrukā 19
a.longest (); //
garākā mala: izdrukā 6
b.longest (); //
garākā mala: izdrukā 2
delete c;
return 0;
}
Given part of
code that utilizes class triangle. Design code for class triangle.
Desired
output:
3 4 6
13
19
6
2
Correct solution: lab14.2a.cpp.