Problem overview

Most programming is not done in one small sprint. Instead most programs are written over large periods of time, in large teams. As the software team builds their software, they often discover new features they would like to support, and old features that were poorly designed. Likewise, as software testing continues, the users of a system (or the people paying you to build it) may make changes to how they want features to work.

While common, this sort of software evolution is remarkably hard to simulate in a teaching environment. This homework, however, seeks to emulate it. In this homework we will be taking "Feedback" from the USMASY clients about the testing version we delivered in HW8. Based on their feedback we will be adding two new commands and substantially altering one of the commands we've already designed.

USMASY system feedback

The USer MAnagement SYstem that we delivered in HW8 was generally well received. While our clients would have preferred to see the full feature set in the first development test, they understand that it wouldn't be possible under the deadline. After seeing how the current version of USMASY worked, they have one new feature they would like to add, one feature from their original USMASY specification they would like to have you prioritize and deliver before the next version, and one core feature they would like changed.

Changes to the load operation The USMASY clients have requested the following changes to the load behavior:

  • The clients expect very significant growth in their service soon. There should be NO UP- PER LIMIT in how many user accounts can be stored. If they can get 10,000,000 users, and a computer with enough memory for storing 10,000,000 SystemUser objects, they want the software to support it.
  • The memory use of the SystemUser array during testing is too high. There should be NO EXTRA MEMORY USAGE for System users. If they are testing a file with only 7 SystemUsers, they only want a 7 user SystemUser array to be stored in memory.
  • The clients have asked us to allow multiple files to be loaded. As it turns out, they often store each week's new users in one file. We will need to change how load works to allow loading multiple files.
  • After discussing as a design team, we've decided that accommodating this request will require switching from a constant sized traditional array, to a dynamically allocated array. This will give our code flexibility to grow or shrink its space usage based on need.
  • To make the above changes easier to make, the clients have agreed to change the ".usmasy" file format slightly. There is one change: the first line of each file will contain an integer - the number of SystemUsers recorded in the file. This change will make it much easier to use dynamic memory in the program.

High Priority Task - Save In the "Original" USMASY outline there was a save operation, which would write an accounts file for future use. We cut this for time, but the clients would like to see this in the next testing version. The save operation should create a new file in the standard USMASY file format: the first line should list the count of users, Following that should be a list of all users, in order, formatted as username < space> password. The files created by the save operation should be directly loadable by the load operation. If the user loads one file and then saves, it should simply create a copy of the loaded file. However, if the user loads two or three files, the saved file should be a combination of all source files.

New Operation - stats To help with testing, the clients have added for a new operation be added to USMASY - the "stats" operation. When the user types the stats command it should print the number of users currently loaded into the USMASY system. After that, it should optionally allow printing all usernames in the order they were loaded.

While this is an extra operation, our team agreed that it should be easy enough to add and agreed to add this into the next release of USMASY. This is also a somewhat strategic decision - 3 our team was having a lot of trouble testing that load operation and think that this might help us test out work before showing it to the clients.

First Task: add a stats command

Your first task should be to add the stats command. This should work essentially the same way with the HW8 load and the HW9 load commands, and having it written will help out a bit with testing the updated load.

Requirements

  • The command must follow the formatting seen in the examples
  • The command must be listed with the other commands in the help command (see examples)
  • The command should list the current number of users in the system.
  • The command should then ask the user if they would like to list all SystemUsers, and prompt the user to type y or n
  • If the user types a letter other than y or n, the prompt should repeat.
  • If the user types y each username should be printed.

Second Task: Setup for updating load command

The changes in file format and load are the primary hard-part of this change, therefore we will focus on changes outside of the command first.

Requirements

  • Your program MUST use a SystemUser pointer, pointing to a dynamically allocated array to solve this problem. You will not get credit if you use a normal, non-dynamically allocated array.
  • Your program MUST NOT leak memory - the dynamically allocated array should be deleted when appropriate. NOTE - this is remarkably hard to test you should plan on manually verifying this is correct by reading your code carefully and arguing logically why it is true. Likewise we will be checking for memory leaks by carefully reading your code and considering if all necessary delete commands are called. Your code can pass all tests and still fail this requirement.

