Solution_assignment_03_BICSE6A

advertisement
Assignment 3: BICSE6A
(Group Assignment)
Total marks 20
Marks 08
Q1: In communication systems the security is very much important. You being an information
system engineer is required to build a program to secure your information over communication
channels so that no one can see the actual information being transmitted. Your communication
channel cannot support more than four digit number.
a): You have to encrypt this information at sending terminal.
b): Decrypt the information at receiving terminal.
The “CYPHER” is provided below :
Sum up 7 with the 1st digit of your number and take the modulus 10 of the sum.
Sum up 3 with the 2nd digit of your number and take the modulus 10 of the sum.
Sum up 6 with the 3rd digit of your number and take the modulus 10 of the sum.
Sum up 4 with the 4th digit of your number and take the modulus 10 of the sum.
Swap 1st digit with 3rd and 3rd with 4th.
Requirements :
The input from user MUST be an integer number ranging from 0 to 9999.
The Encrypted output and Decrypted output both have to be in a “SINGLE INGER”.
For Example:
Output should be like this:
Please enter the integer number ranging 0 to 9999 : (input integer)
The Encrypter code number is : (output integer)
1
#include <iostream>
using namespace std;
int main()
{
int number;
int x0,x1,x2,x3;
int temp;
cout<<"Question 1 solution encryption : "<<endl;
do{
cout<<"Please enter the number -- ";
cin>>number;
}while(number > 9999 || number < 0 );
temp = number;
x3 = temp % 10;
temp = temp / 10;
x2 = temp % 10;
temp = temp / 10;
x1 = temp % 10;
temp = temp / 10;
x0 = temp;
x0 += 7;
x0 = x0 % 10;
x1 += 3;
x1 = x1 % 10;
x2 += 6;
x2 = x2 % 10;
x3 += 4;
x3 = x3 % 10;
number = x0*1000 + x1*100 + x2*10 + x3 ;
cout<<"The encrypted value is : "<<number;
return 0;
}
2
Q2: Write a program which will ask the user to enter time in seconds (integer) and print the text
(“Assignment is very easy”).
Marks 07
a): Print this statement till the time (seconds) entered by user//
b): Along with each print statement also print the remaining time.
c): After each print statement the ask user to press any key to continue.
Output :
Please Enter time in second : 11 (say)
Assignment is very easy the remaining time is 11 Press any key
Assignment is very easy the remaining time is 7 Press any key
Assignment is very easy the remaining time is 6 Press any key
Assignment is very easy the remaining time is 4 Press any key
Assignment is very easy the remaining time is 3 Press any key
Assignment is very easy the remaining time is 0 Press any key
_________________________________________________________
#include <iostream>
using namespace std;
int main()
{
int number;
int x0,x1,x2,x3;
int temp;
cout<<"Question 1 solution encryption : "<<endl;
do{
cout<<"Please enter the number -- ";
cin>>number;
}while(number > 9999 || number < 0 );
temp = number;
x3 = temp % 10;
temp = temp / 10;
x2 = temp % 10;
temp = temp / 10;
3
x1 = temp % 10;
temp = temp / 10;
x0 = temp;
x0 += 3;
x0 = x0 % 10;
x1 += 7;
x1 = x1 % 10;
x2 += 4;
x2 = x2 % 10;
x3 += 6;
x3 = x3 % 10;
number = x0*1000 + x1*100 + x2*10 + x3 ;
cout<<"The dycrypted value is : "<<number;
return 0;
}
_________________________________________________________
Q3: Take an integer input in Decimal number system and then using iterations convert this no
into any base system from 2 to 9.
Output:
Please enter the Decimal number to convert :
(73) ( for exmp)
Please enter Base (to which you want to convert this Decimal number)
(3) (for exmp)
The Value in given base (3) is :
(2201) (for exmp)
BONUS QUESTION:
(Extra marks ! ! !)
=>One who gets it completed will get extra marks IF some marks had been deducted from any
above question.
Put all the three question in single .cpp file having a menu driven interface asking which
question # is to be started
4
There MUST be proper menu to menu entrance and exits. When any of the question is finished,
it should go back to the main menu rather than exiting and there should be the choice to exit
from the program.
Output:
Assignment Submitted by
:
(Your Group Name)
Press 1 for Question # 1(a):
(Encryption)
Press 2 for Question # 1(b):
(Decryption)
Press 3 for Question # 2:
Press 4 for Question # 3:
Press 0 to Exit from Program:
(your input of choice)…
Instructions for Submission
1. Select A4 Sized Paper with narrow margins
2. Write the commented code (for each question) in a well formatted manner
3. The printed / hand written copy should be submitted to the SEECS information/
reception desk. (soft copy is not accepted)
4. Deadline: 26th January, 2009 [4:00 PM]
5. Late submission should be avoided
#include <iostream>
using namespace std;
#include <time.h>;
#include <conio.h>
int main()
{
long t1;
long t2;
int time_usr;
do{
cout<<"Please provide the time (0-30)";
cin>>time_usr;
}while(time_usr <0 || time_usr > 30);
5
time(&t1);
time(&t2);
while((t1 + time_usr) > t2 )
{
cout<<"The message !! "<<t1+time_usr - t2<<endl;
getch();
time(&t2);
}
return 0;
}
__________________________________
#include <iostream.h>
#include <math.h>
int main()
{
int decimal=0,quotient=0,temp=0,number=0,i=0,base =0;
while(1)
{
cout<<"Please enter the number in decimal ";
cin>>decimal;
quotient = decimal;
cout<<"Please enter the desired base : ";
cin>>base;
while(1)
{
temp = quotient % base;
quotient/=base;
6
// remainder
if( temp == 0)
{
i++;
if ( quotient == 1)
{
number += quotient* pow(10,i);
break;
}
continue;
}
number += temp * pow(10,i);
i++;
if(quotient < base )
{
number += quotient* pow(10,i);
break;
}
}
cout<<" The base "<<base<<" equivalent for "<<decimal<< " is :
"<<number<<endl;
decimal=0,quotient=0,temp=0,number=0,i=0,base =0;
}
return 0;
}
7
Download