c programming
Question Paper M20 DipIT04 A1 CW Resit QP
A1 Coursework Question Paper
Module Code: DipIT04
Module Title: Introduction to Programming-I
Module Leader: Subiran Shrestha
Submission Deadline: 1 November 2020 (04:00 pm)
Coursework Type: Individual
Coursework Weight: This Coursework accounts for 40% of your total grade.
Submission Instructions Submit the following to iAcademy RTE department before the deadline:
● Zip file of C source code of all the programs.
● Demonstration Video
Warning: iAcademy takes plagiarism very seriously. Plagiarised source codes will
be awarded zero marks
Guidelines for the Coursework:
● There are 8 questions in total that you have to solve and each question carries equal marks (4).
● You have to write the C source code for each question and submit the source code for all the 8
questions.
● You are also required to submit a demonstration video.
● The video can be made on any one of the 8 questions. (There are 8 questions available and you
can choose any one question for the demonstration purpose).
● You are required to verbally explain the purpose of each line as you are typing.
● The video should be 4-10 mins long.
● The weightage of the video is 8 marks.
● The video must be uploaded to www.youtube.com with your college ID and the link should be
submitted in the link of form below:
https://docs.google.com/forms/d/e/1FAIpQLScTPvJVR7BBGuA_zk2H4tKeeDEZ89oAlMpu9Q
APT-PT_f-Ssg/viewform?usp=sf_link
Question Paper M20 DipIT04 A1 CW Resit QP
Each question carries 4 marks. (8*4=32 marks)
1) Write a C program to reverse each word in a sentence. You must pass the string to a function
named reverseString that reverses the string and then display the reversed string in the main.
Output:
Enter a String: Hello World
Reversed String: World Hello
2) Write a program to read an integer number, count the even digits and odd digits present in the
entered number. You must write a function (only one function) for calculating the result and
the result must be displayed in the main function itself.
Output:
Enter a positive integer number: 12345
Number of odd numbers=3
Number of even numbers=2
3) Create a structure named marks that has subject and mark as its members. Create another structure
named student that has name, roll, marks and remarks as members. Assume appropriate type and
size of members. Include the first structure as a member for the second structure and the structure
named student must have provision to store marks of three subjects for each student.
Write a program to open a file, read data of 10 students from the user and write them to the
file. After writing, display the content of the file.
4) Consider the following algorithm:
a. Start with a positive integer n
b. If n is even then divide it by 2
c. If n is odd then multiply by 3 and add 1.
d. Continue this until n becomes 1
The Guthrie sequence of a positive number n is defined to be the numbers generated by this algorithm.
For example, the Guthrie sequence of the number 7 is: 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4,
2, 1
It is easy to see that this sequence was generated from the number 7 by the above algorithm. Since 7 is
odd, multiply by 3 and add 1 to get 22 which is the second number of the sequence. Since 22 is even,
divide by 2 to get 11 which is the third number of the sequence. 11 is odd so multiply by 3 and add 1 to
get 34 which is the fourth number of the sequence and so on. Note: the first number of a Guthrie sequence
is always the number that generated the sequence and the last number is always 1.
Write a function named guthrieSequence that prints the GuthrieSequence of any number entered
by the user.
Question Paper M20 DipIT04 A1 CW Resit QP
5) An array is called vanilla if all its elements are made up of the same digit. For example {1, 1, 11,
1111, 1111111} is a vanilla array because all its elements use only the digit 1. However, the array
{11, 101, 1111, 11111} is not a vanilla array because its elements use the digit 0 and 1.
Write a function named isVanilla that returns 1 if its argument is a vanilla array. Otherwise it
returns 0. Use this value in the main to print whether an array is a vanilla array or not.
Output 1:
Enter the array: {1,22,33,586}
The array is not a vanilla array.
Output 2:
Enter the array: {9,999,99}
The array is a vanilla array.
6) Write a program that adds the individual rows of a two dimensional array of 3*3 and store the
sum of rows into a single dimensional array using functions. You must create a function that
takes a two dimensional array and one dimensional array and processes the result and stores it
in one dimensional array.
7) Write a program that reads an array of strings and sorts them in alphabetical order without
using any string handling functions.
Output:
Enter five strings: abq
abt
abs
abd
mno
Strings in sorted order are:
abd
abq
abs
abt
mno
8) An array is called centered-15 if some consecutive sequence of elements of the array sum to 15 and
this sequence is preceded and followed by the same number of elements. For example {3, 2, 10, 4, 1,
6, 9} is centered-15 because the sequence 10, 4, 1 sums to 15 and the sequence is preceded by two
elements (3, 2) and followed by two elements (6,9).
Write a method called isCentered15 that returns 1 if its array argument is centered-15,
otherwise it returns 0.
Examples:
a. If the array is {3,2,10,4,1,6,9} then it returns 1 because the sequence 10, 4, 1 sums to 15 and is
preceded by 2 elements and followed by 2 elements. Note that there is another sequence that
sums to 15 (6,9}. It is okay for the array to have more than one sequence that sums to 15 as long
as at least one of them is centered.
Question Paper M20 DipIT04 A1 CW Resit QP
b. If the array is {2,10,4,1,6,9} then the method returns 0 because (10, 4, 1) is preceded by one
element but followed by two. (6,9) is preceded by five elements but followed by none. Hence
neither qualify as centered.
Question Paper M20 DipIT04 A1 CW Resit QP
Marking Scheme:
Total: 40 marks
Title Marks Total marks
Programming Questions (8) 4 32
Demonstration Video (1) 8 8