0% found this document useful (0 votes)
7 views

PDLAB_Assignment1a_Updated

This document outlines the assignment details for the CS1092E Program Design Laboratory at the National Institute of Technology Calicut, including submission guidelines, standards of conduct, and specific programming tasks. Students are required to write C programs for various problems involving linear and binary search on arrays and structures, with strict naming conventions and adherence to academic integrity. The assignment must be submitted as a single ZIP file by January 13, 2025.

Uploaded by

Man Killer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

PDLAB_Assignment1a_Updated

This document outlines the assignment details for the CS1092E Program Design Laboratory at the National Institute of Technology Calicut, including submission guidelines, standards of conduct, and specific programming tasks. Students are required to write C programs for various problems involving linear and binary search on arrays and structures, with strict naming conventions and adherence to academic integrity. The assignment must be submitted as a single ZIP file by January 13, 2025.

Uploaded by

Man Killer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

National Institute of Technology Calicut

Department of Computer Science and Engineering


Second Semester B. Tech.(CSE)
CS1092E Program Design Laboratory
Assignment #1_a
Submission deadline (on or before): 13/01/2025, 8:00a.m
Naming Conventions for Submission
• Submit a single ZIP (.zip) file (do not submit in any other archived formats like .rar, .tar,
.gz). The name of this file must be

ASSG<Number><ROLLNO><FIRST-NAME>.zip
(Example: ASSG1_ B240123CS_NEEMA.zip). DO NOT add any other files (like temporary f
iles, input files, etc.) except your source code, into the zip archive.
• The source codes of each question must be named as
ASSG<Number><ROLLNO><PROGRAM-NUMBER>.c
(For example: ASSG1_ B240123CS_1.c).
Standard of Conduct
• Violation 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.
The department policy on academic integrity can be found at:
http://cse.nitc.ac.in/sites/default/files/Academic-Integrity new.pdf.
General Instructions
• Programs should be written in C language.
• Check your programs with sufficiently large values of inputs within the range as specified
in the question.
• Global and/or static variables should not be used in your program.

Questions

1. Linear Search on arrays

Write a C program to find the unique integer in an unsorted array of integers where every
integer repeats twice or thrice, except for one integer that appears exactly once. Print NO if
the array is not in such a format. You need to implement this solution using linear search
either in an iterative or recursive solution.

Input specification:

● The first line contains array size n (1 ≤ n ≤ 100).


● The second line contains n unsorted integers separated by a single space.

Output specification:
● print the integer that appears exactly once; print NO if the array is not in such a
format.

Sample input 1:
13
25 50 71 71 50 23 71 50 23 72 71 50 25

Sample output 1:

72

Sample input 2:
7
9797696

Sample output:

NO

2. Binary Search on Arrays

A Maruti Suzuki car showroom displays the cars in sequential order based on their price in
lakhs in non increasing order. Whenever a customer visits the showroom with their desired
price to buy a car, the showroom supervisor requests the staff to take the middle car (if the
number of cars is even, take the middle as the last car in the first half) for a test drive with
customers to satisfy them with medium price. This process will go until they reach the
expected price of the customer with the desired half of the cars or it may stop if there is no
car with the desired price of the customer.

Please help the supervisor by writing a C program to print the number of test drives with
customers until they reach their targeted price or otherwise NA with the number of test drives
if the targeted price is not available.

Input Specification:

First line contains the integer n(1<=n<=20) indicates the number of cars.

Second line contains the n integers representing the price of the cars in Lakhs in
non-increasing order separated by a space.

Third line contains the customer price K in Lakhs.

Output Specification:
Prints the position of the car in the order of the arrangement along with the number of test
drives, otherwise it prints NA and the number of test drives taken till that time.

Sample Input1:
10
27 25 22 21 19 17 15 14 11 4
22
Sample Output1:
33

Sample Input2:
10
27 25 22 21 19 17 15 14 11 4
13
Sample Output1:
NA 3

