SlideShare a Scribd company logo
1 of 6
Download to read offline
Make all of your classes work correctly with sortingData.cpp. Note that sortingData.cpp creates a
mixture of both Circles and Participants; this means that your compare methods cannot assume
they can always simply downcast Sortable pointers to their own type. You will have to use
dynamic_casts and/or the typeid function to check what kind of object the compare method
receives and act accordingly.
When comparing two objects of the same type, use the same logic as in lab 8. But when asked to
compare a Circle with a Participant or vice-versa, by definition we will consider a Circle <
Participant, so that, after sorting, all Circles should show up in the Data vector before all of the
Participants. (See the expected output below.) Modify Circle.h and Participant.h classes. All 5
files are provided, you only need to modify Circle.h and Participant.h and make sure they work
correctly with sortingData.cpp.
sortingData.cpp:
#include
#include
#include "Data.h"
#include "Circle.h"
#include "Participant.h"
using namespace std;
int main( int argc, const char* argv[] )
{
Data myData;
myData.add( new Participant( "Waymond", 24, 100 ) );
myData.add( new Circle() );
myData.add( new Participant( "Mary", 27, 96 ) );
myData.add( new Circle( 3 ) );
myData.add( new Participant( "John", 32, 100 ) );
myData.add( new Circle( 2 ) );
myData.add( new Participant( "Eliza", 21, 105 ) );
myData.add( new Circle( 4 ) );
myData.add( new Participant( "Ezekiel", 27, 96 ) );
myData.add( new Circle( 1 ) );
myData.add( new Participant( "Alex", 20, 101 ) );
myData.print();
myData.sort();
myData.print();
return 0;
}
Data.h:
#ifndef DATA_H
#define DATA_H
#include
#include
#include
class Data {
private:
std::vector dataset;
public:
void add(int number);
void sort();
void print();
};
void Data::add(int number) {
dataset.push_back(number);
}
void Data::sort() {
std::sort(dataset.begin(), dataset.end());
}
void Data::print() {
for (auto element : dataset) {
std::cout << element << " ";
}
std::cout << std::endl;
}
#endif /* DATA_H */
Circle.h:
#ifndef CIRCLE_H
#define CIRCLE_H
#include "Sortable.h"
class Circle : public Sortable {
private:
float radius;
public:
Circle();
Circle(float r);
bool compare(const Sortable* other) override;
void print() override;
};
Circle::Circle() : radius(0.0f) {}
Circle::Circle(float r) : radius(r) {}
bool Circle::compare(const Sortable* other) {
const Circle* circle = dynamic_cast(other);
if (circle) {
return radius < circle->radius;
}
return false;
}
void Circle::print() {
std::cout << "Circle with radius: " << radius << std::endl;
}
#endif /* CIRCLE_H */
Participant.h:
#ifndef PARTICIPANT_H
#define PARTICIPANT_H
#include
#include "Sortable.h"
class Participant : public Sortable {
private:
std::string name;
int age;
double score;
public:
Participant(std::string name, int age, double score);
bool compare(const Sortable* obj) override;
void print() override;
};
Participant::Participant(std::string name, int age, double score) {
this->name = name;
this->age = age;
this->score = score;
}
bool Participant::compare(const Sortable* obj) {
const Participant* otherParticipant = dynamic_cast(obj);
if (this->score != otherParticipant->score) {
return this->score > otherParticipant->score;
}
else if (this->age != otherParticipant->age) {
return this->age < otherParticipant->age;
}
else {
return this->name < otherParticipant->name;
}
}
void Participant::print() {
std::cout << this->name << "t" << this->age << "t" << this->score << std::endl;
}
#endif /* PARTICIPANT_H */
Sortable.h:
#ifndef SORTABLE_H
#define SORTABLE_H
class Sortable {
public:
virtual bool compare( const Sortable* ) = 0;
virtual void print() = 0;
};
#endif
sortingData.cpp EXPECTED OUTPUT
Waymond 24 100
Circle with radius: 0
Mary 27 96
Circle with radius: 3
John 32 100
Circle with radius: 2
Eliza 21 105
Circle with radius: 4
Ezekiel 27 96
Circle with radius: 1
Alex 20 101
Circle with radius: 0
Circle with radius: 1
Circle with radius: 2
Circle with radius: 3
Circle with radius: 4
Eliza 21 105
Alex 20 101
Waymond 24 100
John 32 100
Ezekiel 27 96
Mary 27 96

