Vous êtes sur la page 1sur 4

CSE 114

Computer Science I
FALL 2017
MIDTERM EXAM 1 PRACTICE PROGRAMS
These are some practice problems that include nested loops and patterns.
This is only a sample and is not an exhaustive list.
If any clarification is required, post it on piazza.
Please read the note at the end of this document.

SECTION A
Question 1.
Encryption is widely used to protect passwords, user data and classified government information
from miscreants and misdemeanors. Online banking and mobile banking applications,
government websites, etc. se complicated public key-private key combinations to encrypt the
data. Let us develop a simple encryption-decryption program.
Let us assume a message “I LIKE CSE114”.

The private key is in the form of a string, which is rotated about an index.
If the original key was ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 and the index is 3,
then the rotated array is DEFGHIJKLMNOPQRSTUVWXYZ1234567890ABC.
The program has to translate the message to an encrypted message as “L OLNH FVH 447”.
You should hard code the original key and the index at which you want to rotate the array,
however not the rotated array, both act as the private key and this key is kept hidden from the
user.
Your program must also take an encrypted message and decrypt the same.
This type of encryption is substitution cipher.
Question 2.
You must be aware of Bubble Sort (implemented in Lab 9), which was fairly easy to implement
and understand. However, for large data, bubble sort is inefficient.
Hence, we will implement two methods of sorting, one is equally inefficient, while the second
one is slightly better.
The first method is Selection Sort, where the least element is swapped the element in the first
index, the second least element with the second index and so on.
Figure 1 Image taken from Dr. Paul Fodor’s lecture notes.

The second method is Insertion Sort, which repeatedly inserts unsorted elements into a sorted
sub list until the whole list is sorted.

Figure 2 Image taken from Dr. Paul Fodor's lecture notes.


Question 3.
Palindromes are strings whose spellings are the same when read from left to right or from right
to left. For the human eye, it’s not a problem. It can be recognized easily, however a computer,
whose IQ is zero finds it hard to detect a palindrome number, and is seeking your help.
Write a method that returns true if the string is a palindrome lest false.
Examples:
isPalindrome(“madam”); //True
isPalindrome(“computer science”); //False
SECTION B
Question 4.
Write programs to print the following patterns:
Get the number of lines from the user. Here, all are represented for an input of 5.
* ***** *
** **** ***
*** *** *****
**** ** *******
***** * *********
*******
***** * *****
**** *** ***
*** ***** *
** *******
* ********* *********
**** ****
* ********* *** ***
** ******* ** **
*** ***** * *
**** *** ** **
***** * *** ***
**** ****
*********
Question 5.
Write programs to print the following patterns:
Get the length and the breadth from the user. Here, all are represented for an input length of 10
and breadth of 5.
**********
* *
* *
* *
**********

*XX*X*X***
X*X***X*X*
**X*****X*
X*****X***
X*X***X***
Hint: Think of prime numbers here.
Get the number of blocks from the user. Here, all are represented for an input 3.
These were once on CSE 114 exams.
O O O O O O
/ \ / \ / \ / \ / \ / \
O O O O O O O O
| | | | | X X X |
O O O O O O O O
\ / \ / \ / \ / \ / \ /
O O O O O O

Please read to the textbook, myProgrammingLab and the lecture notes to excel in this midterm.
Solutions to these questions shall be out by the end of Saturday (14th October, 2017).

Midterm Exam 1 is scheduled for Monday, October 16, from 8:45 – 10:15 PM in Javits 100,
101, and 103.
Please be on time.
The exam is paper-based, and is CLOSED BOOK, CLOSED NOTES.
You may NOT use any electronic devices (computers, tablets, smartphones, calculators, etc.) for
any reason during the exam; even their mere visibility during the exam will be considered to
be evidence of intent to cheat, and will be treated accordingly.
Bring photo ID (student ID card, driver's license, passport, etc.) to the exam. We will check
IDs, and we will NOT accept exam submissions from anyone without an ID.

Vous aimerez peut-être aussi