To begin, simply change the SystemUser array to a pointer and use a new command to allocate an array of the same initial size as found in the code. You will want to add a line of code to delete at this point as well. You may need to change some arrays to pointers in function parameters, but from there your code from HW8 should compile correctly again.

Before starting the third task you will need to change the inital size of the array to something small such as 1 "empty" user. The inital array will not actually be used once we change the load command, so it can be very small.

Third Task: loading

While the user interface (cin / cout) for this command is unchanged, it will need to change a lot in it's behavior. The expected behavior and changes are detailed in the introduction section of this homework, but we can provide some hints here.

Things to think about / hints:

  • The file format has changed, the first line of each file will be a count of system users following it. This will make loading the users easier if you wish, but you will need at least one read command outside of a loop to address this number.
  • Code you have written that forbids loading twice will simply need to go away.
  • If you have previously used a function for load, you will find this difficult unless you use reference parameters, as the number of users and the system user array pointer itself may both need to change.
  • Your code will need to "make more room" in the dynamic system array. We will do this the same way we saw in the lecture slides - make a second, bigger array, move data into this new array, and then delete the old array.
  • Your load command will need to make a new dynamic array that is the correct size (the number of currently loaded users plus the number of new users as listed in the first line of the file)
  • You will want to copy the already loaded users into the new array. You can do this with a simple assignment operation NOTE: I am NOT saying to overload operator= for SystemUser that is NOT NECESSARY as SystemUser has no pointers within it. The operator= that C++ wrote will be sufficient.
  • Don't forget to delete the old (too small) array, or to update the array pointer in main to point at the new (correctly sized) array
  • New users should be loaded after existing users in the file.
  • When loading you should not worry about duplicate users. It will be frowned upon, but accepted, for login to behave strangely if the user loads the same file twice or otherwise loads duplicate users.

Fourth task: saving

This command asks you to create a new accounts file based on whatever data is currently loaded. The format of this file is exactly as the format used by a load command. You should be able to load several files, save them together as one "big" file, and then run the program again loading only the big file to get the same effect as loading the several smaller files. The count of users you put in the first line of the file should be correct to the accounts you print. Each following line should contain exactly one SystemUser described by it's username and password. Your overloaded << operator should do most of the work here. The file should be named whatever the user types, if the user wants a .usmasy filename, they should type that. If the user wants a .txt filename they should type that, etc.

Examples

These examples make use of the usmasy file posted online.

Example 1

In this example, our user views the new help page and stat command, but gets a bit confused with the yes/no prompt.

Welcome to USMASY the user management system
enter command: help
Welcome to USMASY the user management system
The USMASY commands are:
* help
* stats
* load
* save
* login
* exit
enter command: stats
There are 0 current users loaded
would you like to see all users? (y/n)?: w
would you like to see all users? (y/n)?: q
would you like to see all users? (y/n)?: n
enter command: exit
Goodbye!

Running this example should not create or change any files.

Example 2

In this example the user loads a small testing file, logs in, and shows off the stats command a bit

Welcome to USMASY the user management system
enter command: load
enter a USMASY file name: NotAFile
unable to open NotAFile
enter command: load
enter a USMASY file name: newUsers.usmasy
enter command: login
username: Minymu
password: fbC5DDU5Pzkf5jb2
ERROR: incorrect password
password: empty
ERROR: incorrect password
password: WRpkx7sbv2SPdYB4
login successful
enter command: stats
There are 6 current users loaded
would you like to see all users? (y/n)?: +
would you like to see all users? (y/n)?: y
0: BrainyLive
1: Minymu
2: Dreamyca
3: WannaEver
4: StarThesoy
5: Empreek
enter command: exit
Goodbye!

Running this example should not create or change any files.

Example 3

In this example the user loads two files, checking logins as they go to make sure only the right data is available. They then use stats to confirm loading and loading order, and finally save the two files in a combined file.

