[go: up one dir, main page]

0% found this document useful (0 votes)
77 views8 pages

C l2 - Hands-On Assignment

This document provides 5 hands-on assignments for learning C++ programming at an intermediate level. The assignments cover topics like expression evaluation, encryption/decryption using ciphers, solving the eight queen problem, scheduling a robotic application, and implementing a variation of quicksort. The assignments are designed to help learn concepts like stack/tree operations, file handling, object-oriented programming, and sorting algorithms.
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)
77 views8 pages

C l2 - Hands-On Assignment

This document provides 5 hands-on assignments for learning C++ programming at an intermediate level. The assignments cover topics like expression evaluation, encryption/decryption using ciphers, solving the eight queen problem, scheduling a robotic application, and implementing a variation of quicksort. The assignments are designed to help learn concepts like stack/tree operations, file handling, object-oriented programming, and sorting algorithms.
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/ 8

C++ Programming L2: Trend NXT Hands-on Assignments

Estimated Efforts: 7 PDs

Trend NXT URL Link: https://wipro365.sharepoint.com/sites/ku-practice-


4102/PES/Competency/CGPortal/TrendNxt/PES%20SW/C%20Plus%20Plus%20Programming/TCA-PES-C-
Plus-Plus-Programming-L2-SG.aspx

Author: Sunil Kadam

Date: 25th May 2018

TOC:

Min No of
Sr. No. Topic Assignments

1 Constructors and Destructors, Consructor overloading, Type Conversions


2 Friends
3 Function Overloading and Default Arguments, Operator Overloading
4 Inheritance-Virtual Functions-Polymorphism
5 Streams and File Handling
5
6 Templates
7 Exception Handling
8 Manipulating strings
9 Advanced C++: RTTI/casting, auto_ptr
10 Namespaces

Assignment 1:

Expression evaluator

This assignment is for people to understand the concept of stack/tree/graph operations and
programming.

Design and implement an expression evaluator to evaluate arithmetic expression.

Sensitivity: Internal & Restricted


Expression can have unary and binary operators.

To start with, you can assume following as possible operators.

Unary +, Unary -, Binary +, Binary -, multiplication * and division /

Example of valid expressions:

 -10+20*8-90/2
 (-10+20)*8-90/2
 -10
 +5

Hint: two components –


a. Parser – To scan the input string, check for syntax, and possibly/optionally produce
an intermediate representation

b. Evaluator – To evaluate the expression tree.

Assignment 2:

Key Based Security for Message Passing

This assignment is for a C++ developer at L1 level to get an understanding on how to use files, encryption
and decryption through CIPHERS. This also helps the developer to understand how to use sockets in C++
programming.

This assignment is for the C++ developer who wants hands-on experience on implementing a case study

PROBLEM STATEMENT
Design and develop an object-oriented program in C++ to implement a symmetric key based security
system (which uses a single key) for both encryption and decryption of a message in a secured
communication. The user encrypts the message to be sent and this encrypted message must be sent over
the communication network. At the receiving end, the intended receiver would get the encrypted
message and decrypt it.

Sensitivity: Internal & Restricted


There are different types of ciphers (encryption and decryption algorithms). You will implement in this
project, only a) Substitution cipher and b) Transposition cipher. The algorithms are given below.

REQUIREMENTS

1. A message: A file containing string of characters


2. Ciphers:

A] The substitution cipher:


In which a key character is accepted and added to each and every character of the
source file. And uses the same key for decryption.

1) Each of the 26 alphabets is given a value chronologically starting from 1 to 26

with a = 1 and z = 26.

2) Read a key character for encryption

3) Read the character from the given plaintext and if message ends

goto step 7.

4) Search in the Lookup table, the ASCII value of the character

5) Add the key value to the ASCII value of the character

Goto step 3

6) Stop [and transmit]

B] The transposition cipher:


In which a string is used as a key and the source file contents are stored in the various
columns designed out of the key characters.
Design is as follows.
1) Read the length of the key and initialize n = length and columns = length
2) Read the key and store its characters in separate arrays (K1,K2…Kn) in the order
of their occurrence (key may be a phrase)

Sensitivity: Internal & Restricted


3) Read the characters of the plaintext and store them in the arrays in the order of
their occurrence.
4) Repeat for i = 1 to columns do

a) Search for the key alphabet having the lowest ASCII value in the first location
of each array and transfer the contents of the array from the second location
into ciphertext

b) Set the first location of the selected array to some large value.
5) Stop

Choose an appropriate key and should communicate secretly to your recipient. The
program should include
i) class definition(s) in a separate header file.

ii) All global declarations in yet another file.

