Data Structures and Algorithms in C/C++ In this assignment, you will be using quicksort to sort an array of car objects by various criteria Define a struct Car as follow: #define MAX_STRING_LENGTH  typedef struct Car_ {  char make[MAX_STRING_LENGTH];  char model[MAX_STRING_LENGTH];  int mpg; /* Miles per gallon */ } Car;    Implement a function called compareCarsByMakeThenModel that can be passed as an argument to the compare parameter of the qksort function from the book. compareCarsByMakeThenModel should return a value that will cause qksort to sort an array of cars in ascending order (from smallest to largest) by make and, when two cars have the same make, in ascending order by model.  Implement a function called compareCarsByDescendingMPG that can be passed as an argument to the compare parameter of the qksort function from the book. compareCarsByDescendingMPG should return a value that will cause qksort to sort an array of cars in descending order (from largest to smallest) by mpg.  Implement a function called compareCarsByMakeThenDescendingMPG that can be passed as an argument to the compare parameter of the qksort function from the book. compareCarsByMakeThenDescendingMPG should return a value that will cause qksort to sort an array of cars in ascending order by make and, when two cars have the same make, in descending order by mpg.  Write a program that tests your functions from parts a-c with the following array of cars:            Car cars[] = {  { "Toyota", "Camry", 33 },  { "Ford", "Focus", 40 },  { "Honda", "Accord", 34 },  { "Ford", "Mustang", 31 }, { "Honda", "Civic", 39 }, { "Toyota", "Prius", 48 },  { "Honda", "Fit", 35 },  { "Toyota", "Corolla", 35 },  { "Ford", "Taurus", 28 }  };    The test program should do the following:  Output (displaying make, model, and MPG) the cars in original unsorted order.  2. Output the cars sorted (using qksort from the book) by make then model.  3. Output the cars sorted (using qksort from the book) by descending MPG. 4. Output the cars sorted (using qksort from the book) by make then descending MPG.    e) Make sure source code is well-commented, consistently formatted, uses no magic numbers/values, follows programming best-practices, and is ANSI-compliant.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Data Structures and Algorithms in C/C++

In this assignment, you will be using quicksort to sort an array of car objects by various criteria

Define a struct Car as follow:

#define MAX_STRING_LENGTH 

typedef struct Car_ { 

char make[MAX_STRING_LENGTH]; 

char model[MAX_STRING_LENGTH]; 

int mpg; /* Miles per gallon */ } Car; 

 

  1. Implement a function called compareCarsByMakeThenModel that can be passed as an argument to the compare parameter of the qksort function from the book. compareCarsByMakeThenModel should return a value that will cause qksort to sort an array of cars in ascending order (from smallest to largest) by make and, when two cars have the same make, in ascending order by model. 
  2. Implement a function called compareCarsByDescendingMPG that can be passed as an argument to the compare parameter of the qksort function from the book. compareCarsByDescendingMPG should return a value that will cause qksort to sort an array of cars in descending order (from largest to smallest) by mpg. 
  3. Implement a function called compareCarsByMakeThenDescendingMPG that can be passed as an argument to the compare parameter of the qksort function from the book. compareCarsByMakeThenDescendingMPG should return a value that will cause qksort to sort an array of cars in ascending order by make and, when two cars have the same make, in descending order by mpg. 
  4. Write a program that tests your functions from parts a-c with the following array of cars: 

          Car cars[] = { 

{ "Toyota", "Camry", 33 }, 

{ "Ford", "Focus", 40 }, 

{ "Honda", "Accord", 34 }, 

{ "Ford", "Mustang", 31 },

{ "Honda", "Civic", 39 },

{ "Toyota", "Prius", 48 }, 

{ "Honda", "Fit", 35 }, 

{ "Toyota", "Corolla", 35 }, 

{ "Ford", "Taurus", 28 } 

}; 

 

The test program should do the following: 

  1. Output (displaying make, model, and MPG) the cars in original unsorted order. 
  2. 2. Output the cars sorted (using qksort from the book) by make then model. 
  3. 3. Output the cars sorted (using qksort from the book) by descending MPG.
  4. 4. Output the cars sorted (using qksort from the book) by make then descending MPG. 

 

e) Make sure source code is well-commented, consistently formatted, uses no magic numbers/values, follows programming best-practices, and is ANSI-compliant. 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education