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

Assgn-V SP

Uploaded by

rakeshsandeep24
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)
2 views3 pages

Assgn-V SP

Uploaded by

rakeshsandeep24
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

Assignment V

Submit all the programs separately against each assignment in the


Moodle System. Provide the result in a separate output file (named,
result_<assgn><no>.txt). Use standard output redirection feature to
generate the output file.

Hints. If you run the program with the following command

./a.out >result.txt

Output of your program (generated by printf(.) function) will be


written in the file result.txt. You need to provide input from your
keyboard, by remembering the sequence of inputs to be given or
writing them in a text file in the same sequence.

Otherwise you may use the redirection for the standard input file,
such as,

./a.out <input.txt

For the above all your printing by printf(.) function would be


displayed on your monitor.

For both reading from a file and writing to a file use the following.

./a.out <input.txt >result.txt

If you execute the program multiple times, you may concatenate the
outputs in a single file by using the following redirection command:

./a.out >>result.txt

or

./a.out <input.txt >> result.txt


a) Write a function split_real_number(.), which takes a real number as an
input and separates its whole number part (ignoring the sign of the number)
and the fractional part. The function returns both the parts through parameter
passing.

For example, given a real number -435.354 passed as an input to the


function it returns the whole number part 435 and the fractional part 0.354
through parameter passing (Hint: use pointer variable as arguments).

Write a main program which reads N (to be read) real numbers, and prints
the sums of their whole number parts and fractional parts.

Run your program for the following input data set and provide the results with
input datasets in a separate output file.

(i) N=3

2.34, -4.567, 1289.01267

(ii) N=6

-1.234, 29.01267, 0.0238, 345.567, -908.76, 187.39876

(iii) N=1

4.356

b) Write a function encrypt(.) which takes two strings s1 and s2 as


arguments, and also a positive number K as an encryption key. The function
takes the characters of the string s, encrypts it using the positive number K
to store in the string s2. The encryption process is as follows:

It processes each character of s1 one by one from left to right and also reads
the digits of the number K from right to left and cyclically shift the character
following the alphabetic order of the English language by the corresponding
digits. If all the digits of the encryption key are exhausted, the process
continues to encrypt the successive alphabets from the unit position of the
digit.
For example, given an input string “Lazy” and encryption key “56”, the
encrypted string will be “Rffe”.

Write also another function decrypt(.), which takes encrypted string s1 and
the key (a positive number) as inputs, and gets back the original string in
s2, which is also passed as a parameter to the function.

For example, given the input string “Rffe” in s1 and the key “56”, the
function would get the string “Lazy” in s2.

Write a main program which reads an English sentence and an encryption key.
The program prints its encrypted string by applying the function encrypt(.) to
each of its words. The program also gets back the original string from the
encrypted string by applying the function decrypt(.) with the same key.

Run your program for the following input data set, and provide the results with
input datasets in a separate output file.

(i) Where the mind is without fear, and the head is held high!

Encryption key: 3456

(ii) United we stand, united we fall.

Encryption key: 6543

(iii) Jack and Jill went up the hill to fetch a pail of water.

Encryption key: 201

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy