Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
PROJECT #1: C++ with STL Purpose This project gives you a chance to review and understand the important features that C++ and STL promise through programming practice. Please read the following instructions carefully. Contents and Structure The project mainly covers three features: inheritance and polymorphism, exception and I/O, and STL. Part 1 (40 points) In this part, you design and implement all the classes in the UML diagram on the last page. Polymorphism is emphasized. a) (15) general specifications: Data members of Student class are protected; data members of DCL (Derived Class) are private All member functions are public; constructors may have several parameters Tuition rates should be class-wide constants; they are used to compute total tuition (times credits) Student class should have get-set functions as other classes In Student class, functions print() and tuition() are virtual and tuition() is pure (they must be overridden in DCL) Print functions must print all the data members in a nice format (e.g. add “endl”; “student name: ***”, etc) b) (25) call print() and tuition() for the following three students using both static and dynamic binding: under_rate = 380.0; grad_rate = 500; “Mary”, “000111222”, “Junior”, 12 credits, her tuition, her gpa (4.0) “David”, “111222333”, graduate student, 9 credits, his tuition, his thesis (“How to learn data structures using C++/STL?”), his gpa (3.7) “Jason”, “222333444”, graduate assistant, 9 credit hours, his tuition, his thesis (“Design of efficient algorithms”), his gpa (3.9) his task (“Grading 330 projects and implementing a data mining algorithm”), his hourPay ($20), his superviser (“Dr. Fu”) These are just facts data; your final output may look differently (but nicely). Part 2 (45 points) This part involves I/O streams, files and exceptions, and STL. a) We should be able to guard against “unexpected” input data using exceptions when constructing new students: ssn must be exactly 9 decimal digits gpa in [0, 4.0] credits in 0..18 b) Suppose that input undergraduate roster is a text file called “student.txt” (you type in four records) in which fields are separated by white-space “ ” and records by “\n”. For example, the first record (the fields are all in the following order: name, ssn, year, credits, gpa) could be Mary 000111222 Junior 12 4.0 (10) Scan (read) the file and construct students one by one. Notice that, you should check the input data according to part a. (5) Store the students in a list container (can insert one by one). (5) After all students are scanned and pushed into the list, delete the last student and insert him/her to the front as the first student. (10) Then print out on screen all the students using list iterator in the following format: Header line: Name SSN …… Year Credits Tuition GPA In each line (including the header), each field’s width is10 except “Name” whose width is 20. The last two fields are right-justified and have two fraction digits. Tuition must be padded with $ sign to the left. All other fields are left-justified. (15) Then initialize a vector that contains the above list data and sort the students according to GPA. You must use generic sort algorithm (therefore need to overload “<” operator). After sorting, output the sorted students using the above format. Submission Instruction 1) Code must be run on a UNIX machine. 2) Electrical copy by email and hard copy are required for each submission. 3) You submit one source file named as “X_Undergrad.cpp” (X is your logon username e.g. l_fu ) and put all the drivers in the main function of class “Undergrad”. The output order appears as required above. If you have comments or “readme” things (and you should), put them in the beginning as a comment block. 4) File including the source file must be well-documented. Code is self-evident (e.g. clear names) and comments are concise, sufficient, and accurate. Documenting counts 15 points. X: your logon username. Student name: char[21]; ssn: char[10]; gpa: float; credits: int; Student(); void print(); float tuition(); X_Undergrad Grad undergrad_rate: float; year: char*; grad_rate: float; thesis: char*; Undergrad(); char* get_year(); float get_rate(); void set_year(char*); Grad(); char* get_thesis(); float get_rate(); void set_thesis(char*); GradAsst hourPay: float; superviser: char*; task: char*; GradAsst(); char* get_superviser(); float get_hourPay(); void set_ superviser (char*); void set_ hourPay (float); char* get_task(); void set_task(char*);