More Related Content

Similar to Make all of your classes work correctly with sortingData.cpp. Note t.pdf

I want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdfI want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdfbermanbeancolungak45
 
K is for Kotlin
K is for KotlinK is for Kotlin
K is for KotlinTechMagic
 
C++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdfC++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdfaashisha5
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of cTushar B Kute
 
Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfadmin463580
 
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...Bruce McPherson
 
Using CUDA Within Mathematica
Using CUDA Within MathematicaUsing CUDA Within Mathematica
Using CUDA Within Mathematicakrasul
 
Using Cuda Within Mathematica
Using Cuda Within MathematicaUsing Cuda Within Mathematica
Using Cuda Within MathematicaShoaib Burq
 
Cocoaheads Meetup / Alex Zimin / Swift magic
Cocoaheads Meetup / Alex Zimin / Swift magicCocoaheads Meetup / Alex Zimin / Swift magic
Cocoaheads Meetup / Alex Zimin / Swift magicBadoo Development
 
Александр Зимин (Alexander Zimin) — Магия Swift
Александр Зимин (Alexander Zimin) — Магия SwiftАлександр Зимин (Alexander Zimin) — Магия Swift
Александр Зимин (Alexander Zimin) — Магия SwiftCocoaHeads
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfinfo114
 
this is the concept in C++ under object oriented programming language "POLYMO...
this is the concept in C++ under object oriented programming language "POLYMO...this is the concept in C++ under object oriented programming language "POLYMO...
this is the concept in C++ under object oriented programming language "POLYMO...sj9399037128
 
For this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docxFor this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docxmckellarhastings
 
(Rational Class) - use the original files to create the new progra.pdf
(Rational Class) - use the original files to create the new progra.pdf(Rational Class) - use the original files to create the new progra.pdf
(Rational Class) - use the original files to create the new progra.pdfalstradecentreerode
 
PPT on Data Science Using Python
PPT on Data Science Using PythonPPT on Data Science Using Python
PPT on Data Science Using PythonNishantKumar1179
 
Im having trouble figuring out how to code these sections for an a.pdf
Im having trouble figuring out how to code these sections for an a.pdfIm having trouble figuring out how to code these sections for an a.pdf
Im having trouble figuring out how to code these sections for an a.pdfrishteygallery
 

Similar to Make all of your classes work correctly with sortingData.cpp. Note t.pdf (20)

I want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdfI want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdf
 
K is for Kotlin
K is for KotlinK is for Kotlin
K is for Kotlin
 
The STL
The STLThe STL
The STL
 
C++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdfC++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdf
 
02.adt
02.adt02.adt
02.adt
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
 
Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdf
 
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
 
Using CUDA Within Mathematica
Using CUDA Within MathematicaUsing CUDA Within Mathematica
Using CUDA Within Mathematica
 
Using Cuda Within Mathematica
Using Cuda Within MathematicaUsing Cuda Within Mathematica
Using Cuda Within Mathematica
 
Cocoaheads Meetup / Alex Zimin / Swift magic
Cocoaheads Meetup / Alex Zimin / Swift magicCocoaheads Meetup / Alex Zimin / Swift magic
Cocoaheads Meetup / Alex Zimin / Swift magic
 
Александр Зимин (Alexander Zimin) — Магия Swift
Александр Зимин (Alexander Zimin) — Магия SwiftАлександр Зимин (Alexander Zimin) — Магия Swift
Александр Зимин (Alexander Zimin) — Магия Swift
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
 
this is the concept in C++ under object oriented programming language "POLYMO...
this is the concept in C++ under object oriented programming language "POLYMO...this is the concept in C++ under object oriented programming language "POLYMO...
this is the concept in C++ under object oriented programming language "POLYMO...
 
For this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docxFor this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docx
 
(Rational Class) - use the original files to create the new progra.pdf
(Rational Class) - use the original files to create the new progra.pdf(Rational Class) - use the original files to create the new progra.pdf
(Rational Class) - use the original files to create the new progra.pdf
 
PPT on Data Science Using Python
PPT on Data Science Using PythonPPT on Data Science Using Python
PPT on Data Science Using Python
 
oop objects_classes
oop objects_classesoop objects_classes
oop objects_classes
 
