Lab 8

This week in lab we will be dealing with structure of structs. We've given you some sample code which uses some struct objects, and we'd like you to implement sorting algorithms over them. The "functions" you should implement for this lab are:

1. Print out the database

2. Sort the data by a given criterion

3. Find a particular item from the database

Note that you need not actually use methods or functions to implement this functionality.

In the code you're given the declaration for an array of structs, as well as the instantiation of elements of that array. Also, you are given the structure of the code, which prints out the database, calls a sort function on the data, and then searches through the data for a particular value.

 

A sample run of the program will look like the following. (User input is shown in bold, though in your program it will not be bold.)

For one point:

Data:

Adams, Suma 768454006 37.000000

Alex, Cris 680378908 5.000000

Alvino, Jason 721777193 69.000000

Amrhein, Maria 798094980 1.000000

... // I'm not going to list all 75 lines here.

Vinot, Hill 684654477 73.000000

Warner, Jill 658026216 61.000000

Williams, Michael 785019931 78.000000

For two points:

Which field would you like to sort by?

1. First Name

2. Last Name

3. UIN

4. Grade

3

Sowles, Charles 650993131 83.000000

Villalobos, Patricia 651055147 7.000000

Kinney, Brian 653179869 52.000000

Nash, Christopher 653856107 27.000000

... // Again, I don't think you need all this data in a lab prompt.

Verhoeven, Andrew 791215097 75.000000

Goehring, Brian 794717105 78.000000

Amrhein, Maria 798094980 1.000000

And for extra credit:

if user choice was 2

Which last name would you like to look up? Siebert

At index 64

Siebert, Sabrina 706562581 7.000000

if user choice was 3

Which UIN would you like to look up? 709418024

At index 28

Minielly, Gary 709418024 23.000000

if user choice was 4

Which grade would you like to look up? 57

At index 47

Flagg, Megan 756141672 57.000000

and an example where the object could not be found (happens to be sorted by first name (user choice 1))

Which first name would you like to look up? Sean

No Student was found with the first name Sean.

Use only structs from C, the syntax is different for C++ (largely how you treat it as a type). This means you will have to use typedef notation when defining your struct to make it work with the sample code. You may use any of the library functions for C string operations. Wherever possible, you should use the builtin and library C functions instead of looping through the characters yourself.