Qn 1. Write a complete C program (10 Marks)
Create a text file that contains three columns and ten rows. First column contains strings values,
second column contains integer values, and third column contains float values (you are free to use
your own values).
Declare a structure that contains 3 elements (you are free to use your own variables).
First element should be a char array – to read first column values from the text file.
Second element should be an int value – to read second column values from the text file.
Third element should be a float value – to read third column values from the text file.
Declare an array of this structure with size 10 and read the contents of the text file into this array.
Then prompt the user with the following instructions:
1: Display the details of the array – call a function to display the contents of the array on screen.
2: To sort the array (you should call sort function – output of the sorting function is written onto a
text file and terminal)
You should give the user the chance to sort in ascending or descending order with respect to
int value
Then you should give the user the option to select from different sorting techniques
(you should write minimum two sorting algorithm functions, call the functions
according to the choice the user enters – call the sorting function only after the user
selects the above mentioned options)
3: To search for a string element (Write the output on terminal)
You should give the user to select the searching technique (linear or binary – must use
recursive version of the searching functions)
if binary is selected call a sort function first
4: To insert these array elements into a linked list in the order of integer values. Display the contents
on the terminal.
5: Quit
Your complete program should have multiple files (minimum two .c file and a .h file).
Give your file name as heading and then paste your code. Do not forget to show the screen shots of
your text files as well.
Qn2. Write a complete C++ program (7 Marks)
Assume you are working as a programmer in a communication field. Your task is to alter the original
data before transmitting because of a security reason. All their data is an integer that contains the
number of digits between two and eight (inclusive), thus the possible integers are between 10 and
99999999. You must read in an integer and complete the following stages.
Stage 1:
Your task is to modify the data for transmission according to the following set of rules.
1. If the number is a two–digit number you swap the positions of the numbers (eg: if the number
is 56, altered number is 65).
2. If the number is a three–digit number, digits at positions 1 and 3 are swapped. (eg: number is
123, altered number is 321)
3. If the number is four digits or above the following rules apply.
Developing Technical Software
Replace the first digit (first digit is the rightmost digit in the number) by the remainder after the
sum of that digit plus 1 is divided by 10, the second digit by the remainder after the sum of that
digit plus 2 is divided by 10, third digit by the remainder after the sum of that digit plus 3 is divided
by 10, fourth digit by the remainder after the sum of that digit plus 4 is divided by 10 and so on.
Position of the number is counted from right to left.
5 9 1 5 4 2 3 9
………………………………………
Stage 2: Extra protection (done only on 8 digits numbers – if the user chooses this option)
Eight–digit data contains more valuable information, so you are asked to enable extra protection if
the user chooses to.
The extra protection is done on modified number in stage one by swapping the digit in position 1
with digit in position 8, digit in position 2 with digit in position 7, digit in position 3 with digit in
position 6, digit in position 4 with digit in position 5.
If the modified number in stage 1 is as shown below:
The number after stage 2 will look like:
Stage 3: (Decoding)
Once the encoding stages are over, write the codes to recover your original data from the encoded
data.
You can watch a video here to get the logic behind this question.
YouTube Video – https://youtu.be/k_02wM4v6To
Qn3. Write a complete C program – you must declare and use a self–referential structure for this
question (8 Marks)
You are asked to write a program for a mobile shop that handles the purchases through online. When
the customer places order to buy a mobile, the shop will search for the specific item upon customers
request in the order of first come first served basis. The items (mobiles) available in the shop are kept
in a text file called mobiles.txt (text file contains mobile id and name of the mobile).
2 3 4 5 6 7 8 9
9 8 7 6 5 4 3 2
Position 1Position 2Position 3Position 7Position 8
Developing Technical Software
At the beginning of the program the details of the mobiles are read from mobiles.txt
and stored in a LinkedList. Then the list of the mobiles ordered by customers is saved in a queue.
Then the program should take the order from the beginning (head) of the queue and search for it in
the LinkedList. If the item found in the list delete it and put this mobile in a stack to be able to retrieve
for the last mobile sold.
The main() function handles all interactions with the user and other functions:
• Calls a function named readMobile()which opens a text file mobiles.txt (a sample text file is
shown below) for reading and storing names of mobiles from the file to a LinkedList in order
of name (insertion should happen in alphabetical order).
• It then repeatedly calls the menu () function to display user options, get the user selection
returned by the menu() function, use a switch (or if ..else if) statement to process user request
by calling appropriate function(s).
Details of options in menu function:
(1) Display the current stock of mobiles– here you display the contents of the LinkedList
(2) Add a new mobile to stock – you need to insert a new mobile to LinkedList
(3) Display next order information – displays the next mobile in the order–list (first node of the queue)
(4) Display all orders – displays all nodes of the queue
(5) Add order to queue – adds new order to the end of the queue
(6) Process the next order – Processes the first order in the queue. This function searches for this
mobile in the LinkedList and deletes (if found) from LinkedList and puts it into a stack, deletes from
the queue as well.
(7) Cancel last order – It cancels the last processed order. It inserts the mobile (top of the stack) back
into LinkedList (mobiles is not added back into queue).
(8) Display info of last order – displays the information of the last processed order (top of the stack).
(9) Update mobiles file – updates the mobiles.txt with the remaining mobiles in the list (including the
mobiles added in option2).
Developing Technical Software
Assignment submission information:
Submissions through Canvas must be made on or before the due date/time.
Each submission should have two files.
1. A report (name of the report should be with your student number, eg:
1012546_assignment_2.docx) – use template provided with this assignment.
This report will be used for plagiarism check using turnitin software. 20% of marks will be
deducted if this report is missing for plagiarism check. Report must (.doc/docx) contain:
o Description of the problem, table etc.
o A copy of the contents of the .c file for all tasks (copy and paste the code not the
screenshot of the code).
o Pasted text output or screen shots of the working program resulting from the testing of
the program.
2. A .zip file (name of the zip file should be your student number, eg:
1012546_assignment_2.zip) containing:
a) The actual programs (c/C++ source codes) with comments. Programs must be named
studentid_A_Qn1.c, studentid_A_Qn2.c and so on.
Rubric – Check Assignment 2 page