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

Hi, can you check my code mycode.h that how can I make it seperate as .h file an

ID: 3886896 • Letter: H

Question

Hi, can you check my code mycode.h that how can I make it seperate as .h file and .cpp file

SortedArrayList.h

#include <iostream>
#include "ArrayList.h"

template <typename E>
class SortedArrayList: public ArrayList<E>{
public:
   SortedArrayList(int capacity): ArrayList<E>(capacity) {
   }

   bool add(const E& elem){
       if (this->n_+1> this->capacity_){
           std::cout << "adding " << elem << " failed!" << std::endl;
           return false;
       }
  
       int right_place = getRightPlace(elem);
       // shift everything right
       for (int i=this->n_-1; i>=right_place; i--)
           this->listArray_[i+1] = this->listArray_[i];

       this->listArray_[right_place] = elem;
       this->n_++;      

       return true;
   }

   bool fastSearch(const E& elem){
       return binarySearch(elem, 0, this->n_-1);          
   }

   ~SortedArrayList(){
   }

protected:
   int getRightPlace(const E& elem){
       for (int i=0; i<this->n_; i++)
           if (this->listArray_[i]>= elem)
               return i;
       return this->n_;
   }

   bool binarySearch(const E& elem, int start_index, int end_index){
       if (start_index > end_index)
           return false;
       int middle_index = (start_index + end_index)/2;
       if (this->listArray_[middle_index]>elem)
           return binarySearch(elem, start_index, middle_index-1);
       else if (this->listArray_[middle_index]<elem)
           return binarySearch(elem, middle_index+1, end_index);
       else // this->listArray_[middle_index]==elem
           return true;
   }
};

Mycode.h

#include <iostream>
#include <fstream>
using namespace std;

class myFavoriteDataType{

public:
        myFavoriteDataType(){
           name='p';
           capacity=0;
        }
        myFavoriteDataType(string p, int n){
           name=p;
           capacity = n;
        }

        bool operator< (const myFavoriteDataType& rhs) const{
                return (capacity > rhs.capacity);
        }

        bool operator== (const myFavoriteDataType& rhs) const{
                return (capacity == rhs.capacity);
        }

        bool operator> (const myFavoriteDataType& rhs) const{
                return !(((*this) < rhs) || ((*this == rhs)));
        }

        bool operator>= (const myFavoriteDataType& rhs) const{
                return !((*this) < rhs);
        }

        bool operator<= (const myFavoriteDataType& rhs) const{
                return !((*this) > rhs);
        }

        bool operator!= (const myFavoriteDataType& rhs) const{
                return !((*this) == rhs);
        }

        friend ostream &operator<<( ostream &output, const myFavoriteDataType &p ) {
                output << p.name<<", "<<p.capacity<<endl;
                return output;
        }

private:
        string name;
        int capacity;
};

In this lab we will write a class that can be used as a data type in SortedAmayList This data type is a class similar to patient class that we developed in Lecture 4. But it can have any set ot member data. For example, it you are like me, your tavonte data type is something like movie ramer tnan patient. A movie has a name, a year ot production, a legth, a rating, elc.I cari define all these features as menber variables of ryFavoriteDataType. Then he construclor of my class would lake values for these members. The problem is, this class carn't be used in SorledArrayList just like patient class wasn't at first. So, I need to add all the functions and operators that are needed just like what we did in lecture 4) for my class to be consumable by SonedList. That is what we are doing in this lab. What to submit? 1. The header and implementation hie tor the clasS (myFavoriteDataType.h and myFavoriteDataType.cpp) 2. A coristructor parans.ttfie contining exactly 5 set of parneters for the construclor of the class, each at a lie. paraneters iri a line are seperated from each other with as In fact each line i constructor_parais.txt should be exacuy the sarie as what you'd put in parantheses when calling the constructor of your data type. The following is an example of constructor_params.bt for a class whose constructor takes a sting and a number P17 17 P5", 5 P3", 3 P108", 108 P24", 24 It myFavonteDataType is movie, I have name (a string), year ot production (an int), length (an int), and rating (a float) as constnuctor parameters. Then, construchor params.txt could contain something like the tollowing movie1", 200, 120, 3.5 movie2", 2005, 95, 4.9 movie3", 2002, 80, 2.5 movie4", 2017, 100, 4.0 movie5", 1995, 178, 4.8

Explanation / Answer

Notes: I broke you MyFavouriteDataType down to a .h and a .cpp, added appropriate names to files and classes. Your first piece of code though has some file dependencies, so I can't work with that.

MyDataType.h:

#ifndef MYDATATYPE_H_

#define MYDATATYPE_H_

#include <string>

using namespace std;

class MyDataType

{

private:

std::string name;

int capacity;

public:

MyDataType();

MyDataType(string p, int n);

bool operator < (const MyDataType& rhs) const;

bool operator == (const MyDataType& rhs) const;

bool operator > (const MyDataType& rhs) const;

bool operator >= (const MyDataType& rhs) const;

bool operator <= (const MyDataType& rhs) const;

bool operator != (const MyDataType& rhs) const;

friend ostream &operator <<( ostream &output, const MyDataType &p );

~MyDataType();

};

#endif /* MYDATATYPE_H_ */

MyDataType.h:

====

/*

* MyDataType.cpp

*

* Created on: 19-Sep-2017

* Author: ajay

*/

#include "MyDataType.h"

MyDataType::MyDataType()

{

name='p';

capacity=0;

}

MyDataType::MyDataType(string p, int n)

{

name=p;

capacity = n;

}

bool MyDataType::operator < (const MyDataType& rhs) const

{

return (capacity > rhs.capacity);

}

bool MyDataType::operator == (const MyDataType& rhs) const

{

return (capacity == rhs.capacity);

}

bool MyDataType::operator > (const MyDataType& rhs) const{

return !(((*this) < rhs) || ((*this == rhs)));

}

bool MyDataType::operator >= (const MyDataType& rhs) const{

return !((*this) < rhs);

}

bool MyDataType::operator <= (const MyDataType& rhs) const{

return !((*this) > rhs);

}

bool MyDataType::operator != (const MyDataType& rhs) const{

return !((*this) == rhs);

}

ostream &operator <<( ostream &output, const MyDataType &p ) {

//output << p.name<<", "<<p.capacity<<endl;

return output;

}

MyDataType::~MyDataType()

{}

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