// CSIS 2610L: Final Exam Lab
// DUE: Friday, May 1st 2026, 11:59pm

// ===== L2: The Hall of Presidents (70 pts.) =====
// NOTE:
// Do your best! I will score on the basis of whatever objectives you have WORKING.

// In the file "presidents.csv", you will find comma-separated values for
// the number, name, and political party of all of the U.S. Presidents.
// This file includes column headers on the first line, discard it when reading input.
// HINT: don't overcomplicate throwing the values out, you can getline() before the loop.
// The President struct is defined to hold those 3 attributes.

// Objectives:
// 1. Read the file for input.  Do NOT alter the file.  I will test your code with an
//    identical copy.  You will need to convert the line to individual struct
//    variables (like you did in Hangman).  Store the values in the presidents array. (20pts.)

// 2. Print out a table showing the names of each of the parties and the number of
//    members.  You should arrive at this count by iterating through the
//    presidents array.  Hint: you will need to use the parties array. (20pts.)

// 3. Print out the presidents in sorted (dictionary) order.  You should use the
//    string comparison method in Chapter 10 from the book to determine if a string
//    is less than or greater than another string, e.g., "Bush" comes before "Carter"
//    because 'B'<'C'.  DO NOT use a sorting library call, e.g., sort() from <algorithm>
//    to accomplish this.  I want to see that you understand basic sorting as presented in 
//    lecture (bubble sort, selection sort) and have internalized the concept. (30 pts.)

// BONUS:
// B1. (+5) Implement this program using a dynamic linked list instead of arrays with next pointers.
// B2. (+5) Implement this program using a dynamic linked list with OOP class objects.

// Use the Hogwarts examples for inspiration when you are stuck.  Don't just copy-paste.
// Understand the snippets of useful code and cherrypick the relevant features.

// HINT: Note that in the Hogwarts example, using a presorted file results in all the house members 
// being sorted as well.  Unfortunately, in this case, it is sorted in a completely different 
// (chronological) order...so be careful sorting with pointers.

// If you choose to submit bonus items, submit attachments separately as username_final_Bn.cpp,
// where n is the corresponding number of the bonus item attempted.

// You may find the "pointer swapping" and "string tokenization" example code 
// *extremely* helpful...particularly regarding the way I reference pointers.
// REMINDER: other examples can be found at: 
// http://jwdittrich.people.ysu.edu/CSIS_2610/

// ===== BEGIN stub code ===== 

#include <iostream> // basic i/o
#include <cstdlib>	//string to numeric conversion
#include <string>
// TODO: insert the appropriate library includes for what 
// functions that you need (and actually use).
using namespace std;

#define MAXNUMPRES 47

struct President{
	int number;		 // the number order of succession. 
	string fullname; // the president's full name (first and last/surname).
	string lastname; // should be empty until you extract only the last name.
	string party;	 // their political party affiliation.
};


struct Party{
	int numMembers = 0; // the number of members, should get initialized to zero when created.
	string name;		// e.g., "Whig"
};


string getLastName(string fullname){
	string lastname;

	// TODO: function to extract and return just the last name.
	// Hint -- you can use the cctype booleans at the beginning of chapter 10
	// to help probe for word boundaries (whitespace).

	return lastname;
}


int main(){
	President presidents[MAXNUMPRES]; // an array to hold Presidents...currently [45]
	string partyNames[] = { 
		"Democratic",
		"Democratic-Republican",
		"Federalist",
		"National Union",
		"Republican",
		"Unaffiliated",
		"Whig"
	};
	Party parties[10]; // an array to hold Parties

	// TODO: Objective 1
	//   Read the file for input.  You will need to convert the line to
	//   individual struct variables.  Store the values in the presidents array.

	// TODO: Objective 2
	//   Print out a table (use a combination of tabs and/or '|') showing the names 
	//   of each of the parties and the number of members.
	//   You should arrive at this count by iterating through the
	//   presidents array and not counting by hand.  Hint: you will need to use 
	//   and iterate through the parties array, incrementing parties[index].number

	// TODO: Objective 3
	// Print out the presidents in sorted (dictionary) order, by last name (surname).
	// You will want to call the getLastName() function in order to set each president's last name.
	// Please note, "Van Buren" is Martin Van Buren's last name, so be ready to handle that!
	// Treat it as "Van Buren" and not "Buren" in alphabetical order.
	// You may have to take extra care in the getLastName function.
	// Also note that "Adams" == "Adams" and "Bush" == "Bush", it's not a misprint!  There are two!

	for(int i=0;i<MAXNUMPRES;i++){
		// set the current president's last name
		presidents[i].lastname = getLastName(presidents[i].fullname);
	}
	// SORT (by last name)!

	return 0;
}

