Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A C++ program. Please don't use the global variable, thanks. Notes/Tips: Use std::ifstreamto read data from the text files. Using command-line arguments in your C++

A C++ program. Please don't use the global variable, thanks.

image text in transcribed

image text in transcribedimage text in transcribedNotes/Tips:

Use std::ifstreamto read data from the text files.

Using command-line arguments in your C++ program is covered in https://youtu.be/vskJ1OGDi8c?t=663

Use std::istringstreamto process each lineread using std::getlinemethod. See example in lecture slides on processing Comma Separated Values(in Part 4 of C++ topics). Here is convenience link to that spot in the video: https://youtu.be/quvz74hMzCo?t=735

Use anunordered_mapto store uidloginIDinformation to ease look-up from processing group membership.

It would be easier to compute and store the line of output to print for each gidin another unordered_map.

Here are the #includesin the reference solution for your convenient reference:

#include #include #include #include #include #include

groups.txt:

root:xyzzz:0:0 bin:x:1: faculty:xx:2:1000,1001,1003,1004,2000,1500,2001,2002,2010,2011,2012 staff:x123:3:1002,1000 linux:xab:1000:2002,2012,1000,1001 admin:xabcdefg:5:1001,1002,0 theory:x:6:2001,1500,1004,2002 labs:yy:7:1000,1002,2001,2010,2012

passwd.txt:

root:xx:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbinologin raodm:xyz:1000:1000:DJ Rao:/home/raodm:/bin/bash campbest:xxxxx:1001:1001:Scott Campbell:/home/campbest:/bin/bash lewisjp3:x:1002:1002:John Lewis:/home/lewisjp3:/bin/tcsh kiperjd:xooo:1003:1003:Jim Kiper:/home/kiperjd:/bin/ksh raychov:xp:1004:1004:Vaskar Raychoudhury:/home/raychov:/bin/ksh bachmaer:x:2000:2000:Eric Bachmann:/home/bachmaer:/bin/bash inclezd:x:1500:2000:Daniela Inclezan:/home/inclezd:/bin/bash davisk4:x:2001:2001:Karen Davis:/home/davisk4:/bin/bash femianjc:xya1234:2002:2002:John Femiani:/home/femianjc:/bin/bash crossv:x:2010:2010:Valerie Cross:/home/crossv:/bin/bash castroa:1111:2011:2011:Castro-Hernandez Alberto:/home/castroa:/bin/tcsh ahmede:x:2012:2012:Emdad Ahmed:/home/ahmede:/bin/bash