Im having trouble figuring out how to code these sections for an a.pdf
Im having trouble figuring out how to code these sections for an a.pdfIm having trouble figuring out how to code these sections for an a.pdf
Im having trouble figuring out how to code these sections for an a.pdf
 
Big Data Analytics Part2
Big Data Analytics Part2Big Data Analytics Part2
Big Data Analytics Part2
 

More from pratikradia365

M.B. is a 65-year-old male who is being admitted from the emergency .pdf
M.B. is a 65-year-old male who is being admitted from the emergency .pdfM.B. is a 65-year-old male who is being admitted from the emergency .pdf
M.B. is a 65-year-old male who is being admitted from the emergency .pdfpratikradia365
 
L�neas de cruceros Carnival Aunque los viajes por mar han tenido.pdf
L�neas de cruceros Carnival Aunque los viajes por mar han tenido.pdfL�neas de cruceros Carnival Aunque los viajes por mar han tenido.pdf
L�neas de cruceros Carnival Aunque los viajes por mar han tenido.pdfpratikradia365
 
Los virus que infectan a los eucariotas tambi�n han evolucionado con.pdf
Los virus que infectan a los eucariotas tambi�n han evolucionado con.pdfLos virus que infectan a los eucariotas tambi�n han evolucionado con.pdf
Los virus que infectan a los eucariotas tambi�n han evolucionado con.pdfpratikradia365
 
Los t�cnicos m�dicos de emergencia (EMT, por sus siglas en ingl�s) n.pdf
Los t�cnicos m�dicos de emergencia (EMT, por sus siglas en ingl�s) n.pdfLos t�cnicos m�dicos de emergencia (EMT, por sus siglas en ingl�s) n.pdf
Los t�cnicos m�dicos de emergencia (EMT, por sus siglas en ingl�s) n.pdfpratikradia365
 
Los sistemas de control pueden hacer que las personas Pregunta 13 .pdf
Los sistemas de control pueden hacer que las personas Pregunta 13 .pdfLos sistemas de control pueden hacer que las personas Pregunta 13 .pdf
Los sistemas de control pueden hacer que las personas Pregunta 13 .pdfpratikradia365
 
Los tres tipos principales de pron�sticos utilizados por las organiz.pdf
Los tres tipos principales de pron�sticos utilizados por las organiz.pdfLos tres tipos principales de pron�sticos utilizados por las organiz.pdf
Los tres tipos principales de pron�sticos utilizados por las organiz.pdfpratikradia365
 
Los trabajadores 1,..., n est�n actualmente inactivos. Supongamos qu.pdf
Los trabajadores 1,..., n est�n actualmente inactivos. Supongamos qu.pdfLos trabajadores 1,..., n est�n actualmente inactivos. Supongamos qu.pdf
Los trabajadores 1,..., n est�n actualmente inactivos. Supongamos qu.pdfpratikradia365
 
Los tipos de sangre humana se heredan en un patr�n co-dominante. Hay.pdf
Los tipos de sangre humana se heredan en un patr�n co-dominante. Hay.pdfLos tipos de sangre humana se heredan en un patr�n co-dominante. Hay.pdf
Los tipos de sangre humana se heredan en un patr�n co-dominante. Hay.pdfpratikradia365
 
Los valores m�s grandes de tienen la desventaja de aumentar la proba.pdf
Los valores m�s grandes de tienen la desventaja de aumentar la proba.pdfLos valores m�s grandes de tienen la desventaja de aumentar la proba.pdf
Los valores m�s grandes de tienen la desventaja de aumentar la proba.pdfpratikradia365
 
Los siguientes son motivos razonables para las fusiones I) evitar.pdf
Los siguientes son motivos razonables para las fusiones I) evitar.pdfLos siguientes son motivos razonables para las fusiones I) evitar.pdf
Los siguientes son motivos razonables para las fusiones I) evitar.pdfpratikradia365
 
Los proveedores de atenci�n m�dica son responsables de documentar y .pdf
Los proveedores de atenci�n m�dica son responsables de documentar y .pdfLos proveedores de atenci�n m�dica son responsables de documentar y .pdf
Los proveedores de atenci�n m�dica son responsables de documentar y .pdfpratikradia365
 
mauriland is a fictitious country with only two politically active g.pdf
mauriland is a fictitious country with only two politically active g.pdfmauriland is a fictitious country with only two politically active g.pdf
mauriland is a fictitious country with only two politically active g.pdfpratikradia365
 
Los puntos principales, subpuntos y subsubpuntos deben escribirse en.pdf
Los puntos principales, subpuntos y subsubpuntos deben escribirse en.pdfLos puntos principales, subpuntos y subsubpuntos deben escribirse en.pdf
Los puntos principales, subpuntos y subsubpuntos deben escribirse en.pdfpratikradia365
 
Mathew siempre llega tarde a la oficina. Al gerente de Mathew no le .pdf
Mathew siempre llega tarde a la oficina. Al gerente de Mathew no le .pdfMathew siempre llega tarde a la oficina. Al gerente de Mathew no le .pdf
Mathew siempre llega tarde a la oficina. Al gerente de Mathew no le .pdfpratikradia365
 
Los riesgos que pueden resultar en que un sistema o proceso no fun.pdf
Los riesgos que pueden resultar en que un sistema o proceso no fun.pdfLos riesgos que pueden resultar en que un sistema o proceso no fun.pdf
Los riesgos que pueden resultar en que un sistema o proceso no fun.pdfpratikradia365
 
Match up the following The chance of a type 2 error is reduced.pdf
Match up the following The chance of a type 2 error is reduced.pdfMatch up the following The chance of a type 2 error is reduced.pdf
Match up the following The chance of a type 2 error is reduced.pdfpratikradia365
 
Match the Late Paleozoic time period with the appropriate life. You.pdf
Match the Late Paleozoic time period with the appropriate life.  You.pdfMatch the Late Paleozoic time period with the appropriate life.  You.pdf
Match the Late Paleozoic time period with the appropriate life. You.pdfpratikradia365
 
Match the following proteins with the best description of their func.pdf
Match the following proteins with the best description of their func.pdfMatch the following proteins with the best description of their func.pdf
Match the following proteins with the best description of their func.pdfpratikradia365
 
Materia Comunicaci�n empresarialGui�n Esta es la historia de Ch.pdf
Materia Comunicaci�n empresarialGui�n Esta es la historia de Ch.pdfMateria Comunicaci�n empresarialGui�n Esta es la historia de Ch.pdf
Materia Comunicaci�n empresarialGui�n Esta es la historia de Ch.pdfpratikradia365
 
Match the STRIDE threat with its description. Match the STRIDE threa.pdf
Match the STRIDE threat with its description. Match the STRIDE threa.pdfMatch the STRIDE threat with its description. Match the STRIDE threa.pdf
Match the STRIDE threat with its description. Match the STRIDE threa.pdfpratikradia365
 

More from pratikradia365 (20)

M.B. is a 65-year-old male who is being admitted from the emergency .pdf
M.B. is a 65-year-old male who is being admitted from the emergency .pdfM.B. is a 65-year-old male who is being admitted from the emergency .pdf
M.B. is a 65-year-old male who is being admitted from the emergency .pdf
 
L�neas de cruceros Carnival Aunque los viajes por mar han tenido.pdf
L�neas de cruceros Carnival Aunque los viajes por mar han tenido.pdfL�neas de cruceros Carnival Aunque los viajes por mar han tenido.pdf
L�neas de cruceros Carnival Aunque los viajes por mar han tenido.pdf
 
Los virus que infectan a los eucariotas tambi�n han evolucionado con.pdf
Los virus que infectan a los eucariotas tambi�n han evolucionado con.pdfLos virus que infectan a los eucariotas tambi�n han evolucionado con.pdf
Los virus que infectan a los eucariotas tambi�n han evolucionado con.pdf
 
Los t�cnicos m�dicos de emergencia (EMT, por sus siglas en ingl�s) n.pdf
Los t�cnicos m�dicos de emergencia (EMT, por sus siglas en ingl�s) n.pdfLos t�cnicos m�dicos de emergencia (EMT, por sus siglas en ingl�s) n.pdf
Los t�cnicos m�dicos de emergencia (EMT, por sus siglas en ingl�s) n.pdf
 
Los sistemas de control pueden hacer que las personas Pregunta 13 .pdf
Los sistemas de control pueden hacer que las personas Pregunta 13 .pdfLos sistemas de control pueden hacer que las personas Pregunta 13 .pdf
Los sistemas de control pueden hacer que las personas Pregunta 13 .pdf
 
Los tres tipos principales de pron�sticos utilizados por las organiz.pdf
Los tres tipos principales de pron�sticos utilizados por las organiz.pdfLos tres tipos principales de pron�sticos utilizados por las organiz.pdf
Los tres tipos principales de pron�sticos utilizados por las organiz.pdf
 
Los trabajadores 1,..., n est�n actualmente inactivos. Supongamos qu.pdf
Los trabajadores 1,..., n est�n actualmente inactivos. Supongamos qu.pdfLos trabajadores 1,..., n est�n actualmente inactivos. Supongamos qu.pdf
Los trabajadores 1,..., n est�n actualmente inactivos. Supongamos qu.pdf
 
Los tipos de sangre humana se heredan en un patr�n co-dominante. Hay.pdf
Los tipos de sangre humana se heredan en un patr�n co-dominante. Hay.pdfLos tipos de sangre humana se heredan en un patr�n co-dominante. Hay.pdf
Los tipos de sangre humana se heredan en un patr�n co-dominante. Hay.pdf
 
Los valores m�s grandes de tienen la desventaja de aumentar la proba.pdf
Los valores m�s grandes de tienen la desventaja de aumentar la proba.pdfLos valores m�s grandes de tienen la desventaja de aumentar la proba.pdf
Los valores m�s grandes de tienen la desventaja de aumentar la proba.pdf
 
Los siguientes son motivos razonables para las fusiones I) evitar.pdf
Los siguientes son motivos razonables para las fusiones I) evitar.pdfLos siguientes son motivos razonables para las fusiones I) evitar.pdf
Los siguientes son motivos razonables para las fusiones I) evitar.pdf
 
Los proveedores de atenci�n m�dica son responsables de documentar y .pdf
Los proveedores de atenci�n m�dica son responsables de documentar y .pdfLos proveedores de atenci�n m�dica son responsables de documentar y .pdf
Los proveedores de atenci�n m�dica son responsables de documentar y .pdf
 
mauriland is a fictitious country with only two politically active g.pdf
mauriland is a fictitious country with only two politically active g.pdfmauriland is a fictitious country with only two politically active g.pdf
mauriland is a fictitious country with only two politically active g.pdf
 
Los puntos principales, subpuntos y subsubpuntos deben escribirse en.pdf
Los puntos principales, subpuntos y subsubpuntos deben escribirse en.pdfLos puntos principales, subpuntos y subsubpuntos deben escribirse en.pdf
Los puntos principales, subpuntos y subsubpuntos deben escribirse en.pdf
 
Mathew siempre llega tarde a la oficina. Al gerente de Mathew no le .pdf
Mathew siempre llega tarde a la oficina. Al gerente de Mathew no le .pdfMathew siempre llega tarde a la oficina. Al gerente de Mathew no le .pdf
Mathew siempre llega tarde a la oficina. Al gerente de Mathew no le .pdf
 
Los riesgos que pueden resultar en que un sistema o proceso no fun.pdf
Los riesgos que pueden resultar en que un sistema o proceso no fun.pdfLos riesgos que pueden resultar en que un sistema o proceso no fun.pdf
Los riesgos que pueden resultar en que un sistema o proceso no fun.pdf
 
Match up the following The chance of a type 2 error is reduced.pdf
Match up the following The chance of a type 2 error is reduced.pdfMatch up the following The chance of a type 2 error is reduced.pdf
Match up the following The chance of a type 2 error is reduced.pdf
 
Match the Late Paleozoic time period with the appropriate life. You.pdf
Match the Late Paleozoic time period with the appropriate life.  You.pdfMatch the Late Paleozoic time period with the appropriate life.  You.pdf
Match the Late Paleozoic time period with the appropriate life. You.pdf
 
Match the following proteins with the best description of their func.pdf
Match the following proteins with the best description of their func.pdfMatch the following proteins with the best description of their func.pdf
Match the following proteins with the best description of their func.pdf
 
Materia Comunicaci�n empresarialGui�n Esta es la historia de Ch.pdf
Materia Comunicaci�n empresarialGui�n Esta es la historia de Ch.pdfMateria Comunicaci�n empresarialGui�n Esta es la historia de Ch.pdf
Materia Comunicaci�n empresarialGui�n Esta es la historia de Ch.pdf
 
Match the STRIDE threat with its description. Match the STRIDE threa.pdf
Match the STRIDE threat with its description. Match the STRIDE threa.pdfMatch the STRIDE threat with its description. Match the STRIDE threa.pdf
Match the STRIDE threat with its description. Match the STRIDE threa.pdf
 

Recently uploaded

ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 

Recently uploaded (20)

Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 

Make all of your classes work correctly with sortingData.cpp. Note t.pdf

  • 1. Make all of your classes work correctly with sortingData.cpp. Note that sortingData.cpp creates a mixture of both Circles and Participants; this means that your compare methods cannot assume they can always simply downcast Sortable pointers to their own type. You will have to use dynamic_casts and/or the typeid function to check what kind of object the compare method receives and act accordingly. When comparing two objects of the same type, use the same logic as in lab 8. But when asked to compare a Circle with a Participant or vice-versa, by definition we will consider a Circle < Participant, so that, after sorting, all Circles should show up in the Data vector before all of the Participants. (See the expected output below.) Modify Circle.h and Participant.h classes. All 5 files are provided, you only need to modify Circle.h and Participant.h and make sure they work correctly with sortingData.cpp. sortingData.cpp: #include #include #include "Data.h" #include "Circle.h" #include "Participant.h" using namespace std; int main( int argc, const char* argv[] ) { Data myData; myData.add( new Participant( "Waymond", 24, 100 ) ); myData.add( new Circle() ); myData.add( new Participant( "Mary", 27, 96 ) ); myData.add( new Circle( 3 ) ); myData.add( new Participant( "John", 32, 100 ) ); myData.add( new Circle( 2 ) ); myData.add( new Participant( "Eliza", 21, 105 ) ); myData.add( new Circle( 4 ) ); myData.add( new Participant( "Ezekiel", 27, 96 ) );
  • 2. myData.add( new Circle( 1 ) ); myData.add( new Participant( "Alex", 20, 101 ) ); myData.print(); myData.sort(); myData.print(); return 0; } Data.h: #ifndef DATA_H #define DATA_H #include #include #include class Data { private: std::vector dataset; public: void add(int number); void sort(); void print(); }; void Data::add(int number) { dataset.push_back(number); } void Data::sort() { std::sort(dataset.begin(), dataset.end()); }
  • 3. void Data::print() { for (auto element : dataset) { std::cout << element << " "; } std::cout << std::endl; } #endif /* DATA_H */ Circle.h: #ifndef CIRCLE_H #define CIRCLE_H #include "Sortable.h" class Circle : public Sortable { private: float radius; public: Circle(); Circle(float r); bool compare(const Sortable* other) override; void print() override; }; Circle::Circle() : radius(0.0f) {} Circle::Circle(float r) : radius(r) {} bool Circle::compare(const Sortable* other) { const Circle* circle = dynamic_cast(other); if (circle) { return radius < circle->radius; } return false; } void Circle::print() { std::cout << "Circle with radius: " << radius << std::endl;
  • 4. } #endif /* CIRCLE_H */ Participant.h: #ifndef PARTICIPANT_H #define PARTICIPANT_H #include #include "Sortable.h" class Participant : public Sortable { private: std::string name; int age; double score; public: Participant(std::string name, int age, double score); bool compare(const Sortable* obj) override; void print() override; }; Participant::Participant(std::string name, int age, double score) { this->name = name; this->age = age; this->score = score; } bool Participant::compare(const Sortable* obj) { const Participant* otherParticipant = dynamic_cast(obj); if (this->score != otherParticipant->score) { return this->score > otherParticipant->score; } else if (this->age != otherParticipant->age) { return this->age < otherParticipant->age; } else {
  • 5. return this->name < otherParticipant->name; } } void Participant::print() { std::cout << this->name << "t" << this->age << "t" << this->score << std::endl; } #endif /* PARTICIPANT_H */ Sortable.h: #ifndef SORTABLE_H #define SORTABLE_H class Sortable { public: virtual bool compare( const Sortable* ) = 0; virtual void print() = 0; }; #endif sortingData.cpp EXPECTED OUTPUT Waymond 24 100 Circle with radius: 0 Mary 27 96 Circle with radius: 3 John 32 100 Circle with radius: 2 Eliza 21 105 Circle with radius: 4 Ezekiel 27 96 Circle with radius: 1 Alex 20 101 Circle with radius: 0 Circle with radius: 1 Circle with radius: 2
  • 6. Circle with radius: 3 Circle with radius: 4 Eliza 21 105 Alex 20 101 Waymond 24 100 John 32 100 Ezekiel 27 96 Mary 27 96