Write functions that add a user to a server

Assignment Help C/C++ Programming
Reference no: EM132587278

Problem Description

In this project, you have to manage a list of computer servers, where each server hosts multiple users. The server data is stored as an associative data structure type called ServerData which is an STL map<string, set<string>>. Thus, the keys of this map are strings that represent server names, and the values associated with each server name is an STL set of strings that are the names of users on that server.

You will have to write functions that add a user to a server, disconnect a user from a server, balance the server load, etc.

Program Specifications
You are provided with a proj07_functions.h that contains the signatures of all the functions you must implement. You must implement those functions and turn in your results as proj07/proj07_functions.cpp to Mimir. You are also provided with proj07_main.cpp that does some minimal testing of these functions. Of course, the real test cases are on Mimir as always.

Functions
bool AddConnection(ServerData &sd, ServerName sn, UserName un)
This function tries to connect the user un to the server sn. If the server exists, it adds un to that server. If the server does not exist, it is created (added to sd) and the user un is added to that server. Both of those conditions return true
If the user un is already connected to the server sn, then no action is taken, and the function returns false.
bool DeleteConnection(ServerData &sd, ServerName sn, UserName un)

This function tries to disconnect the user un from the server sn, and returns true if d is successfully updated with that information. If the user un is not connected to the server sn, then no action is taken, and the function returns false.

ServerData ParseServerData(const std::string &fname)

fname is the name of a file that contains an arbitrary number of lines of text where each line consists of three strings, each space separated. Each line is either of two forms:
• user_name join server_name
• user_name leave server_name

For each line in this file, if the 2nd string is join, then add user_name to server_name. If the 2nd string is leave, remove user name from server name. If specified action cannot be performed, e.g. if trying to add user_name to server_name when user_name is already connected to server_name, then that action is simply ignored.

Errors on ParseServerData
• if the file name cannot be opened, the function throws an invalid_argument exception
• if any of the input lines has a command other than leave or join, the function throws a domain_error exception
void PrintAll(std::ostream out&, const ServerData sd&)
Prints the contents of sd to out (not cout, the passed ostream out). Format is:
server_name : user_name user_name ... user_name
server_name : user_name user_name ... user_name

There is a '\n' after each line including the last

set<string> AllServers(const ServerData & sd)
Returns a set<string> which is the set of all servers in the sd
set<string> AllUsers(const ServerData & sd)
Returns a set<string> which is the set of all users on any server in the sd
set<string> HasConnections(const ServerData &sd, UserName un)
This function returns a set<string> of all the server names in sd that the user un is
currently connected to. Note that the return set could be empty.
set<string> HasUsers(const ServerData &sd, ServerName sn)
This function returns a set<string> of all the user names in the server sn that are currently connected in sn. Note that the return set could be empty.
void BalanceServers(ServerData &sd, ServerName sn1, ServerName
sn2)
This function tries to balance the number of users that are connected to server sn1 and sn2. If a user is connected to both servers, then they are not moved. All the users that are only connected to one of the 2 servers are moved in the following fashion. These users are sorted alphabetically by their name, and the first half are moved to server sn1, and the other half are moved to server sn2. (Note: if there are an odd number N of users, then N/2 +1 users are moved to sn1.)

void CleanAndBalance(ServerData &sd)

This function first removes all duplicate users from sd. Then the unique users are moved around in the following way.
1. All the user names and server names are sorted alphabetically
2. The users are distributed to servers in a round-robin fashion in alphabetical order of server and user names

For example, assume there are 3 servers named x,y,z and 8 users named a,b,c,d,e,f,g,h. Note we already sorted both lists (which you would have to do).
• users a,d,g will be moved to server x, users b,e,h will be moved to server y and users c,f will be moved to server z

Deliverables
proj07proj07_functions.cpp -- your completion of the functions described above.
Only proj07/proj07_functions.cpp is turned in to Mimir.
1. Remember to include your section, the date, project number and comments.
2. Please be sure to use the specified directory and file name.

Manual Grading
In lab05 you worked with Code Style. The TAs will apply the things that you learned in your Code Review lesson on the code you submit. 4 points are reserved (out of 104) for this.

Assignment Notes
1. Mimir allows us to test the functions in proj07_functions.cpp individually and we will do that.
2. We provide a pro07_main.cpp to test your code which you can modify for your own testing, but only proj07_functions.cpp needs to be turned into Mimir
3. proj07_functions.h is provided in the project07 directory. It will be used in testing. When we do testing, we will use the file we provide. If you change and submit your own version, Mimir will ignore your version and use the file originally provided.
4. Algorithms/iterators are your friends here! Check out the following:
a. set_intersection, things that are common in two sets
b. set_symmetric_difference, opposite of intersection (unique elements from each set).
c. copy_n, copy n elements from one set to another
d. the map.find function (different from the regular find, utilizes ordered search)
e. inserter iterator, adds elements to a map/set
f. be on the lookout for others as well. Let the algorithms do the work!

Reference no: EM132587278

Questions Cloud

Obtain a procyclical trade deficit : Using one of the models outline a possible explanation for the procyclical behavior of the trade deficit
Discussion on wireless networks : We looked at networks in general; however, in this discussion we're looking at wireless networks, mostly focusing on mobile networks.
What are the economic reasons for fuel taxes : 1. What are the economic reasons for fuel taxes being different in different countries?
Discuss differences between the types of regular expressions : Advanced Graphs in R-Studio. Discuss the importance of regular expressions in data analytics. Also, discuss the differences between the types of regular.
Write functions that add a user to a server : Write functions that add a user to a server, disconnect a user from a server, balance the server load, etc - manage a list of computer servers
Prepare the journal entry for the year-end adjustment : The Highlander Truck Company sold two heavy duty trucks to Zebra Corporation for $160,000. Prepare the journal entry for the year-end adjustment
Systems and quality assurance : Discuss how a systems analyst professional could stay current in industry standards for quality assurance and methods of managing systems implementation.
Would recommend that management invest in the equipment : 20% tax rate and using a discount rate of 8% when making investment decisions. Would you recommend that management invest in the equipment?
Beneficial in implementing the best decisions : Discuss and identify leader traits and attributes that are most beneficial in implementing the best decisions in an organization.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd