Coursework – _Programming Assignment and In-Class Test
A. Core Coursework Assignment – _Hotel Program:
1. Using incremental development, design a program for a hotel with 10 rooms using an a
ay where each entry is the name of the main customer while the index represents the room number. Your code should allow the user to view the status of all rooms, to add a customer to a room as well as to initialise each room to empty by storing a specific character – say “e”.
Once the basic code runs, then put the code that ‘Views All rooms’ and ‘Adds customer to room’, into separate procedures, and test how it works. Then add a menu system, which allow the user to choose what they want to select. Enter an ‘I’ to initialise, an ‘A’ to add a customer to a room, and a ‘V’ to view all rooms. When an ‘A’ is pressed, it should do the Add procedure, or a ‘V’ should do the View procedure and so on.
B. Extras:
2. One by one, add extra procedures to do each of the following. The user should be able to choose from the menu below what the program does.
E: Display Empty rooms,
D: Delete customer from room,
F: Find room from customer name,
S: Store program data in to file,
L: Load program data from file.
O: View rooms Ordered alphabetically by the main customer’s name.
3. Create a second version of the program using hotel room a
ay of structs and/or objects.
Problem 1
Write a programme that defines two different namespaces (you can use the names of teammembers). Within each namespace define three variables:
double width;
double height;
double length;
and initialise them accordingly to the sizes of the rooms you live in. Use different techniques to print the values to the three variables from one or another namespace. Suggested techniques:
a) Use scope resolution operator :: in front of each variable used
) Use #define directive to change the name of the namespace (as in the example on the next page)
c) use using statement to access the appropriate namespace
Sample programme for solution b):
#include
namespace Helen
{
double length(3.5);
double width=2.3;
double height(2.5);
}
namespace Ro
{
double length=7.5;
double width=5.3;
double height=2.95;
}
using std::cout;
using std::endl;
#define nmsp Ro
int main()
{
cout
"The length of the room is "
nmsp::length
endl;
cout
"The width of the room is "
nmsp::width
endl;
cout
"The height of the room is "
nmsp::height;
eturn 0;
}
If time permits:
- use different techniques to format the output
- display information about the area of the floor of the room
- display information about the area of the walls of the room
- calculate and display information about the size of the room in cubic meters.
Problem 2
Write a programme calculating how many rolls of wallpaper is needed to decorate a room.
The programme should ask about and read information:
a) about the size of the room: width, length and height,
) about size of a single roll of wallpaper: width and length
c) if details of calculations should be presented
Then
d) perform all necessary calculations
e) if details of calculations are to be presented the programme should print:
i. total width of all four walls to be wallpapered
ii. the number of stripes of wallpaper needed for this room
iii. the number of stripes that could be obtained from one roll of wallpape
iv. the total number of wallpaper rolls needed for this room
f) if details of calculations are not to be presented the programme should print:
i. the total number of wallpaper rolls needed for this room
Use appropriate rounding up or down of various numbers to make sure that:
g) If a piece of wallpaper is used to cover the a gap that is na
ower than the width of
the wallpaper the remaining stripe is discarded rather then used
h) If a reminder of a roll is shorter than the height of the room then it is also discarded
ather than used to partially cover the next strip.
There are the following rounding function that you may consider for use: ceil(), floor() and
ound(). Type the name of the function in the text of your programme and press F1 to get
help information.
Problem 3.
Write a programme that declares two unsigned short variables and then reads their values
and shows the result of calculating:
the reminder of dividing one by another,
itwise “and” between the variables,
itwise “or” between the variables,
itwise “exclusive or” between the variables
shifting leftwards one of the variables by one, two, and three bits.
Check the programme results by performing manual calculations and making sure that you
esults are the same as those produced by the programme
Problem 4
Write two programmes that have the same functionality, i.e. they read two int numbers ?
and ?, and then calculate either:
the sum of all even numbers between ? and ? when ? < ?.
the sum of all number between ? and ? when ? ≤ ?
The first programme should be using a “for” loop to accomplish this task while the second
one should use the “while” loop.
None of the numbers ? or ? should be less than −10,000 or greater than 10,000. Request
the user to enter any of these numbers again if the value entered is from outside the
permitted range.
Problem 5.
Write a programme that reads two double numbers and then requests the code of
operation to be performed on these numbers. The operation should be either +, -, * or /.
Then it performs the operation and prints the result. If the operation code is not entered
co
ectly the programme should ask for it again but no more than three times. After three
attempts it should inform the user that the code was not entered properly and the
programme should terminate.
Problem 6
Write C++ code that prints out whether or not a thrill-seeking person standing in line for a roller coaster should be allowed on the ride. A pregnant person (usually she is a woman) is not allowed on the roller coaster. Additionally, an altitudinally-challenged (i.e., a short) person is not allowed on a roller coaster if the person is shorter than 48 inches.
If the person is not allowed on the ride, output the string "So
y".
Otherwise, output the string "OK: have fun!". Assume the following variables have been defined and initialized to the person's height and state of pregnancy:
int height;
holds the person's height in inches.
int is_pregnant;
is true if the person is pregnant.
Problem 7
Write a programme that reads an a
ay of 10 numbers of type double. Then
a. Prints all the numbers from the first one to the last one
. Prints the first, third and the last number
c. Prints all the numbers from the last to the first one
d. Prints every second number starting with the second read
e. Calculates and prints the average of all numbers
f. Calculates and prints the average of all non‐negative numbers.
Problem 8
Write a programme that reads three double numbers A, B and C.
a. Then it uses a pointer to access the values of each of the numbers and then prints each of them (still using the pointer).
. It calculates and prints the sum of the three numbers (still with use of the pointer)
Problem 9
A. Write a programme that takes as input a text file and prints its contents on the screen.
B. Write two collaborating programmes. The first one stores a sequence of numbers of type double in a binary format that are typed in by the user. The second programme opens the file, determines how many double numbers are stored in the file and then reads them into dynamically allocated memory block of suitable size and also prints them on the screen.
Problem 10
A. Write a function that prints a line of 20 stars:
********************
Use this function to print your name between two lines of stars. Put your name at the centre of the area marked by the stars. E.g.
********************
John Smith
********************
B. Write a function that takes two input parameters and does not return any value. The first parameter states how many times your name should be printed on the screen and the second one how many empty lines should be left between two consecutive printouts of your name. Both parameters should be of type int. In the main programme prepare a short dialogue with the user to let them decide the actual values of the parameters of your function.
C. Write two versions of a function calculating factorial of an integer number. The definition of the factorial is:
0! = 1
n! = (n-1)! ×n
Therefore:
0! =1,
1!=1,
2!=2,
3!=6,
4!=24 etc.
The first programme should calculate the factorial using a loop. The second version should use the recursive call where the factorial function calls itself with the decremented value of the argument.
Use this function to calculate factorials of selected numbers. The function should return unsigned long long number.
Problem 11.
The database storing collection of your books uses the records represented by the following Structure
struct a_Book
{
char Title[30];
char Author[30];
unsigned PublicationYear;
bool NotReadYet;
}
1. Write a programme that declares a variable of the type a_Book, initialises it and prints the values of all three its elements on the screen;
2. Write a programme that declares an a
ay of length 2 of variables of type a_Book, initialises both of them and prints them on the screen.
3. Write a programme that dynamically allocates memory to an a
ay to N variables of type a_Book, where N is a number entered by the user. Then the programme prompts the user to enter data for each book and prints it on the screen. Allow the user to have the data written to the disk before terminating the programme.
Scenario: Cld Hospital
Mr. Ha
y, the IT director at Cld Hospital, is responsible for managing the network. Mr. Ha
y has requested your help in proposing a network solution that will meet the hospital’s requirements. The hospital is growing (of course), and the management has released funds for network improvements.
Existing network:
The cu
ent network has ten segments that are connected to a single router which also serves the Internet. The router is running Routing Information Protocol Version 1 (RIPv1). The back-end new servers are located in the same segment as those used on floor 1. Mr. Ha
y mentions that users have complained of slow access to the servers. He also hands your team a table with