3. Linear Search on Structures

Write a C program to perform a linear search on an array of structures containing student


details. Each structure contains the following fields:

● rollno (integer)(100≤rollno≤250): The roll number of the student


● name (string): The name of the student (up to 20 characters)
● subject (string): The subject studied by the student (up to 10 characters)
● marks (integer)(0≤marks≤100): The marks obtained by the student

The program should:

1. Allow the user to input details of n students.


2. Allow the user to perform the following operations:
The user has a menu-driven program as mentioned below:
3. r - search for a student by his/her roll number and display their details separated by a
comma in a single line if found, otherwise display -1.
4. s - search for a student by his/her subject and marks, display the student’s name
having the given marks in the specified subject, otherwise display -1.
5. e - exit the program.
Perform the chosen operation from the menu and print the result until the user types the
alphabet e.

Input specification:

● First line contains an integer N that indicates the number of student records.
● Second line starts reading N records of the student details in the mentioned order
rollno, name, subject, and marks separated by comma and each record is separated
by a new line. You may assume that the input is according to specifications.
● The menu-driven options are applied from N+2 line onwards as given operations in
the following format:
Menu:
r : search for a student record by ‘rollno’
s: search for a student record by ‘subject’ and ‘marks’
e: exit from the menu

Output specification:
● If the user's operation choice is ‘r rollno’, print the corresponding student’s record that
matches the entered roll number separated by a comma after each field; otherwise,
print ‘-1’.
● If the operation chosen by the user is ‘s subject marks’, print the corresponding
student’s name that matches with the entered subject and marks; otherwise, print ‘-1’.
● Above two options will repeat until the user chooses e.

Sample input 1:

5
111,Alice,Maths,85
123,Bob,Science,50
150,Charlie,Maths,75
145,Emily,History,50
175,David,Science,92
r 123
s Maths 90
e

Output
123,Bob,Science,50
-1

Sample input 2:

4
201,Zara,English,78
202,Ethan,Maths,60
203,Emma,Science,95
204,Noah,History,40
s Science 95
r 202
e

Output:
Emma
202,Ethan,Maths,60
4. Binary Search on Structures

In an advanced Student Information Management System, you are tasked with managing
a large number of students' records efficiently. The student's record includes the following
details:
● Name: The student's name (string of length at max 30 characters).

● Roll Number: The unique identifier for the student (integer within [100,250]).

● CGPA (Cumulative Grade Point Average): The academic performance of a student


(float within [0,10]).

The system assigns the roll number based on the sorted list of CGPA(both are in
non-decreasing order).

Write a C program that performs the following operations in menu-driven programs


with options (i, r, e).

1. i - Binary Search based on Roll Number using iterative: Search for a student by
their roll number and print the student’s record if the roll number presents otherwise
-1.

2. r- Binary Search based on CGPA Range using recursive: The challenge is to print
all students’ names whose CGPA lies between a given minimum CGPA and a
maximum CGPA using binary search recursively. To solve the challenge,

● Find the index of first student whose CGPA is greater than or equal to the minimum
CGPA
● Find the index of last student whose CGPA is less than or equal to the maximum
CGPA
● Finally, find the list of the students whose CGPA falls within the CGPA range.

Input/Output Specification:

Input:

● The first line contains an integer n>0 representing the size of the array.
● The next n lines each contains a student’s record, consisting of:
Name Roll No CGPA
● Display Menu: i - Binary search iterative, r- Binary search recursive, e- Exit from the
program.
● User may choose based on their choice and appropriate task to be done.
● If the choice is ‘i rollno’ then search the rollno in the records and print the record
details if exist otherwise print ‘-1’.
● If the choice is ‘r mincgpa maxcgpa’ then the program should print the records of the
students in between the CGPA including mincgpa and maxcgpa records otherwise
print ‘-1’ if either of the borders doesn’t exist or none of them exist.

Output:

