Icp Mohamed Bakri Osman
Icp Mohamed Bakri Osman
Icp Mohamed Bakri Osman
_____________________________________________________________________________________
__________________________________________________________
CT018-3-1-ICP INTRODUCTION TO C PROGRAMMING
INDIVIDUAL ASSIGNMENT
NAME:
MOHAMED BAKRI OSMAN
INTAKE: APU1F2009PE
Table of content:
I. List of Figures…………………………………………………………2
II. Introduction………………………………...………….………………3
III. Objectives…………………………………………………….………..4
IV. Assumptions………………………………………………….………..5
V. Design of the Program…………………………………………………6
VI. Code Demonstration………………………………………..…………10
VII. Output Sample………………………………………………..……….17
VIII. Flowchart…………………………………………………..………….19
IX. Pseudocode…………………………………………………………….26
X. Conclusion……………………………………………………………..32
XI. Reference………………………………………………………………33
I. List of Figures
a) Figure 1………………………………………………….……………6
b) Figure 2………………………………………………….……………7
c) Figure 3………………………………………………….……………8
d) Figure 4………………………………………………………………17
e) Figure 5………………………………………………………………17
f) Figure 6………………………………………………………………17
g) Figure 7………………………………………………………………18
h) Figure 8………………………………………………………………18
i) Figure 9………………………………………………………………19
j) Figure 10………………………………………………….…………..20
k) Figure 11………………………………………………..…………….22
l) Figure 12………………………………………………..…………….24
II. Introduction
COVID-19 is a coronavirus illness caused by the December of 2019 SARS-CoV-2. COVID-19
can be serious and have caused millions of fatalities in some survivors of the disease worldwide,
as well as long-term health issues. Coronavirus may spread by individuals. A laboratory test is
diagnosed.
Prevention requires separating yourself from physical activity, mask use, cleanliness and keeping
away if you feel unwell.
The file contains various columns including Vaccine name, code, producing country, the dosage
required and the population covered.
The task is to read the file, update some changes, display the new details. Also, users can search
for any vaccine using the vaccine code for newly detailed data.
Vaccine: It is an agent that activates the immune system and protects against pathogen
microorganisms. The composition of the vaccine includes inactivated, weakened or killed
microorganism. when the vaccine is introduced into the body, the immune system secretes
antibodies against these inactivated or killed microorganisms. Secreted antibodies protect the body
against dread full diseases.
Live Vaccines: These types of vaccines are prepared from live organisms. The live organism
chosen for producing the vaccine is subjected to pass through the chicken embryos and other media
to reduce the capability the causing disease. when this vaccine is introduced into the human body,
it produces a defense mechanism against microorganisms. Live vaccines are more active against
the inactivated vaccines. Live vaccines are not preferred towards pregnant women.
First of all, the file has been opened and read. We also checked a condition that if the file contains
nothing, we would say the file is unfamiliar.
• create_inventory ();
• display_vaccine ();
• search_vaccine ();
The create_inventory (); function is used for writing and updating data.
The display_vaccine (); function is used for displaying the updated data.
search_vaccine (); function is used to search the new details of vaccine from the available ones.
Users can call any functions to write, update, display and search the details of vaccines. The latest
data can be again saved in the same file.
I. Objectives
3- To Inventory Creation.
IV. Assumptions
• The name of the vaccine cannot be greater than 15 characters in length.
• The file used for reading and writing operation exists in the same folder as the one where
the .c file is present. This is because complete path of the file is not used for opening it.
• Assumption is made that the user will give either input 1 or 0 for pursuing. Invalid option
is not taken into consideration like a string input or decimal input.
• It is assumed that the file Vaccine.txt file is initially empty. No content is present there
from before.
Since these are the assumptions of the code, any deviation from the assumptions made will result
in an error in the code.
Therefore, proper handling of the input and field validation for the above scenarios will improve
the quality of the code.
The create_inventory () function allows the user to write the updated data in the "vaccine.txt" file.
The user can write the data for each vaccine until he/she press 0.
The display_vaccine () function will read the data from the create_inventory () function and
displays the new data. %15s is used to display only 15 characters of the string.
The search_vaccine () function will take input the vaccine_code (code) from the user. The
function will match the vaccine code. Here is how it will match.
strcpy (temp, vcode); --> It means the function first copy the user entered vcode and stored in
temp
Now, the function will read every data that the user entered to display the matched vaccine code
details.
temp [0] = A
temp [1] = Z
vaccinecode[0] = A
vaccinecode[1] = Z
Hence, we can say vaccinecode [0] == temp [0] and vaccinecode [1] == temp [1]
#include <stdlib.h>
#include <string.h>
// Function Declarations
int search_vaccine();
int main ()
display_vaccine ();
search_vaccine ();
//update_vacc_qty ();
return 0;
void create_inventory()
int option = 1;
char vaccinename[15];
char vaccinecode[2];
char country[15];
int dosage;
float populaion;
//File definition
FILE* infile;
Step 2
//Accepting data from user from keyboard till user enters 0 to close
while (option != 0)
scanf("%s", vaccinename);
scanf("%s", vaccinecode);
scanf("%s", country);
scanf("%d", &dosage);
scanf("%f", &populaion);
scanf("%d", &option);
if (option == 0)
void display_vaccine()
char vaccinename[15];
char vaccinecode[2];
char country[15];
int dosage;
float populaion;
FILE* infile;
int search_vaccine()
char vaccinename[15];
char vaccinecode[2];
char country[15];
int dosage;
float populaion;
FILE* infile;
char vcode[2];
char temp[2];
int value;
scanf("%s", vcode);
strcpy(temp, vcode);
//checking user entered vaccine code and available in the file is same
*Here add more comments in first step1 . Run the code and get output.
2. void update_vacc_qty
When call update_vacc_qty () method it will ask user to update current existing vaccinated
person data like.
3. int search_vaccine
When call search_vaccine () method it will ask vaccine code to retrieve the data from
"vaccine.txt" file.
if vaccine code exist in file, it will retrieve otherwise return Not exist record in file.
4. void display_vaccine
When call display_vaccine () method it will display the all-persons data who are get vaccinated.
User wants to check vaccine with code 2 as vaccine with code 2 is present that details will be
displayed.
If no vaccine present of that code it comes out of execution. [vaccine with code 3 is not there
thus came out of execution.
VIII. Flowchart
1-Main
2-Function call display_vaccine () for printing output and displaying the details.
2-Create inventory.
1.Declaring of variable for storing values for option and giving by default the value.
2.Declaring of string types vaccine name, vaccine code, country where we enter the vaccine details
like name code and which country.
3. Declaring dosage and population as number type where dosage represents the no of times to
take vaccine and total count of population.
4.Vaccine.txt code for storing the values typed so that it is enabled for writing and inserting data.
5.Checking for the condition if it is true or false option if the option is 0 then it for exiting and
close the file and stop.
6. If option is equal to zero then it is true and we are supposed to close the file and then return.
7.If it becomes option 1 then prompt window opens and asks to enter the vaccine details as input.
10.If the user enters 0 then it leads to exit the window and out of the loop.
11.Again allowing to repeat the same process like loops if enters 1 then to allow the user to enter
the input and repeat from the step 7 again.
3-Display vaccine.
1.Declaring of string types vaccine name, vaccine code, country where we enter the vaccine details
like name code and which country.
2.Declaring dosage and population as number type where dosage represents the no of times to take
vaccine and total count of population.
3.Vaccine.txt data to be displayed and enabling it only in reading mode for reading so that no
editing is enabled.
5.Checking for next line not null so that it is condition for going till the end of the file and to
prevent it is not causing any error.
6.If next line is not null is true then it will print all the vaccine details and move to the next line
7. Checking next line is also not null and repeat the same process till the end.
4-Search Vaccine
1-Declaring of string types vaccine name, vaccine code, country where we enter the vaccine details
like name code and which country.
2.Declaring dosage and population as number type where dosage represents the no of times to
take vaccine and total count of population.
3.Vaccine.txt data to be displayed and enabling it only in reading mode for reading so that no
editing is enabled.
4.Declaring variables vcode for storing vaccine code and temp to store temporary values and are
of string type.
5.Prompt window appears and asks to enter the user to enter vcode.
6. Taking input from user to insert vcode of which details to be searched for.
7. Checking for next line not null so that it is condition for going till the end of the file and to
prevent it is not causing any error. That is until the end of the file.
8.If true then in the next step vaccinecode is checked whether it is equal to the vcode and if they
are equal the data will be fetched.
9. If true condition with vaccinecode and vcode details of current line are fetched if not found then
it will move on the next line and repeat from next line not null.
11. Return.
IX. Pseudocode
1-MODULE is sub-function and it starts from MAIN
START ; main starts here
CALL create_inventory ()
CALL display_vaccine ()
CALL search_vaccine ()
END MAIN;
DECLARE option = 1
; variables to collect data as per table given
DELCARE vaccinename, vaccinecode, country as strings
DECLARE dosage and population as number
READ: vaccinename
READ: vaccinecode
READ: country
READ: dosage
READ: population
CLOSE FILE
END IF
END REPEAT
END REPEAT
END MODULE
IF (vaccinecode = temp)
END IF
END REPEAT
CLOSE file
END MODULE
• Step 1
Start main:
1.Here is the main function which has the call functions of different functions like.
Call create_inventory ()
Call display_vaccine ()
Call search_vaccine ()
All calls for function definitions like it will call all modules are done here.
• Step 2
Create_inventory:
1.Start module create_inventory () getting into thee function definition whenever it is being
called.
3.Declaring of variables of string type in order to store vaccine name, vaccine code, country.
4.Declaring of variables of number type that are like dosage and population as they are of
numerical.
5.Opening the file in the writing mode so that we can edit and write the contents to the file.
6.Repeat the process until reached the end of the file or closing the file and exiting by entering
zero until it becomes zero it will be repeated.
7.Reading the input from user like vaccine name, vaccine code, country, dosage, population.
8.Writing that information into the file line by line and after entering single line moving to the
next line.
9.Taking option input from user if user enters zero then it enters into the closing file and the file
gets closed and out of the repeat if user enters the 1 then it will move to step 6 and repeats the
process until the user enters zero.
10.End if.
11.End Repeat and ending the module i.e. the function definition.
• Step 3
Module display_vaccine():
2.Declaring of string type variables in order to take assign values and display those values i.e,
vaccinename, vaccinecode, country.
4.Opening of the file in the reading mode so that the user can only ready without any writing as it
is needed to display the information not the writing of the information.
5.Printing the details of all things line by line initially putting the heading so that it should be
displayed in the tabular form.
7.Printing all details of vaccine line by line and moving to the next line.
• Step 4
2.Declaring of string type variables in order to take assign values and display those values i.e,
vaccinename, vaccinecode, country.
4.Opening of the file in the reading mode so that the user can only ready without any writing as it
is needed to display the information not the writing of the information.
5.Declaring of vcode and temp string type so that the user can enter the vaccine code that needs
to be searched.
9.Repeating the search process until reached the end of the file.
11.Printing of the current vaccine details that are matching with the searched vaccine code.
12.End if.
X. Conclusion
All in all, the program has utilized solid and fundamental C programming capabilities, such as the
loop, which allows the same operation to be repeated and null is an integrated constant with zero
values. It corresponds to the character 0 in C, which is used to terminate strings.
In its most basic form, a preprocessor takes a C programmer and generates another C programmer.
The product programmer does not process lines beginning with #, but handles all of them in the
preprocessor. The preprocessor transfers the pre-processed h-code to both the design and the file.
The files (h) are also referred to as C-header files. In the majority of situations, these header files
contain function statements. Printf is the single function of the stdio.h programmer ().
The program is capable of reading a file called "vaccine.txt" and updating some data changes. The
program has a function called display vaccine () that may show the updated information. Using
the vaccination code, the software may look up any vaccine information. Finally, the software may
save the file with the freshly modified data. Based on user input, the provided code modifies the
vaccine's information. Furthermore, users may check vaccine data will be supplied if accessible;
execution otherwise will be discontinued. And any immunization information provided by the user
is stored in a text file.
The execution of the compiled C programmer must begin from the beginning. In C, the first
significant line is generally performed first. The void in parentheses indicates the lack of a
parameter in the main. It is also possible to supply arguments to Main (). In future publications.
The int typed before main indicates the return main type (). Basic's output indicates the condition
of the programmer. C is one of the most extensively used programming languages in history, and
it is used in virtually all computer architectures. C impacted several other well-known
programming languages, notably C++, which started as a C extension.
XII. Reference
1- Docs.ansible.com. (n.d.). Developing dynamic inventory — Ansible Documentation. [online]
Available at: https://docs.ansible.com/ansible/latest/dev_guide/developing_inventory.html.
2. SQL Shack - articles about database auditing, server performance, data recovery, and more.
(2018). SQL Substring function overview. [online] Available at: https://www.sqlshack.com/sql-
substring-function-overview/ [Accessed 26 Jun. 2021].
6.www.mathworks.com. (n.d.). Close one or all open files - MATLAB fclose. [online] Available
at: https://www.mathworks.com/help/matlab/ref/fclose.html.
10- Munoz, D. (2015). After All These Years, the World is Still Powered by C Programming.
[online] Toptal Engineering Blog. Available at: https://www.toptal.com/c/after-all-these-years-
the-world-is-still-powered-by-c-programming.
11- www.cs.uic.edu. (n.d.). C Programming Course Notes - Functions. [online] Available at:
https://www.cs.uic.edu/~jbell/CourseNotes/C_Programming/Functions.html [Accessed 28 Jun.
2021].