Develop program to print group membership Objective The objective of this program is to print login-IDs of the users belonging to a given set of gids (group IDs) specified as command-line arguments. The necessary data is read from 2 given text files. Background In Linux, users are internally represented using a unique number called user ID or uid. Moreover, a set of users can be logically organized into a group. Such groups are represented by a group ID or gid. Typically, these numbers are seldom used and instead a name is associated with these numbers and the names are often used. This program will serve as an excellent tool to quickly identify membership in a given group. Data file formats Prior to solving any problem is important to study the supplied data. So, ensure you view the data files (yes, of course you can do this in NetBeans). The supplied data files used are nearly in the same format as they are in a real Linux OS as described below. Needless to add, you will need to copy/download these files to your NetBeans project in order to read/use them. 0 User data (passwd. txt): The supplied file contains user information in the following colon (:) delimited format: login ID:passkey:uid:... For example, the following line from passwd "raodm: xyz:1000:.." contains the login ID raodm as the first entry, xyz is some passkey (not used) followed by the uid (int). Rest of the information on each line is not used in this project. Group information (groups.txt): The supplied file contains group information in the following colon (:) delimited format: groupID:passkey:gid:members... For example, the following line from groups "staff:x123:3:1002,1000" contains the group ID staff as the first entry, x123 is some passkey (not used) followed by the gid (int), followed by a comma separated list of uids. This results in group corresponding to output "3 staff: lewisjp3 (1002) raodm (1000)", where the uid for each login ID is shown in parentheses. The loginId for an uid is in the passwd file, described just above. Base case #1 [Must pass to earn any points]: Simple test with exactly 1 valid group ID as a command-line argument $ ./raodm_hw2 0 = root: root (0) 0 Base case #2 [Must pass to earn any points]: Simple test with exactly 1 valid group ID as a command-line argument $ ./raodm_hw2 1 1 = bin: Test case #3 [Additional feature]: Test with an invalid group id $ ./raodm hw2 100 100 = Group not found. Test case #4 [Additional Feature]: Test with many valid/invalid group IDs supplied as command-line arguments $ ./raodm_hw2 0 1 2 6 100 6 2 0 = root: root (0) 1 = bin: 2 = faculty: raodm (1000) campbest (1001) kiperjd (1003) raychov (1004) bachmaer (2000) inclezd (1500) davisk 4 (2001) femianjc (2002) crossv (2010) castroa (2011) ahmede (2012) 6 = theory: davisk4 (2001) inclezd (1500) raychov (1004) femianjc (2002) 100 = Group not found. 6 = theory: davisk4 (2001) inclezd (1500) raychov (1004) femianjc (2002) 2 = faculty: raodm (1000) campbest (1001) kiperjd (1003) raychov (1004) bachmaer (2000) inclezd (1500) davisk4 (2001) femianjc (2002) crossv (2010) castroa (2011) ahmede (2012) Develop program to print group membership Objective The objective of this program is to print login-IDs of the users belonging to a given set of gids (group IDs) specified as command-line arguments. The necessary data is read from 2 given text files. Background In Linux, users are internally represented using a unique number called user ID or uid. Moreover, a set of users can be logically organized into a group. Such groups are represented by a group ID or gid. Typically, these numbers are seldom used and instead a name is associated with these numbers and the names are often used. This program will serve as an excellent tool to quickly identify membership in a given group. Data file formats Prior to solving any problem is important to study the supplied data. So, ensure you view the data files (yes, of course you can do this in NetBeans). The supplied data files used are nearly in the same format as they are in a real Linux OS as described below. Needless to add, you will need to copy/download these files to your NetBeans project in order to read/use them. 0 User data (passwd. txt): The supplied file contains user information in the following colon (:) delimited format: login ID:passkey:uid:... For example, the following line from passwd "raodm: xyz:1000:.." contains the login ID raodm as the first entry, xyz is some passkey (not used) followed by the uid (int). Rest of the information on each line is not used in this project. Group information (groups.txt): The supplied file contains group information in the following colon (:) delimited format: groupID:passkey:gid:members... For example, the following line from groups "staff:x123:3:1002,1000" contains the group ID staff as the first entry, x123 is some passkey (not used) followed by the gid (int), followed by a comma separated list of uids. This results in group corresponding to output "3 staff: lewisjp3 (1002) raodm (1000)", where the uid for each login ID is shown in parentheses. The loginId for an uid is in the passwd file, described just above. Base case #1 [Must pass to earn any points]: Simple test with exactly 1 valid group ID as a command-line argument $ ./raodm_hw2 0 = root: root (0) 0 Base case #2 [Must pass to earn any points]: Simple test with exactly 1 valid group ID as a command-line argument $ ./raodm_hw2 1 1 = bin: Test case #3 [Additional feature]: Test with an invalid group id $ ./raodm hw2 100 100 = Group not found. Test case #4 [Additional Feature]: Test with many valid/invalid group IDs supplied as command-line arguments $ ./raodm_hw2 0 1 2 6 100 6 2 0 = root: root (0) 1 = bin: 2 = faculty: raodm (1000) campbest (1001) kiperjd (1003) raychov (1004) bachmaer (2000) inclezd (1500) davisk 4 (2001) femianjc (2002) crossv (2010) castroa (2011) ahmede (2012) 6 = theory: davisk4 (2001) inclezd (1500) raychov (1004) femianjc (2002) 100 = Group not found. 6 = theory: davisk4 (2001) inclezd (1500) raychov (1004) femianjc (2002) 2 = faculty: raodm (1000) campbest (1001) kiperjd (1003) raychov (1004) bachmaer (2000) inclezd (1500) davisk4 (2001) femianjc (2002) crossv (2010) castroa (2011) ahmede (2012)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions