0% found this document useful (0 votes)
29 views4 pages

W11-Struct-File IO

Uploaded by

mathanhnhi2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views4 pages

W11-Struct-File IO

Uploaded by

mathanhnhi2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Introduction to Programming

Week 09
Struct – File IO

Department of Software Engineering-FIT-VNU-HCMUS


Introduction to Programming W09 – Struct – File IO

1
Content
In this lab, we will study the following topics:
• How to define and use a struct.
• How to load data from text file.
• How to save data to text file.

2
Introduction to Programming W09 – Struct – File IO

2
Assignments
A: YY = 05
H: YY = 20: at least 7 in struct Date + at least 7 in struct Student + at least 6 in struct Course

2.1 Assignment 1
Define a struct Date (day, month, year) and the following functions.
1. Input a date.
2. Output a date (yyyy-MM-dd).
3. Output a date with a given format. For example: yy: 70, yyyy: 1970, M: 8 or 12, MM: 08 or 12,
MMM: Jan … Dec, d: 1 or 29, dd: 01 or 29.
outputDateWithFormat(d1, "yyyy-MM-dd"); // 2019 - 12 - 04
outputDateWithFormat(d1, "MMM dd yy"); // Dec 12 19

4. Load a date from a text file.


5. Save a date to another text file.
6. Compare 2 date.
7. Find tomorrow: increase a date by 1 day.
8. Find yesterday: decrease a date by 1 day.
9. Increase a date by k day.
10. Decrease a date by k day.
11. Compute the distance between input date vs 1/1/same year.
12. Compute the distance between input date vs 1/1/1970.
13. Compute the distance between 2 input dates.
14. Given that the date of week of 1970-01-01 is Thursday. Compute the date of week of the input
date.
Define a struct Student (id, full name, gpa, address, date of birth) and the following functions.
15. Input a student.
16. Output a student: id, full name, gpa, address, dob.
17. Output a student: id, first name (first word), last name (remaining words), gpa, address, dob,
age (18 year 2 months, 2 days).
18. Load a student from a text file.
19. Save a student to a text file.
20. Extract the class of input student. For example, if your id is 19127001, you are in K19 class.
21. Compare 2 students by id.
22. Compare 2 students by gpa, and then by id.
23. Compare 2 students by name, and then by id.
24. Compare 2 students by first name, and then by id.

3
Introduction to Programming W09 – Struct – File IO

25. Compare 2 students by last name, and then by id.


26. Compare 2 students by dob, and then by id.
Define a struct Course (course id, e.g. CS161, course name, e.g. Introduction to Programming, and
an array of students, status, e.g. open, or close, maximum number of students in the course,
minimum number of students in the course) and the following functions.
27. Load a course from text file.
28. Save a course to text file.
29. Add a student to a course. Check the maximum number of students in the course condition.
30. Remove a student to a course. Check minimum number of students in the course to update the
course status: open or close.
31. Get the current date in your computer. Find all students who were born in this month and save
to a text file.
32. Get the current date in your computer. Find all students who were born in this date and save to
a text file.
33. Get the current date in your computer. Find all students who are legal to have driving licences
(>= 18 years old) and save to a text file.
34. Find all students are in K19 class and save to a text file.
35. Find a student by a given id. Save the answer to a text file.
36. Find a student by a given name (“thanh” vs “Tuan-Thanh Ho”). Save the answers to a text file.
37. Sort students by id. Save the answers to a text file.
38. Sort students by first name. Save the answers to a text file.
39. Sort students by gpa. Save the answers to a text file.
40. Sort students by dob. Save the answers to a text file.

You might also like