National University of Sciences and Technology (NUST) CS-114 Fundamentals of Programming
National University of Sciences and Technology (NUST) CS-114 Fundamentals of Programming
(NUST)
CS-114 Fundamentals of Programming
Introduction:
1
This program is designed for the maps of different
apartments. The maps are designed according to the number of
bedrooms that what the customer would like to have. Condition is that
he/she must select bedrooms from 1-4. The program will then display
the map. Different functions and operators are used in this code.
Problem Statement:
Make a bedroom selection program which asks
the user the number of rooms required (bedroom numbers can be
hardcoded) and once the number of rooms are selected, output a
display showing how it looks.
Allow an option so the user can view the bedroom with window and
view the front view of the apartment. In case the user may not like
their selection they should be able to change the design.
Methodology:
2
Step 1:
For instructions, file handling is used since all the instructions are
written in an alternate file and has to be called. Then with a logical
operator it checks to see if the file reads and then proceeds to a while
loop with an imbedded function getline to read a line of text from the
stream into the string.
Step 2:
Step 3:
Step 4:
For viewing design 1,2,3,4 a separate file for each design was made and
then by using file handling, logical operator and getline function exactly
like how instructions was outputted these designs would be.
Step 5:
User is then prompted 4 more options for bed view, apartment view,
changing design and exiting. In the same rubric followed in for
instructions & viewing design, the bedroom view and front apartment
is outputted.
3
However, for changing the design it will prompt the user asking what
new design they want and then go back to step 4.
Flow Chart:
Welcome to home Type in 1 or 0 to The numbers of
designs continue bedrooms we have
are 1,2,3,4
4
If typed in (0)
If typed in (3)
takes back to
the home
page
If typed in (2)
displays the main
door view
Valid
number
Code Description:
Invalid
Line 1-2: number
5
This is the beginning of code and line one function is that it uses the objects cin , cout
etc. While the fstream is used to read the other files attached with the code.
Line 8-16:
This part of code shows the start of the program where it displays ‘HOUSE DESIGNS’ the
function if stream is used to read the file named ‘info’ Then we apply a condition as to if the file
opens meaning if the console is able to read from the file then, it will output the string until the
loop ends And at the end we use readme.close() to stop reading from the file exiting design 4
function.
Line 18-28:
Over here if char is used and only single letter is going to be typed in and if it is 1 the
program will continue and if 0 is typed in it will end. ‘If else statements’ are used here.
Line 30-46:
6
This is the part of code where the user will be asked how man bedrooms he want and
because user will have to enter a value between 1 to 4 we used the ‘if’ statement to make the
condition and after that we used the ‘do-while’ loop so that the user continues to input the
valid number until the condition becomes true. If any other number is typed in the user will be
asked to input the value again and while he/she enters the correct number the program
proceeds.
Line 47-49:
The system clear function is to clear the screen before it gives the user the display of
his/her map that he has selected.
Line 50-66:
After the user has typed in his/her desired number this part of code displays the loading
screen where we used the ‘sleep’ function to pause the system for 1000miliseconds and the
design pops up before them. It’s kind of animation.
Line 67-79:
7
This is for when the user selects option 1.We use the function ifstream to read from a
file with the name design 1 and assign the ifstream with a name readme Then we apply a
condition as to if the file opens meaning if the console is able to read from the file.Getline() is a
function used for reading a string. readme acts as cin operator and line is the name assigned to
the string. Thus, it will output the string until the loop breaks. And at the end we use
readme.close() to stop reading from the file exiting design 1 function.
NOTE: from line 80-120 the function used is same as used in line 67-79 just the design is
different.
Line 122-128:
After the user has typed in and seen his desired design he/she will be given further more
three options to view the house from different angles. We used ‘while’ so that if he does not
type in 0 he will be able to see the other options results and on typing 0 the program will end.
System clear is also used here again as to clear the screen before the user the sees the next part
of the program.
Line 129-141:
8
If the user has typed in 1 he/she will be able to see the view of bedroom and again
ifstream is used to read the from the file name ‘view of bedroom with window’ and the
condition is applied if the file opens meaning if the console is able to read from the file. Getline
is usded for reading the string readme acts as cin operator and line is the name assigned to the
string. Thus it will output the string until the loop breaks.
Line 155-172:
This is part of code is designed d that if after the user has seen one map of home and
he/she wants to switch to other design they can by typing in 3 and the same options will be
displayed infront of them as it was in start. Once again ‘if statement ‘ is used and do while loop
is in use until the condition becomes true the program will continue running until the valid
number has been typed in.
10