C++代写:CS162FileIO


练习C++中基础 I/O 处理,读写文件。
![C++](https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/ISO_C%2B%2B_Logo.svg/150px-
ISO_C%2B%2B_Logo.svg.png)

Requirement

In order to get credit for the lab, you need to be checked off by the end of
lab. You can earn a maximum of 5 points for lab work completed outside of lab
time, but you must finish the lab before the next lab. For extenuating
circumstances, contact your lab TAs and the instructor.
This lab is worth 10 points total. Here’s the breakdown:

  • 4 point: Design for the problem
  • 6 points: Implement your design

Step 1: Design

In this lab, you will practice reading and writing to a file, a.k.a. File I/O.
You can copy and paste or download this example file.
The input file provides details for a student database in the following
format:
Number_of_students
ID_Number Student_First_Name Student_Last_Name Major

ID_Number Student_First_Name Student_Last_Name Major
Your program will read specific information from the file and continue reading
the contents of the body from the file until the EOF (end of file) character.
You will write the following information to an output file:

  • Sort students by ID number
  • Sort students by last name
  • The number of unique majors
    Each section of information should be labeled in the output file in all
    capital letters. A struct should be used to store and manipulate the file
    information between reading and writing the file. You must include the follow
    three functions with the exact prototypes:
  • student * create_student_db(int);
    This function will create the array of student based on the number of students
    in the file
  • void populate_student_db_info(student *, int, ifstream &);
    This function should do the work of actually reading through the ifstream that
    represents your opened file and storing the information in a pre-allocated
    array of student that’s passed in
  • void delete_student_db_info(student **, int);
    This function will delete all dynamic memory created in your program
    Your main function needs to check to make sure the file you open exists before
    moving forward. If the file doesn’t exist, then you need to provide an error
    message and get a file name that does exist.
  • Write a design for the main function in the driver file, driver.cpp.
  • Write a design for the create_student_db(), populate_student_db_info(), and delete_student_db_info() as well as the functions needed to satisfy the above bulleted output functions in the implementation file, student_db.cpp
    Here’s some documentation that will help you get going with File I/O:
  • C++ Basic file I/O: http://www.learncpp.com/cpp-tutorial/186-basic-file-io/
  • ifstream: http://www.cplusplus.com/reference/fstream/ifstream/
  • ofstream: http://www.cplusplus.com/reference/fstream/ofstream/
  • fstream: http://www.cplusplus.com/reference/fstream/fstream/

Step 2: Implementation

Now, implement the driver.cpp, student_db.cpp, and student_db.h files. Create
a Makefile to manage the compilation of all these files. You can adapt the
Makefile that was posted on the Calendar page in Canvas.
Remember, you will not receive lab credit if you do not get checked off before
leaving each lab. Once you have a zero on a lab, then it cannot be changed
because we have no way of knowing if you were there or no t.
Show your completed work and answers to the TAs for credit. You will not get
points if you do not get checked off!
Submit your work to TEACH for our records (Note: you will not get points if
you don’t get checked off with a TA!!!)

  1. Create a tar archive that contains all files you’ve created in this lab: tar -cvf lab2.tar student_db.h student_db.cpp driver.cpp makefile
  2. Transfer the tar file from the ENGR server to your local laptop.
  3. Go to TEACH.
  4. In the menu on the right side, go to Class Tools Submit Assignment.
  5. Select CS162 Lab2 from the list of assignments and click “SUBMIT NOW”
  6. Select your files and click the Submit button

文章作者: SafePoker
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 SafePoker !
  目录