● For a given ‘i rollno’, the program prints the student record with a single space in
between each field if it exists; otherwise, it prints ‘-1’.

● Given a ‘r mincgpa maxcgpa’, prints the list of all student’s names whose CGPA falls
within the specified range otherwise, print ‘-1’.

Sample Input 1:
5
Pranav 101 6.5
Naveen 102 7.3
Gokul 103 8.2
Veenus 104 9.1
Farhan 105 9.8
i 103
r 7.0 9.5
e

Sample Output 1:
Gokul 103 8.20
Naveen
Gokul
Veenus

Sample Input 2:
4
Pranav 201 6.9
Naveen 202 7.5
Gokul 203 8.3
Farhan 204 9.6
i 202
i 205
r 7.0 8.5
r 9.7 9.9
e
Sample Output 2:
Naveen 202 7.50
-1
Naveen
Gokul
-1

5. LS on Array of Strings

Problem Statement
Perform Linear Search for an array of strings. The implementation includes
user input for strings, searching for a target string, and which can handle the
following Scenarios:

1. Case-Sensitive Match: The target string is present in the array and matches the
case exactly.
2. Case-Insensitive Match: The target string is present but has a different case.
3. Target Not Found: The target string is not in the array.
4. Empty Array: The user provides no strings in the array (should be handled with
an error message).
5. Edge Cases:
○ Target string is an empty string.
○ Strings with special characters or spaces.

Input Specification
1. Number of Strings: An integer n representing the number of strings in the array
(1 ≤ n ≤ 100).
2. Strings: n strings, each up to 100 characters, entered one by one.
3. Target String: A single string (up to 100 characters) to search for.
4. Case Sensitivity: A character (y or n) indicating whether the search is
case-sensitive.

Output Specification

1. If Found: Print the index (0-based) where the target string is located.
2. If Not Found: Print a message stating that the string is not in the array.
3. Errors: Handle invalid input gracefully (e.g., invalid n).

Sample Input/Output
Scenario 1: Case-Sensitive Match

Input :
Enter the number of strings (max 100): 5
Enter 5 strings:
String 1: Hello
String 2: World
String 3: IIT
String 4: Student
String 5: LinearSearch
Enter the string to search: IIT
Do you want the search to be case-sensitive? (y/n): y
Output:
String 'IIT' found at index 2.

Scenario 2: Case-Insensitive Match


Input:
Enter the number of strings (max 100): 3
Enter 3 strings:
String 1: Linear
String 2: Search
String 3: Algorithm
Enter the string to search: linear
Do you want the search to be case-sensitive? (y/n): n
Output:
String 'linear' found at index 0.

Scenario 3: Target Not Found


Input :
Enter the number of strings (max 100): 4
Enter 4 strings:
String 1: Data
String 2: Structures
String 3: Programming
String 4: Concepts
Enter the string to search: Code
Do you want the search to be case-sensitive? (y/n): n
Output:
String 'Code' not found in the array.

Scenario 4: Invalid Number of Strings


Input :
Enter the number of strings (max 100): 0
Output :
Invalid number of strings!

Scenario 5: Edge Case - Special Characters


Input :
Enter the number of strings (max 100): 3
Enter 3 strings:
String 1: @hello
String 2: #world
String 3: $money
Enter the string to search: #world
Do you want the search to be case-sensitive? (y/n): y
Output :
String '#world' found at index 1.

6. LS on Files.
Write a C program that reads integers from a file, performs linear search to find the input
key, and finds the number of occurrences of the key in the file.
Input Specification
Name of the input file and the integer key to be searched separated by a space. You may
assume that the file with the given name is present.
Output Specification
Number of occurrences of the key in the file.

Sample Input1:
Numbers.txt 3
Sample output1:
2
Sample Input2:
Numbers.txt 355

Sample output1:
0

—------------------------------
numbers.txt(file)
500
10
3
70
1
8
56
78
69
487
3
48
656
4
233
49

You might also like