You are on page 1of 3

National Institute of Technology Calicut

Department of Computer Science and Engineering


B. Tech. (CSE) – First Semester
CS1091E: Programming Laboratory
Problem Set – 10

Submission deadline (on or before):


• 28/11/23, 5:00 PM
Policies for Submission and Evaluation:

• You must submit your programs in the moodle (Eduserver) course page,
on or before the submission deadline. Also, ensure that your programs
compile and execute without errors in the linux platform. During evalu-
ation, failure to execute programs without compilation errors may lead
to zero marks for that program. Detection of ANY malpractice can
lead to awarding an F grade in the course.

Naming Conventions for Individual Program


• P S < P ROBLEM SET N U M BER > < ROLLN O > <
F IRST − N AM E > < P ROGRAM − N U M BER > . <
extension > (For example: P S10 BxxyyyyCS LAXM AN 1.c).
Please make sure that you follow the naming conventions correctly.

Naming Conventions for Submission


• Submit a single ZIP (.zip) file (do not submit in any other archived
formats like .rar, .tar, .gz) containing the source code (.c file). The
name of this file must be P S < P ROBLEM SET N U M BER >
< ROLLN O > < F IRST − N AM E > .zip (For example:
P S10 BxxyyyyCS LAXM AN.zip). DO NOT add any other files (like
temporary files, input files, etc.) except your source code, into the zip
archive.

Standard of Conduct
• Violations of academic integrity will be severely penalized. Each student
is expected to adhere to high standards of ethical conduct, especially those
related to cheating and plagiarism. Any submitted work MUST BE an
individual effort. Any academic dishonesty will result in zero marks in the
corresponding exam or evaluation and will be reported to the department
council for record keeping and for permission to assign F grade in the
course.

General Instructions
• Programs should be written in C language and compiled using C com-
piler in Linux platform. Sample inputs are just indicative. Submit the

1
solutions to questions 1 and 2 as a single .zip file through the
submission link in Eduserver.

QUESTIONS
1. Using typedef, define a struct type named Student with fields rollnum
- a character array of 10 elements, marks (int) and result a character
array. Define functions with the following prototypes

printStudent(Student *s) //prints the individual members in a


//structure pointed to by s, all
//members in the same line with a
//single space separation between
//the members
assignResult(Student *s) // assigns a value for the result
//member in the structure pointed
//to by s, based on marks - “Pass”
//if marks>40 and “Fail” otherwise.
int isValidRollnumber(char *str) //returns 1 if str is a valid roll
//number and 0 otherwise.
The format of a valid roll number is BCS2 < d1 >< d2 >< d3 >< d4 >
where d1 is a digit in the range 0..3 and each of the last 3 characters is a
digit in the range 0..9. Create a variable st of type Student by reading the
values for rollnum and marks of a student. Invoke isValidRollnumber()
and print INVALID if roll number is not valid. If roll number is valid,
invoke assignResult() and then print the values of members of st by calling
printStudent(). You may use the library functions for string/character
manipulation, if required.
2. Store the results of a set of 5 students in an array of Students (same type
as in Qn. 1) by reading the values of rollnum and marks of each student.
For each roll number entered, invoke isValidRollnumber() to check if the
roll number is valid. If the roll number is invalid, the program should
print INVALID and repeatedly read rollnum till a valid roll number is
entered. Assign result for each student by invoking assignResult() (same
as in Qn. 1) for each array element. Invoke a function with prototype
void PrintPassed( Student [ ]); to print the roll numbers of students who

2
passed the exam (each roll number in a separate line). You may use the
library functions for string/character manipulation, if required.

3. Practice question (to be done after the class on 28th) - do not


submit
Write C programs to do the following file operations. The name of the
text file should be given as a command line argument.
(a) Read the contents of a file, one character at a time and print each
character.
(b) Read a sequence of characters from the keyboard and write each
character to a file.

You might also like