lab 4

lab description:
In this lab we designed a C++ program to add, multiply, exponentiate,subtract and roman numaralize numbers. This lab was very similar to the hla program that we created for our lab #2. The statements, syntaxes were a little different in comparison to hla. instead of using stdout.put,and stdin.get we used cout<< and Cin<< while declaring using namespace std before main function. in hla we declare the bits of the integers but we didn't declare bits for c++. Then was removed from the ifelse statements. jmp was totally omitted on this program. In Hla we used the registers ,whereas in C++ we didn't.
(note: the g++ compiler wasn’t working on my virtual box. when i was trying to install it i couldn’t because i have no network connection on my virtual box)
code:

#include
#include
#include

using namespace std;
int x,y,z;
int operand;
int main()
{
	cout<<"this is calculating program:"<<endl;
	cout<<"press 1 for addition:"<<endl;
	cout<<"press 2 for subtraction:"<<endl;
	cout<<"press 3 for multiplication:"<<endl;
	cout<<"press 4 for exponentiation:"<<endl;
	cout<<"press 5 for converting numbers to roman numerals:"<<endl;
	cout<<"press any other number to exit from the program:"<>operand;
while (operand>0||operand <6){

	switch (operand){
	



     case 1:
	
	cout<<"you have chosen to add:"<<endl;
	cout<<"enter a number"<>x;
	cout<<"enter another number"<>y;
	z=x+y;
	if (x>65536||y>65536)
	{
	cout<<"this is too big, it might cause program overflow";break;}
	else if(x<65536||y<65536){ 
	cout<<"the result is:"<<z<<endl;
		cout<<"this is calculating program:"<<endl;
	cout<<"press 1 for addition:"<<endl;
	cout<<"press 2 for subtraction:"<<endl;
	cout<<"press 3 for multiplication:"<<endl;
	cout<<"press 4 for exponentiation:"<<endl;
	cout<<"press 5 for converting numbers to roman numerals:"<<endl;
	cout<<"press any other number to exit from the program:"<>operand;
    
	break;
	
	case 2:
		cout<<"you have chosen to subtract"<<endl;
	cout<<"enter a number"<>x;
	cout<<"enter another number"<>y;
	z=x-y;
	if (x>65536||y>65536)
	{
	cout<<"this is too big, it might cause program overflow";break;}
	else if (x<65536||y<65536){ 
	cout<<"the result is:"<<z<<endl;}
	cout<<"this is calculating program:"<<endl;
	cout<<"press 1 for addition:"<<endl;
	cout<<"press 2 for subtraction:"<<endl;
	cout<<"press 3 for multiplication:"<<endl;
	cout<<"press 4 for exponentiation:"<<endl;
	cout<<"press 5 for converting numbers to roman numerals:"<<endl;
	cout<<"press any other number to exit from the program:"<>operand;
	
	break;
	case 3:
		cout<<"you have chosen to multiply"<<endl;
	cout<<"enter a number"<>x;
	cout<<"enter another number"<>y;
	if (x>65536||y>65536)
	{
	cout<<"this is too big, it might cause program overflow";break;}
	else if (x<65536||y<65536){ 
	z=0; 
for (int i=0;i<y;i++) 
	z=z+x;
	cout<<z<<endl;
	cout<<"this is calculating program:"<<endl;
	cout<<"press 1 for addition:"<<endl;
	cout<<"press 2 for subtraction:"<<endl;
	cout<<"press 3 for multiplication:"<<endl;
	cout<<"press 4 for exponentiation:"<<endl;
	cout<<"press 5 for converting numbers to roman numerals:"<<endl;
	cout<<"press any other number to exit from the program:"<>operand;

	break;
	}
	
	
	case 4:
		cout<<"you have chosen to exponentiate:"<<endl;
	cout<<"enter a number"<>x;
	cout<<"enter another number"<>y;
	if (x>65536||y>65536)
	{
	cout<<"this is too big, it might cause program overflow";break;}
	 
	z=1;
	for(int i = 0; i < y; y++)
	{
	    z*=x;
	cout<<z<<endl; break;}
	cout<<"this is calculating program:"<<endl;
	cout<<"press 1 for addition:"<<endl;
	cout<<"press 2 for subtraction:"<<endl;
	cout<<"press 3 for multiplication:"<<endl;
	cout<<"press 4 for exponentiation:"<<endl;
	cout<<"press 5 for converting numbers to roman numerals:"<<endl;
	cout<<"press any other number to exit from the program:"<>operand;
	
	}
    break;

    case 5:
    	cout<<"you have selected conversion to roman"<<endl;
	cout<>x;
	  while(x!=0)
            if(x>=1000){
            
               x=x-1000;
               cout<<"M";}

            else if(x==999){
            
               x=x-999;
               cout<=900){
            
               x=x-900;
               cout<=500){
            
               x=x-500;
               cout<=499){
            
               x=x-499;
               cout<=400){
            
               x=x-400;
               cout<=100){
            
               x=x-100;
               cout<<"C";}

            else if(x==99){
            
               x=x-99;
               cout<=90){
            
               x=x-90;
               cout<=50){
            
               x=x-50;
               cout<<"L";}

            else if(x==49){
            
               x=x-49;
               cout<=40){
            
               x=x-40;
               cout<=10){
            
               x=x-10;
               cout<<"X";}

            else if(x==9){
            
               x=x-9;
               cout<=5){
            
               x=x-5;
               cout<<"V";}

            else if(x==4){
            
               x=x-4;
               cout<<"IV";}

            else{
            
               x=x-1;
               cout<<"I"<<endl;}
	cout<<"this is calculating program:"<<endl;
	cout<<"press 1 for addition:"<<endl;
	cout<<"press 2 for subtraction:"<<endl;
	cout<<"press 3 for multiplication:"<<endl;
	cout<<"press 4 for exponentiation:"<<endl;
	cout<<"press 5 for converting numbers to roman numerals:"<<endl;
	cout<<"press any other number to exit from the program:"<>operand;
	break;
	
	case 6:
		while(operand>5||operand<0)
		{
			cout<<"exit";
			return 0;
			break;
		}
	
	}

		
 }
}

screenshots:

fuck12

fuck1

Leave a Reply

Your email address will not be published. Required fields are marked *