[Solved] SOLVED:Laboratory axercise Week 11 solution

30 $

File Name: SOLVED:Laboratory_axercise_Week_11_solution.zip
File Size: 405.06 KB

SKU: [Solved] SOLVED:Laboratory axercise Week 11 solution Category: Tag:

Or Upload Your Assignment Here:


Task One: String streamUse ostringstream and istringstream to implement the following two functions in a file stringIO.cpp by assuming that the operators << and have been overloaded for type T.template string toString (T value); // convert a value into a stringtemplate T toValue(string str); // extract the value from a stringDefined a class Student in a file Student.h and implemented the member functions in a file Student.cpp. The class Student can be defined like followingclass Student {private:string firstname;string lastname;int id; // student numberfloat gpa;public:// all necessary functions to be defined here… …};Implement a main() function in stringIO.cpp to test the two functions in the cases where T is integer, double and class Student.You need to define and implement the student class properly in order to test the two template functions and assume the input string for the student class is in the following format.First-name:last-name:student-number:gpaFor example:John:Anderson:1234567:6.35Testing:Compile the program in this task by:CC –o task1 stringIO.cpp Student.cppRun the program (You may use different values)./task1Input an integer: 12345678Integer to string: 12345678String to integer: 12345678Input a double: 3214.654Double to string: 3214.65String to double: 3214.65Input a student record (first-name:last-name:number:gpa): David:Smith:1234567:3.65Student to string:David:Smith:1234567:3.65String to Student:David:Smith:1234567:3.65Note: The outputs above indicate different types of data.Task Two: Containers and generic functionsImplement C++ code in a file task2.cpp include main() function that read input data for students; add students’ records in a vector container; use generic functions copy to copy the students’ records from a vector to a deque container; display the records in the deque container by using its iterator to travel through the container; then use sort function to sort the students’ records by their last names and first names inside the deque container; finally display the sorted records by using the generic copy function.Hint: You should define comparison operator (<) for the class Student and define afunction object to compare two students.Testing:Compile the program in this task by:CC –o task2 task2.cpp Student.cpp./task2Number of Student records: 5John:Smith:1234567:3.21Taylor:Swift:7654321:5.43Joan:Anderson:1122334:4.25Bob:Cook:2211443:3.89Marry:Brand:1234432:5.23There are 5 records in the vector.Copy Students from vector to deque:John:Smith:1234567:3.21Taylor:Swift:7654321:5.43Joan:Anderson:1122334:4.25Bob:Cook:2211443:3.89Marry:Brand:1234432:5.23Sorted records in deque:Joan:Anderson:1122334:4.25Marry:Brand:1234432:5.23Bob:Cook:2211443:3.89John:Smith:1234567:3.21Taylor:Swift:7654321:5.43You can download the testing file input2.txt from Moodle.Task Three: Binary file and vectorDownload the source files Employee.h and Employee.cpp from the web site. Implement main() function in a file task3Main.cpp that read employees’ records from the given binary file from the command line and save the records into a vector container. Then use iterator to access each Employee record in the vector container and print out all the information.You will consider there is no file name passed from the command line or the file not exists.Testing:Compile the program in this task by:CC –o task3 task3Main.cpp Employee.cppWhen you run the program./task3Usage: ./task3 binary-file-nameWhen you run the program with a file name which does not exist../task3 mydata.datError: The file mydata.dat not exists or cannot be opened.When you test the program with a binary file (edate.bin can be downloaded from the web site),./task3 edata.binThe output will beEmployee ID: 100First name: aaaLast name: bbbPay rate/hour: $00105.28Employee ID: 101First name: bbbLast name: ccc

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] SOLVED:Laboratory axercise Week 11 solution
30 $