CSCI 132 Data Structures--Spring 2014

    Assignment 8

    Due at the beginning of class, Friday, April 25, 2014

    Home | | Syllabus | | Assignments | | Lecture Notes


    Programming Style: You will be graded not only on whether your programs work correctly, but also on programming style, such as the use of informative names, good comments, easily readable formatting, and a good balance between compactness and clarity (e.g. do not define lots of unnecessary variables) Create appropriate functions for tasks that can be encapsulated.


    Problem 1: Choosing the Right Computer Science Graduate Program

    There are many online resources that provide valuable information about rankings of graduate programs in Computer Science, and how to choose programs that best fit an individual student's interests and needs. Conducting a Google search (at http://www.google.com/) on the string

        Computer Science Graduate Program Rankings

    points you to many of these resources. One particularly interesting site allows you to customize the ranking of graduate programs based on your own weighting of various criteria used to judge the quality of these programs. The site was created by Geoff Davis while he was on the faculty at Dartmouth College. The site is located at http://graduate-school.phds.org/rankings/ . If you click on the "Computer Sciences" link on this page you will go to a page of the site that lists a large number of factors that you can assign importance to, on a scale from 0 to 5. After specifying the importance of the various factors, you can click on the <Rank Programs> button and a customized ranking of Computer Science graduate programs will appear.

    In this assignment, you will implement a small version of a program that produces a customized ranking of Computer Science graduate programs. You will make use of the list functions and sortable_list functions (e.g. insertion_sort(), merge_sort(), etc) that we developed in class. You will create a class, GradSchools, that contains a single data member that is a sortable_list of objects from the School class (which you will also implement). The GradSchools class will contain functions that allow you to add schools to the list and to sort schools according to various weights given to different aspects of the school.

    To begin this assignment, copy the files from ~csci132/assignments/assign8 into your own assign8 folder. You will find the following files:

    • gradSchoolsTest.cc
    • list.cc
    • list.h
    • school.cc
    • school.h
    • sortable_list.cc
    • sortable_list.h
    • gradSchools.cc
    • gradSchools.h

    The list and sortable_list files have all the usual list and sorting functions implemented for you. The school.h and gradSchools.h files have the class specifications for the School and GradSchools classes. Your task is to implement the member functions of these classes in the school.cc and gradSchools.cc files (which are empty except for an include statement when you first copy them). The gradSchoolsTest.cc file contains code to test your implementation of the School and GradSchools functions.

    The School class

    The school.h file contains the specification for a new class named School for storing information about a single graduate school program. A set of public data members are already declared in the file:

    string name;     // name of the school
    string state;     // state in which school is located
    int women;     // rating of percentage of women PhD's
    int rateAI;     // rating of AI program
    int rateSys;     // rating of Computer Systems program
    int rateTheory;     // rating of Theory program
    int effectiveness;     // rating of effectiveness in educating research scholars
    int ratePubs;     // rating of number and impact of publications per faculty member
    int overallRating;     // overall rating that considers all of the above factors

    Each of the rating variables above (women, rateAI, rateSys, rateTheory, effectiveness and ratePubs) is assumed to be an integer between 1 and 10.

    The remainder of this specification lists the 4 public member functions that you will implement, as well as the 6 comparison operator overload functions that you will also implement. All of these implementations will go in the school.cc file. The functions are described as follows:

    (1) one constructor method that has no parameters for the School class. This is the default constructor and should initialize the integer data members to zero.

    (2) one constructor method that has 8 parameters corresponding to the first 8 data members for the School class. The final instance variable, overallRating, can be initialized to 0.

    (3) a member function printSchoolInfo() that prints all of the information contained in a single School object. The printout should contain short strings of text that label each data member.

    (4) a member function computeRating() that has 6 inputs that represent weights (an integer between 0 and 5) to be associated with each of the 6 factors used to evaluate graduate programs (women PhD's, rating of AI, Computer Systems and Theory programs, effectiveness, and rating of faculty publications). This method should compute an overall rating for the school's graduate program as shown below, and assign this value to the overallRating data member:

       S (weight * factor)

    i.e. the value is the sum over all factors of each factor times the weight for that factor.

    factor refers to one of the 6 factors being considered, weight is the weight associated with this factor, and the sum is computed over the set of 6 factors.

    (5) Operator overloads: In addition to the member functions of the School class, you must also implement 6 comparison operator overloads to be used by the sorting functions. These overload functions should compare the overallRating data member of the school objects and return an appropriate boolean value depending on how the overallRatings of the two schools compare. This method will be used to sort schools by their overall ratings.

    Note that the members for the School class have been declared public, so they can be accessed directly from other code files -- there is no need to write any public member functions that read or change the values of these instance variables.

    The GradSchools class

    The gradSchools.h file contains the definition of a new class named GradSchools that stores information about multiple School objects that are maintained in a Sortable_list. The single data member is a Sortable_list named schools that is a Sortable_list of School objects. The class definition also lists 6 public member functions that you will implement in the gradSchools.cc file:

    (1) one constructor method that has no parameters. This should clear the schools data member.

    (2) a member function addSchool() that has 8 parameters corresponding to the first 8 instance variables for the School class. This function should create a new instance of the School class and add it to the schools list in the GradSchools object that is used to call the function.

    (3) member function printGradSchools() that prints all of the information that is stored in the entire GradSchools object used to invoke this method. The printSchoolInfo() method defined for the School class will be helpful here.

    (4) a member function computeRatings() that has 6 inputs that represent the weights to be associated with each of the 6 factors that are considered for evaluation of graduate programs. This method should compute the overallRating for each of the School objects stored in the schools array, using the computeRating() method defined for the School class.

    (5) a member function rankSchools() that sorts all of the School objects contained in the schools Sortable_list using the overallRating as the basis for the ranking. This method should also have 6 inputs that represent the weights to be associated with the 6 factors used to compute the overallRating. Before sorting the schools, this method should call the computeRatings() method to recompute the values of overallRating based on the new input weights. This method should call an appropriate sorting function to rearrange the School objects in the schools array so that the School with the lowest overallRating is placed in the first location of the schools list (at position 0) and the School with the highest overallRating is placed at the highest list position. (Do not worry about the ordering of School objects that have the same overallRating.) After completing the sorting task, this method should print the names of the schools, in order from highest to lowest rank. Note that this means you must print the list in reverse order (you might want to write an auxiliary function to do this).

    You should think carefully about which sorting function to use. Take into account the type of list (contiguous), the size of the list, and the trade-offs between efficient functions and ease of use. Write a short paragraph stating which sorting function you chose and explaining why you chose it for this application.

    (6) a member function rankSchoolsFactor() that ranks the schools based on a single factor. This method should have a single string input that specifies which factor to use (e.g. "women", "AI", etc.), and should call the rankSchools() function with the appropriate parameters set to compute the ranking.

    Sample Output

    Once you have implemented the appropriate functions (or at least put the function stubs into the appropriate .cc files) you can compile your program with the following compile command:

      g++ -g -Wall gradSchoolsTest.cc -o gradSchoolsTest

    When you run gradSchoolsTest the output should look as follows (although note that if 2 schools have the same overallRating, they may be in a different order from that shown here, depending on which sorting function you use):

      Ranking of Grad School programs, given your preferences:
      Stanford
      MIT
      Cornell
      CMU
      UC Berkeley
      Univ. of Washington
      Princeton
      Univ. of Illinois
      
      
      Ranking of Grad School programs, given your preferences:
      MIT
      CMU
      Stanford
      Univ. of Illinois
      UC Berkeley
      Cornell
      Univ. of Washington
      Princeton
      
      Ranking of Grad School programs, given your preferences:
      Cornell
      Stanford
      Princeton
      Univ. of Washington
      CMU
      MIT
      UC Berkeley
      Univ. of Illinois
      
      There are 8 schools in the database:
      
      Name: Univ. of Illinois
      State: Illinois
      Rating of number of women PhD's: 4
      Rating of AI program: 7
      Rating of Systems program: 7
      Rating of Theory program: 7
      Effectiveness rating: 7
      Rating of faculty publications: 7
      Overall rating: 4
      
      
      Name: UC Berkeley
      State: California
      Rating of number of women PhD's: 4
      Rating of AI program: 6
      Rating of Systems program: 8
      Rating of Theory program: 9
      Effectiveness rating: 9
      Rating of faculty publications: 9
      Overall rating: 4
      
      
      Name: MIT
      State: Massachusetts
      Rating of number of women PhD's: 5
      Rating of AI program: 10
      Rating of Systems program: 9
      Rating of Theory program: 10
      Effectiveness rating: 10
      Rating of faculty publications: 7
      Overall rating: 5
      
      
      Name: CMU
      State: Pennsylvania
      Rating of number of women PhD's: 6
      Rating of AI program: 9
      Rating of Systems program: 9
      Rating of Theory program: 7
      Effectiveness rating: 8
      Rating of faculty publications: 6
      Overall rating: 6
      
      
      Name: Univ. of Washington
      State: Washington
      Rating of number of women PhD's: 7
      Rating of AI program: 5
      Rating of Systems program: 7
      Rating of Theory program: 8
      Effectiveness rating: 8
      Rating of faculty publications: 8
      Overall rating: 7
      
      
      Name: Princeton
      State: New Jersey
      Rating of number of women PhD's: 8
      Rating of AI program: 4
      Rating of Systems program: 5
      Rating of Theory program: 8
      Effectiveness rating: 7
      Rating of faculty publications: 10
      Overall rating: 8
      
      
      Name: Stanford
      State: California
      Rating of number of women PhD's: 9
      Rating of AI program: 8
      Rating of Systems program: 5
      Rating of Theory program: 8
      Effectiveness rating: 10
      Rating of faculty publications: 9
      Overall rating: 9
      
      
      Name: Cornell
      State: New York
      Rating of number of women PhD's: 9
      Rating of AI program: 5
      Rating of Systems program: 8
      Rating of Theory program: 9
      Effectiveness rating: 9
      Rating of faculty publications: 8
      Overall rating: 9
      
      

    What to turn in:

    • Turn in a hard copy of the files:
        gradSchools.cc
        school.cc

      Make sure you include a file prologue with your name, class, lecture section, the date, and the assignment number, along with a description of the file contents and their purpose. Also include appropriate comments for each of the functions you implement (with proper pre and post conditions).
    • A written paragraph describing why you picked the sorting function that you did.
    • A discussion log.
    • Submit the soft copy of your program using the command:
      ~csci132/bin/submit csci132 assign8

    Home | | Syllabus | | Assignments | | Lecture Notes


    Constance Royden--croyden@mathcs.holycross.edu
    Computer Science 132--Data Structures
    Last Modified: April 8, 2014
    Page Expires: January 14, 2015