Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(really need answer not suggestions )Given this c++ code: #include <iostream> #i

ID: 644618 • Letter: #

Question

(really need answer not suggestions )Given this c++ code:

#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>

class Shape{
public:
   virtual double GetArea();
   virtual bool CheckValidity();
};

class Rectangle{
private:
   double a, b;
public:
   Rectangle(double a, double b){
       setA(a);
       setB(b);
   }
   void setA(double val){ a = val; }
   void setB(double val){ b = val; }
   double getA() const { return a; }
   double getB() const { return b; }
   bool CheckValidity(){
       if (a > 0 && b > 0){
           return true;
       }
       return false;
   }
   double GetArea(){
       return a * b;
   }
};

class Triangle{
private:
   double a, b, c;
public:
   Triangle(double a, double b, double c){
       setA(a);
       setB(b);
       setC(c);
   }
   void setA(double val){ a = val; }
   void setB(double val){ b = val; }
   void setC(double val){ c = val; }
   double getA() const { return a; }
   double getB() const { return b; }
   double getC() const { return c; }
   bool CheckValidity(){
       if (a > 0 && b > 0 && c > 0){
           if (a > b && a > c){
               return a < (b + c);
           }
           else if (b > a && b > c){
               return b < (a + c);
           }
           else if (c > a && c > b){
               return c < (a + b);
           }
       }
       return false;
   }
   double GetArea(){
       double p = (a + b + c) / 2;
       return sqrt(p * (p - a) * (p - b) * (p - c));
   }
};

using namespace std;

int main(){
   vector<Rectangle> vRect;
   vector<Triangle> vTriangle;
   ifstream in;
   in.open("Tsides.txt");
   double a, b, c;
   if (in.is_open()){
       while (in >> a){
           in >> b >> c;
           Triangle temp = Triangle(a, b, c);
           if (temp.CheckValidity()){
               vTriangle.push_back(temp);
           }
       }
   }
   in.close();
   in.open("Rsides.txt");
   if (in.is_open()){
       while (in >> a){
           in >> b;
           Rectangle temp = Rectangle(a, b);
           if (temp.CheckValidity()){
               vRect.push_back(temp);
           }
       }
   }
   in.close();
   ofstream out;
   out.open("Tareas.txt");
   for (int i = 0; i < vTriangle.size(); ++i){
       out << vTriangle[i].GetArea() << endl;
   }
   out.close();
   out.open("Rareas.txt");
   for (int i = 0; i < vRect.size(); ++i){
       out << vRect[i].GetArea() << endl;
   }
   out.close();
   return 0;
}

Implement one sorting algorithm at your own selection (selection sort or quick sort preferred). You are required to sort your vectors of Shape objects (or two vectors, one for Rectangle objects and one for Triangle objects) based on their areas.

Implement a customized binary search algorithm that takes a vector of certain objects, a target area value, and a range, returns the index of the first object in the vector with the same area value.

Your program should read at least 50 valid sides from the files and then call the sorting algorithm. Then, it keeps asking the user to enter an area value to search until user decides to quit. You should ask user "do you want to quit(y/n)?" and quit if "y" is typed, or something similar.

Explanation / Answer

Sorting a;gorithm is an algorithm that puts elements of a list in a certain order.

#include <iostream>

#include <fstream>

#include <vector>

#include <algorithm>

#include <cmath>

using namespace std;

int main ()

{

char ints[]={'A','B','C'};

vector <char> myvector(myints, myints+3);

sort (myvector.begin(),myvector.end());

cout << "myvector contains:";

for (int i=0; i!=3; i++)

cout << ' ' myvector[i];

cout << ' ';

system("quit(y/n)");

return 0;

}