0% found this document useful (0 votes)
104 views3 pages

PF Assignmnet 2

This document provides instructions for an assignment in CS118 Programming Fundamentals. Students are asked to write code to simulate a game involving students opening and closing lockers. They must write two functions: one that returns the number of open lockers at the end of the game, and another that returns the locker number(s) touched by the most students. The code must be properly named and formatted or it will receive a grade of zero. Plagiarism is also not allowed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views3 pages

PF Assignmnet 2

This document provides instructions for an assignment in CS118 Programming Fundamentals. Students are asked to write code to simulate a game involving students opening and closing lockers. They must write two functions: one that returns the number of open lockers at the end of the game, and another that returns the locker number(s) touched by the most students. The code must be properly named and formatted or it will receive a grade of zero. Plagiarism is also not allowed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CS118 Programming Fundamentals (Fall 2022)

ASSIGNMNET
INSTRUCTIONS:
Please keep the following in mind:

• Do not share your code with anyone else. All assignments are to be done
individually.
• SOLUTIONS/PLAGIARISM from INTERNET will lead to ZERO
• You must submit the .c files only. Make sure you name as
rollno_name_dept_sec.cpp
• For example: P22_1234_ Name_CS_1D
• Make sure you follow the naming schemes of the .c files correctly. Failure
to do so will result in getting ZERO.
• No submissions other than Classroom will be entertained.
• Make sure your code compiles and runs. If a piece of code fails to compile,
you’ll be given a ZERO.
• All submissions will be checked for plagiarism. You are not allowed to copy
code from the internet or any other individual.
• Any sort of plagiarism will lead to ZERO.
• DO NOT MODIFY FILE, JUST WRITE YOUR CODE IN DESIRED AREA.
• RENAME task.c according to this schema P22_1234_Name_CS_1D
• ARRAYS are not allowed.
• USE ONLY LOOPS and FUNCTIONS
• LATE SUBMITIONS WILL NOT BE ENTERTAINED
• DEADLINES TO BE FOLLOWED STRICTLY

Page 1|3
CS118 Programming Fundamentals (Fall 2022)

1. New School Game

A high school has “n” number of students and “m” number of lockers. For
simplicity we are taking 100 students and 100 lockers. On the first day of school,
the principal plays the following game: She asks the first student to go and open
all the lockers. She then asks the second student to go and close all the even-
numbered lockers. The third student is asked to check every third locker. If it is
open, the student closes it; if it is closed, the student opens it. The fourth student
is asked to check every fourth locker. If it is open, the student closes it; if it is
closed, the student opens it. The remaining students continue this game. In
general, the nth student checks every nth locker. If the locker is open, the student
closes it; if it is closed, the student opens it. After all the students have taken their
turn, some of the lockers are open and some are closed. Your job is to tell how
many lockers are open at the end of the game and if we take 100 students and
100 lockers the result should be 10.

1.1 Tasks to do

There are two main tasks to complete:

1. You have to implement this scenario using a function named “openLocks()”,


which takes two input parameters i.e number_of_lockers and
number_of_students that returns the number of lockers that are opened.

2. Your job now, is to write a function named “mostTouchableLocker()” which


takes two input parameters i.e number_of_lockers and number_of_students
that returns the locker number which is touched by the most of the students.
If you have more than one lockers that are most touched. Let say locker 1 and
2 both are most touchable, then your function should return 2

Note: Please make sure your functions are defined before Main and test1 and
test2 Functions

Hint is on the next page.

Page 2|3
CS118 Programming Fundamentals (Fall 2022)

Hint: Try to do yourself. Try to break it into smaller parts and make function.

Page 3|3

You might also like