Question: Design and implement a C/C++ program (a3part2.c [or a3part2.cpp]) to read a file, to do the following tasks. Task1. Read the file (/etc/passwd) and output
Design and implement a C/C++ program (a3part2.c [or a3part2.cpp]) to read a file, to do the following tasks.
Task1. Read the file (/etc/passwd) and output for each line to the file named (a3p2task1.txt)
For example, for one entry in the /etc/passwd file contains the following line:
name:*:1000:513:CS Professor:/home/name:/bin/bash
Then the program should output it as shown below.
userid: name
uid: 1000
gid: 513
gecos: CS Professor
home directory: /home/name
shell:/bin/bash
Task #2.
Design and implement each record as an object (of class named user).
Design and implement a C++ static variable (userMap) which is an associative map, to keep track of (the reference of each) user-account information so that you may enumerate (iterate) each object later. The map keeps track of the pair of (a) user-name (e.g., name) and (b) its reference to the corresponding object (e.g., of name).
Then output the content of the map first (1) sorted by uid and output each object (as shown in Task1 output-format), and then (2) sorted by gid and output each object (as shown in Task1 output-format), to a file named (a3p2task2.txt).
Task #3.
Iterate each user object in the map, to write each object into a binary file (a3p2task3.bin).
Then delete all the user objects and empty all the entries in the map.
Task #4
Then your program is to read this binary file (a3p2task3.bin), reading each user object from the file into a new user object, and create an entry to the map as you have done in Task #2. Then output each object as you have done in Task#3 to a file (a3p2task4.txt).
You should provide a cross-checking of these two files with cmp command.
cmp a3p2task1.txt a3p2task4.txt
Task #5. Provide a Makefile file to compile your program.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
