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

PLEASE READ THE QUESTION BEFORE YOU POST THE ANSWER. USE C++ AND PLEASE DESCRIBE

ID: 3716887 • Letter: P

Question

PLEASE READ THE QUESTION BEFORE YOU POST THE ANSWER. USE C++ AND PLEASE DESCRIBE YOUE CODE. ALSO RUN YOUR PROGRAM AND ANSWER IT PLEASE.

MOST OF THE ANSWER BEFORE ARE FALSE. SO PLEASE DONOT JUST COPY AND PASTE. DO IT FROM SCRATCH.

Requested files: Point.h, Point.cpp, Shape.h, Shape.cpp, Polygon.h, Polygon.cpp, Ellipse.h, Ellipse.cpp, ShapeNodePoly.cpp, ShapeNodePoly_test.cpp
Type of work: Individual work

In this assignment, you will create a class that can behave as any of the shapes listed below. You will use object inheritance to enable all shapes to be managed using the same interface. The functions named in your interface file will be polymorphic; they behave differently depending on the instance of a shape is being emulated by an object.

Using the combination of inheritance and function overloading, you will design a program that can manipulate a group of objects derived from the base class Shape. A Shape is an abstract class that can be used to represent instances of the following geometric shapes:

A Triangle

A Rectangle

A Square

An Oval

A Circle

An Elliipse

Your program should contain classes to create each type of object listed above. You should design an inheritance hierarchy where all classes are derived from an abstract class called Shape. The shape class should have a virtual function getArea() that when invoked on an object will return the area of that shape object. You should insert the code from the GeometricArea program for the appropriate type of shape object. Here is a guide to calculating the area of an ellipse and how it relates to a circle.

Your program should make use of a concrete class named Point. Point has two fields of type float: x and y representing a Cartesian coordinate that identifies a location in the xy plane. Each shape should contain the necessary fields to represent itself: for example, a triangle would contain 3 Point objects, a circle 1 Point.

Be sure to consider using intermediate classes. For example, Triangle, Rectangle, Square are all polygons, so it is good design practice to create an intermediate class Polygon, from which Triangle, Rectangle and Square are all derived. There is a similar relationship between an ellipse and a circle; a circle is an ellipse where the two focal points are the same and the length of the major and minor radii are the same.

Note: In the ShapeNodePoly assignment you do not submit a separate file. The evidence for grading the inheritance hierarchy you design is provided by putting the appropriate C++code into each of the named files.

Explanation / Answer

//main.cpp
#include<iostream>
#include "Mergesort.h"
#include<fstream>

using namespace std;
int main()
{
    int size;
    int* numbers;
    fstream file;
  
    file.open("threesData.bin", ios::binary | ios::in |ios::ate);
    int memory = file.tellg();   
    size = memory/4;  
    numbers = new int[size];  
    file.seekg(0, ios::beg);
    file.read(reinterpret_cast<char *>(numbers), sizeof(numbers));
    file.close();
  
    mergesort(numbers, size);   //sort the array
  
    file.open("sortedThreesData.bin", ios::binary | ios::out |ios::ate);  
    file.write(reinterpret_cast<char *>(numbers), sizeof(numbers));
    file.close();
  
    delete[]numbers;  
    return 0;
}
---------------------------------------------------------------------------------------------------
//MergeSort.cpp
#include<iostream>
#include"Mergesort.h"
using namespace std;

void selectionsort(int array[], int size){
    int scan;
    int min;
    int minindex;
    for(scan = 0; scan<size-1; scan++){
        min = array[scan];
        minindex = scan;
        for(int i= scan+1; i<size; i++ ){
            if(array[i] < min){
                min = array[i];
                minindex = i;
            }
        }
        array[minindex] = array[scan];
        array[scan] = min;
    }
}


//merges an array
void merges(int A[], int left[], int right[],int nL, int nR){

    int i=0;
    int k=0;
    int j=0;
    //loop through the array
    while(i< nL && j < nR){
        if(left[i] <= right[j]){
            A[k] = left[i];
            i++;
        }

        else{
            A[k] = right[j];
            j++;
        }
        k++;
    }


    while(i < nL){
        A[k] = left[i];
        i++;
        k++;
    }

    while(j < nR){
        A[k] = right[j];
        j++;
        k++;
    }
}

// sorts and merges an array.
void mergesort(int A[], int n){
    if (n<2){
        return;
    }
    int mid = n/2;
    int left[mid];
    for(int i=0; i<mid; i++){
        left[i]=A[i];
    }
    int right[n-mid];
    for(int j=mid; j<n; j++){
        right[j-mid] = A[j];

    }

    selectionsort(left, mid);
    selectionsort(right, n-mid);
    merges(A, left, right, mid, n-mid);

}

// prints an array
void print(int A[], int size){
    for(int i=0; i<size; i++){
        cout << A[i]<< endl;
    }
}
---------------------------------------------------------------
//Mergesort.h
#ifndef MERGESORT_MERGESORT_H
#define MERGESORT_MERGESORT_H


void selectionsort(int array[], int size);
void merges(int A[], int left[], int right[],int nL, int nR);
void mergesort(int A[], int n);
void print(int A[], int size);


#endif //MERGESORT_MERGESORT_H

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote