ICP Assignment Document PDF
ICP Assignment Document PDF
INSTRUCTIONS TO CANDIDATES:
1. Submit your assignment online in Moodle unless advised otherwise.
2. Late submission will be awarded zero (0) unless Extenuating Circumstances (EC)
are upheld.
4. You must obtain at least 50% in each component to pass this module.
Table of Content
2.1 Pseudocode
4.0 Conclusion
5.0 Reference
1.0 Introduction and Assumption
A complete telephone operator system must contain different types of features such as adding
new employees, searching employee’s extension number, updating new numbers for employees,
classifying different departments, etc. According to figure 1, there will be five departments in the
university, each department will be available for a thousand employees inside which means there are
also thousands of extension numbers available to use.
The university is in the scaling phase, and it only has twenty-five employees inside. To record
all the information, there will only require one text file. Inside the text file, there will record four data,
which are, employee name, id, department name, and extension number. When initializing the input, the
program will use the structure to store the data into a list form then store into a text file directly. After
the list is completely generated, it should be able to use the program to open to read, write, or append.
Firstly, there should be ten employees already working in the university, so in the beginning will
input the existing employees by using structures. Secondly, the users should be able to search and update
the employee extension number by input their name and id number. Next, the university is in the scaling
phase, so the system should be allowed to add the new employee into the text file. Lastly, the text file
was adding those employees’ information randomly, so the order of every department must be in a mixed
order. A list must be in a neat status, so it should require sorting those mixed data in every department
stays together. Since, every department has their representative digit, so it should sort those digits in
ascending order. All features should be arranging into a menu function and allowed users to choose
them.
2.0 Design of the program
2.1 Pseudocode
2.2 Flow Chart
START
START
End
END
Menu function
menu()
Read choice
Read i
True
case A
Input break
case a
False
True
case B
Search break
case b
False
True
case C
Add break
case c
False
True
case D
Update break
case d
False
True
case E
List break
case e
False
default Print
"Invalid input.
Adios.
END
Input function
Input()
False True
fp NOT =
NULL
Writeexit
"\n"to into
1 file
True
DO i = 0 TO False
size
exit to 1
Print "\n"
exit to 1
Print "\n"
Flush output buffer
Close fp
Get string emp[i].no
END
Print "Enter name: "
exit to 1
Print "\n"
exit to 1
Print "Enter name or id: "
exit to 1
Read name_id
False True
fp NOT =
NULL
Print "File
unreadable."
True DOWHILE (fp not False
pointing to end-of-
file)
exit to 1
Print content
num = 1
break
Close fp
END
Add()
Add function
False True
fp NOT =
NULL
True
DO i = 0 TO False
size
exit to 1
Print "\n"
END
Print "Enter name: "
exit to 1
Print "\n"
Define fp as filename
Search
exit to 1
Print "Enter old number: "
exit to 1
Read old_num
exit to 1
Print "Enter new number: "
exit to 1
Read new_num
rep
END
Close fp
REMOVE filename
RENAME ftemp
as filename
exit to 1
Print "Update successfully !"
Define fp as filename
exit to 1
Display content
Close fp
END
List function List()
Declare
Declare content as
content as empty
emptycharacter
character
False True
fp NOT =
NULL
True DOWHILE
DOWHILE (content(content
NOT = END-OF- False
FILE)
NOT = END-OF-FILE) exit to00
exit to
Display array
Open fp in read mode
Display content
Close fp
END
Replace function
Comparator function
comparator(str1, str2)
Menu function:
Input function:
The structure of employee will declare as emp and the emp will be an array. It will use in the loop
condition. For example, if user types 5, then loop will stop until five employee details written.
Search function:
Add function:
Update function and replace function:
This program will declare two file pointers, but one of them will be a temporary file. The temporary
file will record the new content then rename as the original file when the original was remove. The
replace function will copy the current line which to require variable. Then, the replace of new word
will place to the current line, next will need to concatenate the rest of the current line data which
include the backup data, the index of old word and the length of old word to complete a new replace
data (C program to find and replace a word in file - Codeforwin, 2021).
*tmpfile() function is defined in the “stdio.h” header file. The temporary file will atomically deleted
after termination of program.
List function and comparator function:
This function will need to read the formatted string in every line then loop in purpose. When comes to
the comparator function, it will compare the string in each of the line specific string. In this case, it
will compare the extension no itself and sort those data in ascending order (Comparator function of
qsort() in C - GeeksforGeeks, 2021).
3.1 Sample of output
Figure 3.1.1
According to figure 3.1.1, if type other than choice from A to E or, a to e, the program will jump
directly to default and end the program.
Figure 3.1.2
When type a, the program will create and write a file name tel.txt, input extension number, name, id,
department name then records into the file.
Figure 3.1.3
The program will need user to input employee name or id to search the information.
Figure 3.1.4
The program able to add the new employee information into the text file.
Figure 3.1.5
The update program will able to search the employee information and input the extension no to renew.
Figure 3.1.6
The sort of program will sort the extension number. Because the department have their representative
number. The end of this program will display and rewrite the sorted data.
4.0 Conclusion
The university will need the telephone operator system to organize the extension no and basic
information of employee. Due to the university still in the education and business scaling phase, the
must be a lot of preparation cannot be ignored.
In the future, the university will be growing and growing for no doubt. This telephone operator
system can be used for more longer than other temporary system because the amount of employee
limitation will be one thousand. The one thousand space can be extended as sub-department. For
example, visa department have a sub-department and fifty employees. The representative digits of visa
sub-department will be same as visa department, but the number behind the only digits will be different.
In addition, there are fewer pitfalls for the program. Firstly, it would be troublesome if the
program cannot remove the employee who no longer work in the company. Secondly, although the
program can be able to put one thousand amounts of employees’ information but it just one text file
there, it would be uneasy to manage the whole bunch of information.
In conclusion, the program was existed both advantages and setbacks. In the future, the program
should be improved more useful features to cover more possible situation. It could be generated more
text file to record the employee information or adding a removing specific data feature, etc. There are a
lot of possibility inside the programming.
5.0 Reference
3. Codeforwin. 2021. C program to find and replace a word in file - Codeforwin. [online] Available at:
<https://codeforwin.org/2018/02/c-program-find-and-replace-a-word-in-file.html> [Accessed 18 February
2021].