Question: Help in Unix on bash Design and implement C++ program (a3part2.cpp) with the password file (/etc/passwd) to do the following tasks. root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin

Help in Unix on bash

Design and implement C++ program (a3part2.cpp) with the password file (/etc/passwd) to do the following tasks.

root:x:0:0:root:/root:/bin/bash

bin:x:1:1:bin:/bin:/sbin/nologin

daemon:x:2:2:daemon:/sbin:/sbin/nologin

adm:x:3:4:adm:/var/adm:/sbin/nologin

Task1.

Design and implement a class (passwd) which contains member variables for each field of the password file (/etc/passwd). You will have an array (passwdArray) of which each element is an instance-object of passwd class (from each record of the passwd file). Reading the password file (/etc/passwd), each record will be instantiated as an object of the passwd class and set to be an element of an array.

Output each record (object) in the array (passwdArray) to a file (a3p2task1.txt).

Task2

Output each passwd object in the passwdArray, into a binary file (a3p2task2.bin).

Then your program is to read this binary file (a3p2task2.bin), reading each passwd object from the file, into another password array (passwdArray2). Then output each object as you have done in Task1 to a file (a3p2task2.txt).

Task #3

Create a Map object (passwdMap) where its key is uid and its value is gid. Populate map entry from each object in passwdArray. Print each entry in passwdMap in ascending order by the key value.

this is part of it and also for task 1 and 2

#include

#include

using namespace std;

class Student

{

public:

char name[10];

char address[10];

char Gender;

char DOB[10];

Student()

{}

};

int main()

{

cout<<" Writting on file: Student1.txt ";

Student *p=new Student;

cout<<1<<": ";

cin>>p->name;

cout<<" ";

// to append use ios::app

// ofstream osfile("Student1.txt",ios::binary|ios::app);

ofstream osfile("Student1.txt",ios::binary);

osfile.write((char*)p,sizeof(Student));

osfile.close();

cout<<" reading Student1.txt ";

Student *p2=new Student;

ifstream isfile("Student1.txt",ios::binary);

isfile.read((char*)p2,sizeof(Student));

isfile.seekg(0);

isfile.close();

cout<<1<<": ";

cout<name;

cout<<" ";

return 0;

}

this is for task 3

#include  
#include  
#include  
 
int main() 
{ 
 std::map wordcounts; 
 std::string s; 
 
 while (std::cin >> s && s != "end") 
 ++wordcounts[s]; 
 
 while (std::cin >> s && s != "end") 
 std::cout << s << ' ' << wordcounts[s] << ' '; 

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

It seems like the provided information is incomplete because the code snippets shared do not relate directly to the tasks specified with the etcpasswd file They appear to be starting points or example... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!