iii) Test program ( your main )

Use sockets and appropriate function calls.

Assignment 3:

Eight Queen Problem

Eight queens are to be placed on an 8x8 chess board in such a way that no queen checks against
any other queen. No two queens should be in the same column or same row or same diagonal.
No two queens should be in the adjacent position.

Create a two dimensional array. Presence of queen in a cell should be indicated by putting 1 in
the corresponding position in the array. Similarly, absence of queen to be indicated by putting 0
there.

Find out possible outcomes. Display the outcomes as shown below.

Example of valid positions:

Sensitivity: Internal & Restricted


10000000
00000010
00001000
00000001
01000000
00010000
00000100
00100000

Example of invalid positions:

Assignment 4:

Scheduler for robotic application

A semi-conductor wafer manufacturing company has an automated robotic machine to process the
wafers.

Sensitivity: Internal & Restricted


Each wafer undergoes steps as mentioned below.
1. Wafer is picked up from a stack of wafers (stack of 10) and put to Washing and Rinsing
chamber for defined interval.
2. Wafer is then put to Electroplating chamber for defined time.
3. Wafer is then again put to washing and rinsing chamber for defined time.
Each wafer in the stack is associated with a recipe which mentions various time periods for that
wafer in respective chamber.
Machine consists of following.
- 2 stacks to hold wafers, each one holding 10 wafers.
- 6+6=12 washing/rinsing chambers
- 2+2=4 chambers for electroplating.
Write a scheduler to schedule and process the wafers through different chambers.
Note that,
a) You cannot wash/rinse/electroplate for time less that that defined for a given wafer.
b) You must not keep the wafer in electroplating chamber for more than the defined time
period.
Compute overall completion time for all the wafers in both the stacks.
You can make suitable assumptions and creatively add requirements. Clearly document
assumptions and requirements.

Assignment 5:

A variation of Quick sort

1. Implement a variation of quick sort algorithm as explained below.


2. X is an array of N integers to be sorted.
3. Array is partitioned using an element say X[j] as the pivot such that after partitioning,
all the elements in the array at positions less than j are less than X[j] and all the
elements in the array at positions greater than j are greater than X[j].

Sensitivity: Internal & Restricted


4. This is done recursively on each of the two partitions, till all the partitions contain one
element – which means the array is sorted.
5. The partitions works as follows.
o The partitioning procedure gives the position J.
o Let,
 LB – Lower bound of the sub-array
 UB – Upper bound of the sub-array
 Pivot element A is the middle element of the sub-array i.e. the element
at position (LN+UB)/2
 DOWN – Pointer initialized to upper bound of the sub-array
 UP – Pointer initialized to lower bound of the sub-array
o At any point during execution,
 each element at a position greater than UP >= A
 each element at a position lower than DOWN <= A
o Pointers UP and DOWN are moved towards each other as follows:
 Step-1:
Repeatedly increase the pointer DOWN by one position until X[DOWN]
> A. After DOWN is increased each time, if X[DOWN] < X[DOWN-1],
swap X[DOWN] < X[DOWN-1].
 Step-2:
Repeatedly decrease the pointer UP by one position until X[UP] <= A.
After UP is decreased each time, if X[UP] > X[UP+1], swap X[UP] <
X[UP+1].
 Step-3:
If UP > DOWN, swap X[DOWN] and X[UP]
If X[ DOWN] < X[DOWN-1], swap X[DOWN] and X[DOWN-1]
If X[ UP] > X[UP+1], swap X[UP] and X[UP+1]
 The above steps are repeated till UP <= DOWN. The position UP is the
position J required.

Input specifications:

The input will be a single line containing an integer N, followed by N integers. Assume N
< 50.

Output specifications:

You have to print the content of the array X each time partitioning is done. The output
should be on a single line containing the array elements separated by a space.

Sensitivity: Internal & Restricted


Sample Input/ Output

Input

8 25 57 48 37 12 92 86 33

Output
Explanation
25 12 33 37 48 57 92 86 sort(0,7) UP = 3 X[DOWN] = 48, X[UP] = 37
12 25 33 37 48 57 92 86 sort(0,2) UP = 0 X[DOWN] = 25, X[UP] = 12
12 25 33 37 48 57 92 86 sort(1,2) UP = 1 X[DOWN] = 33, X[UP] = 25
12 25 33 37 48 57 86 92 sort(4,7) UP = 5 X[DOWN] = 86, X[UP] = 57
12 25 33 37 48 57 86 92 sort(6,7) UP = 6 X[DOWN] = 92, X[UP] = 86

Sensitivity: Internal & Restricted

You might also like