Welcome to USMASY the user management system
enter command: load
enter a USMASY file name: week3Accounts.usmasy
enter command: stats
There are 30 current users loaded
would you like to see all users? (y/n)?: n
enter command: login
username: angelfishpenalty
password: MTmdaK6W
login successful
enter command: login
username: BrainyLive
ERROR: unable to find user data
enter command: load
enter a USMASY file name: newUsers.usmasy
enter command: stats
There are 36 current users loaded
would you like to see all users? (y/n)?: y
0: unpackcedric
1: iphoneexternal
2: donnybrookvivace
3: husksilo
4: strikesport
5: urifraction
6: muskyurinary
7: grubblethundercat
8: eulerpreseason
9: priscillablame
10: izzycosmogony
11: empathicoverlay
12: retailmonitors
13: proposespry
14: concernedlexy
15: unyieldingelixir
16: chaosconnie
17: exceptioncerebrum
18: euphemismedmundston
19: shyingblaze
20: angelfishpenalty
21: brittledefinitely
22: glitzyunripe
23: earactive
24: juliusshowplace
25: pileshoop
26: perchanger
27: digbyiridium
28: dollsswab
29: fingernoir
30: BrainyLive
31: Minymu
32: Dreamyca
33: WannaEver
34: StarThesoy
35: Empreek
enter command: login
username: BrainyLive
password: fbC5DDU5Pzkf5jb2
login successful
enter command: login
username: chaosconnie
password: f4aWYp89
login successful
enter command: save
enter a USMASY file name: combined.txt
enter command: exit
Goodbye!

After running this example a file "combined.txt" should be made with the following contents:

36
unpackcedric NnQzE6GL
iphoneexternal BM8F6fC8
donnybrookvivace 7f6SMcDS
husksilo gJ6n9fyG
strikesport yE9CMeTQ
urifraction KcPxJNB4
muskyurinary BCx6E3KB
grubblethundercat bYe7T6WQ
eulerpreseason 5S8t3BKD
priscillablame 5Qz4sj2K
izzycosmogony uSk7dEtq
empathicoverlay 94XzJqxd
retailmonitors 5AU4yZhJ
proposespry wSpE3d9Y
concernedlexy xG6p6BEu
unyieldingelixir PMapBF5K
chaosconnie f4aWYp89
exceptioncerebrum u7Q5dU7G
euphemismedmundston DHQyJ6G6
shyingblaze uDgc6Q2G
angelfishpenalty MTmdaK6W
brittledefinitely Us6BMV4Z
glitzyunripe t5vaxyZB
earactive cVL8u7PR
juliusshowplace SwgCUbk8
pileshoop PyQWX5Uw
perchanger 8yBHGQ3C
digbyiridium ZSgWAh6N
dollsswab 2EHxt2PC
fingernoir JbCM2W49
BrainyLive fbC5DDU5Pzkf5jb2
Minymu WRpkx7sbv2SPdYB4
Dreamyca xvfQFh6Wny9vCRsm
WannaEver nMCe5qZXX4fHGVdk
StarThesoy 3A3GLq4VpMsVBVxa
Empreek VyJeNVkRZuAq93Em

Example 4

In Example 4 we load the file made in Example 3.

Welcome to USMASY the user management system
enter command: load
enter a USMASY file name: combined.txt
enter command: stats
There are 36 current users loaded
would you like to see all users? (y/n)?: y
0: unpackcedric
1: iphoneexternal
2: donnybrookvivace
3: husksilo
4: strikesport
5: urifraction
6: muskyurinary
7: grubblethundercat
8: eulerpreseason
9: priscillablame
10: izzycosmogony
11: empathicoverlay
12: retailmonitors
13: proposespry
14: concernedlexy
15: unyieldingelixir
16: chaosconnie
17: exceptioncerebrum
18: euphemismedmundston
19: shyingblaze
20: angelfishpenalty
21: brittledefinitely
22: glitzyunripe
23: earactive
24: juliusshowplace
25: pileshoop
26: perchanger
27: digbyiridium
28: dollsswab
29: fingernoir
30: BrainyLive
31: Minymu
32: Dreamyca
33: WannaEver
34: StarThesoy
35: Empreek
enter command: login
username: strikesport
password: yE9CMeTQ
login successful
enter command: login
username: Empreek
password: VyJeNVkRZuAq93Em
login successful
enter command: load
enter a USMASY file name: week2Accounts.usmasy
enter command: stats
There are 106 current users loaded
would you like to see all users? (y/n)?: n
enter command: exit
Goodbye!

After running this example no new files should be made, and no files should be changed.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.