Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions 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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education