Solved Conversion from Bottom-up to Top-down design...

March 24, 2012 at 04:32:13
Specs: Windows XP
I have a trouble in converting bottom-up program to top-down.

# include <stdio.h>
# include <conio.h>
# include <stdlib.h>

int main()

{
int main, num_sys, x, again, matri ;

do{
system("cls");
printf("\n ============================ ");
printf("\n || WELCOME TO THE MAIN MENU || ");
printf("\n ============================ ");
printf("\n ");
printf("\n ====================================================== ");
printf("\n // PRESS: \\ ");
printf("\n ||[1] TO GO TO THE NUMERAL CONVERTER MENU ||");
printf("\n ||[2] TO GO TO THE BASIC OPERATIONS FOR 3x3 MATRICES MENU||");
printf("\n \\ // ");
printf("\n ====================================================== ");
printf("\n ++++++++ ");
printf("\n ENTER YOUR CHOICE:+++> ");
scanf("%d",& main);
printf(" ++++++++ ");
printf("\n ");
printf("\n ");
printf("\n");
getch();

if (main==1){
system("cls");
printf("\n ============================================== ");
printf("\n || WELCOME TO THE NUMERAL SYSTEM CONVERTER MENU || ");
printf("\n || with FOUR DIGITS || ");
printf("\n ============================================== ");
printf("\n");
printf("\n ================================================== ");
printf("\n // PRESS: \\ ");
printf("\n ||[1] THE OCTAL to DECIMAL CONVERTER. ||");
printf("\n ||[2] THE HEXADECIMAL to DECIMAL CONVERTER. ||");
printf("\n ||[3] THE 14 DIGIT BINARY TO DECIMAL CONVERTER. ||");
printf("\n \\ // ");
printf("\n ================================================== ");
printf("\n ++++++++ ");
printf("\n ENTER YOUR CHOICE:+++> ");
scanf("%d",& num_sys);
printf(" ++++++++ ");
printf("\n ");
printf("\n ");
printf("\n");
printf("\n");
getch();

if (num_sys==1){
int o1,o2,o3,o4,d1,d2,d3,d4,td;
do{
system("cls");
printf("\n ====================================== ");
printf("\n // \\ ");
printf("\n ||Welcome to the Octal-Decimal Converter || ");
printf("\n \\ // ");
printf("\n ====================================== ");
printf("\n ");
printf("\n o================================================o ");
printf("\n \\ \\ ");
printf("\n )) Direction: If the number that you are going )) ");
printf("\n // to convert is 3,2 or 1 digit/s use 0. // ");
printf("\n (( Example: instead of 6 5 4, use 0 6 5 4 or else(( ");
printf("\n \\the result will be wrong. \\ ");
printf("\n \\ \\");
printf("\n o================================================o ");
printf("\n ");
printf("\n ");
printf("\n Enter the first digit of the number to be converted: ");
scanf("%d",&o1);


if ((o1<=7)&&(o1>=0)){
printf("\n Enter the second digit of the number to be converted: ");
scanf("%d",&o2);}

else{
system("cls");
printf("\n !!!! !!!!! !!!!! !!! !!!!! ");
printf("\n ! ! ! ! ! ! ! ! ! ");
printf("\n !! !!!! !!!! ! ! !!!! ");
printf("\n ! ! ! ! ! ! ! ! ! ");
printf("\n !!!! ! ! ! ! !!! ! ! ");
printf("\n");}

if ((o2<=7)&&(o2>=0)){
printf("\n Enter the third digit of the number to be converted: ");
scanf("%d",&o3);}

else{
system("cls");
printf("\n !!!! !!!!! !!!!! !!! !!!!! ");
printf("\n ! ! ! ! ! ! ! ! ! ");
printf("\n !! !!!! !!!! ! ! !!!! ");
printf("\n ! ! ! ! ! ! ! ! ! ");
printf("\n !!!! ! ! ! ! !!! ! ! ");
printf("\n");}

if ((o3<=7)&&(o3>=0)){
printf("\n Enter the forth digit of the number to be converted: ");
scanf("%d",&o4);}

else{
system("cls");
printf("\n !!!! !!!!! !!!!! !!! !!!!! ");
printf("\n ! ! ! ! ! ! ! ! ! ");
printf("\n !! !!!! !!!! ! ! !!!! ");
printf("\n ! ! ! ! ! ! ! ! ! ");
printf("\n !!!! ! ! ! ! !!! ! ! ");
printf("\n");}


d1=o1*8*8*8;
d2=o2*8*8;
d3=o3*8;
d4=o4;
td=d1+d2+d3+d4;
if ((o4<=7)&&(o4>=0)){
printf("\n %d %d %d %d in octal",o1,o2,o3,o4);
printf(" = %d in decimal",td);}
printf("\n");
printf("\n");
printf("\n ______________________ ");
printf("\n |[1] Reuse this program|");
printf("\n |[2] Exit |");
printf("\n |[3] Back to main menu |");
printf("\n |______________________|");
printf("\n");
printf("\n Enter your choice: ");
scanf("%d",&again);

if(again == 1){
system("cls");}
else if (again==2){
for(x=60;x>=0;x--)
{
system("cls");
printf("Exiting the system in: ");
printf("\n%d",x);
}
system("cls");
printf("\n");
printf("\n");
printf("\n");
printf("\n Exiting the system...");
printf("\n ");
printf("\n GOOD BYE!!!");
printf("\n");
printf("\n");
printf("\n");}

else if (again == 3){
system("cls");}

else{
system("cls");
printf("\n !!!! !!!!! !!!!! !!! !!!!! ");
printf("\n ! ! ! ! ! ! ! ! ! ");
printf("\n !! !!!! !!!! ! ! !!!! ");
printf("\n ! ! ! ! ! ! ! ! ! ");
printf("\n !!!! ! ! ! ! !!! ! ! ");
printf("\n");
printf("\n _____________________ ");
printf("\n |[1] Reuse the program|");
printf("\n |[2] Exit |");
printf("\n |[3] Back to main menu|");
printf("\n |_____________________|");
printf("\n");
printf("\n Enter your choice: ");
scanf("%d",&again);

if(again == 1){
system("cls");}
else if (again==2){
for(x=60;x>=0;x--)
{
system("cls");
printf("Exiting the system in: ");
printf("\n%d",x);
}
system("cls");
printf("\n");
printf("\n");
printf("\n");
printf("\n Exiting the system...");
printf("\n ");
printf("\n GOOD BYE!!!");
printf("\n");
printf("\n");
printf("\n");}}
} while (again==1);}

else if (num_sys==2){
int h1,h2,h3,h4,e1,e2,e3,e4,te;
do{
system("cls");
printf("\n ====================================== ");
printf("\n // \\ ");
printf("\n ||Welcome to the Hexa-Decimal Converter || ");
printf("\n \\ // ");
printf("\n ====================================== ");
printf("\n ");
printf("\n o================================================o ");
printf("\n \\ \\");
printf("\n )) Direction: If the number that you are going to ))");
printf("\n // convert envolve/s a,b,c,d,e or f digit use // ");
printf("\n (( this conversion. (( ");
printf("\n \\ a=10 c=12 e=14 \\");
printf("\n )) b=11 d=13 f=15 ))");
printf("\n // // ");
printf("\n o=================================================o ");
printf("\n ");
printf("\n ");
printf("\n Enter the first digit of the number to be converted: ");
scanf("%d",&h1);


if ((h1<=15)&&(h1>=0)){
printf("\n Enter the second digit of the number to be converted: ");
scanf("%d",&h2);}

else{
system("cls");
printf("\n !!!! !!!!! !!!!! !!! !!!!! ");
printf("\n ! ! ! ! ! ! ! ! ! ");
printf("\n !! !!!! !!!! ! ! !!!! ");
printf("\n ! ! ! ! ! ! ! ! ! ");
printf("\n !!!! ! ! ! ! !!! ! ! ");
printf("\n");}

if ((h2<=15)&&(h2>=0)){
printf("\n Enter the third digit of the number to be converted: ");
scanf("%d",&h3);}

else{
system("cls");
printf("\n !!!! !!!!! !!!!! !!! !!!!! ");
printf("\n ! ! ! ! ! ! ! ! ! ");
printf("\n !! !!!! !!!! ! ! !!!! ");
printf("\n ! ! ! ! ! ! ! ! ! ");
printf("\n !!!! ! ! ! ! !!! ! ! ");
printf("\n");}

if ((h3<=15)&&(h3>=0)){
printf("\n Enter the forth digit of the number to be converted: ");
scanf("%d",&h4);}

else{
system("cls");
printf("\n !!!! !!!!! !!!!! !!! !!!!! ");
printf("\n ! ! ! ! ! ! ! ! ! ");
printf("\n !! !!!! !!!! ! ! !!!! ");
printf("\n ! ! ! ! ! ! ! ! ! ");
printf("\n !!!! ! ! ! ! !!! ! ! ");
printf("\n");}


e1=h1*16*16*16;
e2=h2*16*16;
e3=h3*16;
e4=h4;
te=e1+e2+e3+e4;
if ((h4<=15)&&(h4>=0)){
printf("\n %d %d %d %d in hexadecimal",h1,h2,h3,h4);
printf(" = %d in decimal",te);}
printf("\n");
printf("\n");
printf("\n ______________________ ");
printf("\n |[1] Reuse this program|");
printf("\n |[2] Exit |");
printf("\n |[3] Back to main menu |");
printf("\n |______________________|");
printf("\n");
printf("\n Enter your choice: ");
scanf("%d",&again);

if(again == 1){
system("cls");}
else if (again==2){
for(x=60;x>=0;x--)
{
system("cls");
printf("Exiting the system in: ");
printf("\n%d",x);
}
system("cls");
printf("\n");
printf("\n");
printf("\n");
printf("\n Exiting the system...");
printf("\n ");
printf("\n GOOD BYE!!!");
printf("\n");
printf("\n");
printf("\n");}

else if (again == 3){
system("cls");}

else{
system("cls");
printf("\n !!!! !!!!! !!!!! !!! !!!!! ");
printf("\n ! ! ! ! ! ! ! ! ! ");
printf("\n !! !!!! !!!! ! ! !!!! ");
printf("\n ! ! ! ! ! ! ! ! ! ");
printf("\n !!!! ! ! ! ! !!! ! ! ");
printf("\n");
printf("\n _____________________ ");
printf("\n |[1] Reuse the program|");
printf("\n |[2] Exit |");
printf("\n |[3] Back to main menu|");
printf("\n |_____________________|");
printf("\n");
printf("\n Enter your choice: ");
scanf("%d",&again);

if(again == 1){
system("cls");}
else if (again==2){
for(x=60;x>=0;x--)
{
system("cls");
printf("Exiting the system in: ");
printf("\n%d",x);
}
system("cls");
printf("\n");
printf("\n");
printf("\n");
printf("\n Exiting the system...");
printf("\n ");
printf("\n GOOD BYE!!!");
printf("\n");
printf("\n");
printf("\n");}}
} while (again==1);}

else if(num_sys==3){
int b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,
f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,tf ;
do{
system("cls");
printf("\n ====================================== ");
printf("\n // \\ ");
printf("\n || Welcome to the 14 digit Binary to || ");
printf("\n || Decimal Converter || ");
printf("\n \\ // ");
printf("\n ====================================== ");
printf("\n ");
printf("\n o================================================o ");
printf("\n \\ \\");
printf("\n )) Direction: You MUST Enter only 1's or 0's to ))");
printf("\n // convert the entered Binary value to Decimal // ");
printf("\n (( or else, YOU WILL GET THE WRONG OUTPUT (( ");
printf("\n \\ \\");
printf("\n o=================================================o ");
printf("\n ");
printf("\n ");
printf("\n Enter the first digit of the number to be converted: ");
scanf("%d",&b1);
printf("\n Enter the second digit of the number to be converted: ");
scanf("%d",&b2);
printf("\n Enter the third digit of the number to be converted: ");
scanf("%d",&b3);
printf("\n Enter the fourth digit of the number to be converted: ");
scanf("%d",&b4);
printf("\n Enter the fifth digit of the number to be converted: ");
scanf("%d",&b5);
printf("\n Enter the sixth digit of the number to be converted: ");
scanf("%d",&b6);
printf("\n Enter the seventh digit of the number to be converted: ");
scanf("%d",&b7);
printf("\n Enter the eighth digit of the number to be converted: ");
scanf("%d",&b8);
printf("\n Enter the ninth digit of the number to be converted: ");
scanf("%d",&b9);
printf("\n Enter the tenth digit of the number to be converted: ");
scanf("%d",&b10);
printf("\n Enter the eleventh digit of the number to be converted: ");
scanf("%d",&b11);
printf("\n Enter the twelfth digit of the number to be converted: ");
scanf("%d",&b12);
printf("\n Enter the thirteenth digit of the number to be converted: ");
scanf("%d",&b13);
printf("\n Enter the fourteenth digit of the number to be converted: ");
scanf("%d",&b14);
printf("\n Enter the fifteenth digit of the number to be converted: ");
scanf("%d",&b15);
printf("\n Enter the sixteenth digit of the number to be converted: ");
scanf("%d",&b16);

printf("\n ");
f16=b16;
f15=b15*2;
f14=b14*2*2;
f13=b13*2*2*2;
f12=b12*2*2*2*2;
f11=b11*2*2*2*2*2;
f10=b10*2*2*2*2*2*2;
f9=b9*2*2*2*2*2*2*2;
f8=b8*2*2*2*2*2*2*2*2;
f7=b7*2*2*2*2*2*2*2*2*2;
f6=b6*2*2*2*2*2*2*2*2*2*2;
f5=b5*2*2*2*2*2*2*2*2*2*2*2;
f4=b4*2*2*2*2*2*2*2*2*2*2*2*2;
f3=b3*2*2*2*2*2*2*2*2*2*2*2*2*2;
f2=b2*2*2*2*2*2*2*2*2*2*2*2*2*2*2;
f1=b1*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2;
tf=f1+f2+f3+f4+f5+f6+f7+f8+f9+f10+f11+f12+f13+f14+f15+f16;
printf("\n ");

printf("\n %d%d%d%d %d%d%d%d %d%d%d%d %d%d%d%d in binary", b1 ,b2 ,b3 ,b4 ,b5 ,b6 ,b7 ,b8 ,b9 ,b10 ,b11 ,b12 ,b13 ,b14 ,b15 ,b16 );
printf(" = %d in decimal", tf);
printf("\n");
printf("\n _____________________ ");
printf("\n |[1] Reuse the program|");
printf("\n |[2] Exit |");
printf("\n |[3] Back to main menu|");
printf("\n |_____________________|");
printf("\n");
printf("\n Enter your choice: ");
scanf("%d",&again);

if(again == 1){
system("cls");}
else if (again==2){
for(x=60;x>=0;x--)
{
system("cls");
printf("Exiting the system in: ");
printf("\n%d",x);
}
system("cls");
printf("\n");
printf("\n");
printf("\n");
printf("\n Exiting the system...");
printf("\n ");
printf("\n GOOD BYE!!!");
printf("\n");
printf("\n");
printf("\n");}
} while (again==1);}
}


if(main==2){

do{

int r11,r12,r13,r21,r22,r23,r31,r32,r33,
l11,l12,l13,l21,l22,l23,l31,l32,l33,
a11,a12,a13,a21,a22,a23,a31,a32,a33;

system("cls");
printf("\n ============================================== ");
printf("\n || WELCOME TO THE BASIC OPERATIONS FOR 3x3 || ");
printf("\n || MATRICES MENU || ");
printf("\n ============================================== ");
printf("\n");
printf("\n ================================================== ");
printf("\n // PRESS: \\ ");
printf("\n ||[1] ADDITION OF MATRICES. ||");
printf("\n ||[2] MULTIPLICATION OF MATRICES. ||");
printf("\n \\ // ");
printf("\n ================================================== ");
printf("\n ++++++++ ");
printf("\n ENTER YOUR CHOICE:+++> ");
scanf("%d",& matri);
printf(" ++++++++ ");
printf("\n ");
printf("\n ");
printf("\n");
printf("\n");
getch();

printf("\n ENTER r11 : ");
scanf("%d",&r11);
printf("\n ENTER r12 : ");
scanf("%d",&r12);
printf("\n ENTER r13 : ");
scanf("%d",&r13);
printf("\n ENTER r21 : ");
scanf("%d",&r21);
printf("\n ENTER r22 : ");
scanf("%d",&r22);
printf("\n ENTER r23 : ");
scanf("%d",&r23);
printf("\n ENTER r31 : ");
scanf("%d",&r31);
printf("\n ENTER r32 : ");
scanf("%d",&r32);
printf("\n ENTER r33 : ");
scanf("%d",&r33);


printf("\n ENTER l11 : ");
scanf("%d",&l11);
printf("\n ENTER l12 : ");
scanf("%d",&l12);
printf("\n ENTER l13 : ");
scanf("%d",&l13);
printf("\n ENTER l21 : ");
scanf("%d",&l21);
printf("\n ENTER l22 : ");
scanf("%d",&l22);
printf("\n ENTER l23 : ");
scanf("%d",&l23);
printf("\n ENTER l31 : ");
scanf("%d",&l31);
printf("\n ENTER l32 : ");
scanf("%d",&l32);
printf("\n ENTER l33 : ");
scanf("%d",&l33);


if(matri==1){


system("cls");
printf("\n ====================================== ");
printf("\n // \\ ");
printf("\n || Welcome to the addition of matrices || ");
printf("\n \\ // ");
printf("\n ====================================== ");
printf("\n ");
printf("\n o================================================o ");
printf("\n \\ \\ ");
printf("\n )) Direction: Follow this format while inserting ))");
printf("\n // the value of your matrices. // ");
printf("\n (( R=right matrix L=left matrix A=added matrices (( ");
printf("\n \\ _ _ _ _ \\ ");
printf("\n )) | | | | ))");
printf("\n // | r11 r21 r31 | _ | 4 7 3 | // ");
printf("\n (( | r12 r22 r32 | _ | 16 9 5 | (( ");
printf("\n \\ | r13 r23 r33 | | 7 12 11 | \\ ");
printf("\n )) |_ _| |_ _| ))");
printf("\n o=================================================o ");
printf("\n ");
printf("\n ");

printf("\n _ _ " );
printf("\n | |" );
printf("\n | %d %d %d |",r11,r21,r31);
printf("\n | %d %d %d |",r12,r22,r32);
printf("\n | %d %d %d |",r13,r23,r33 );
printf("\n |_ _|" );

printf("\n _ _ " );
printf("\n | |" );
printf("\n | %d %d %d |",l11,l21,l31);
printf("\n | %d %d %d |",l12,l22,l32);
printf("\n | %d %d %d |",l13,l23,l33);
printf("\n |_ _|" );

a11=r11+l11;
a12=r12+l12;
a13=r13+l13;
a21=r21+l21;
a22=r22+l22;
a23=r23+l23;
a31=r31+l31;
a32=r32+l32;
a33=r33+l33;

printf("\n The answer is: ");
printf("\n _ _ " );
printf("\n | |" );
printf("\n | %d %d %d |", a11,a21,a31);
printf("\n | %d %d %d |", a12,a22,a32);
printf("\n | %d %d %d |", a13,a23,a33);
printf("\n |_ _|" );

printf("\n");
printf("\n _____________________ ");
printf("\n |[1] Reuse the program|");
printf("\n |[2] Exit |");
printf("\n |[3] Back to main menu|");
printf("\n |_____________________|");
printf("\n");
printf("\n Enter your choice: ");
scanf("%d",&again);

if(again == 1){
system("cls");}
else if (again==2){
for(x=60;x>=0;x--)
{
system("cls");
printf("Exiting the system in: ");
printf("\n%d",x);
}
system("cls");
printf("\n");
printf("\n");
printf("\n");
printf("\n Exiting the system...");
printf("\n ");
printf("\n GOOD BYE!!!");
printf("\n");
printf("\n");
printf("\n");}

}

else if(matri==2){
system("cls");
printf("\n ========================================= ");
printf("\n // \\ ");
printf("\n ||Welcome to the multiplication of matrices || ");
printf("\n \\ // ");
printf("\n ========================================= ");
printf("\n ");
printf("\n o================================================o ");
printf("\n \\ \\ ");
printf("\n )) Direction: Follow this format while inserting ))");
printf("\n // the value of your matrices. // ");
printf("\n (( R=right matrix L=left matrix A=added matrices (( ");
printf("\n \\ _ _ _ _ \\ ");
printf("\n )) | | | | ))");
printf("\n // | r11 r21 r31 | _ | 4 7 3 | // ");
printf("\n (( | r12 r22 r32 | _ | 16 9 5 | (( ");
printf("\n \\ | r13 r23 r33 | | 7 12 11 | \\ ");
printf("\n )) |_ _| |_ _| ))");
printf("\n o=================================================o ");
printf("\n ");
printf("\n ");


printf("\n _ _ " );
printf("\n | |" );
printf("\n | %d %d %d |",r11,r21,r31);
printf("\n | %d %d %d |",r12,r22,r32);
printf("\n | %d %d %d |",r13,r23,r33 );
printf("\n |_ _|" );

printf("\n _ _ " );
printf("\n | |" );
printf("\n | %d %d %d |",l11,l21,l31);
printf("\n | %d %d %d |",l12,l22,l32);
printf("\n | %d %d %d |",l13,l23,l33);
printf("\n |_ _|" );


a11=(r11*l11)+(r21*l12)+(r31*l13) ;
a21=(r11*l21)+(r21*l22)+(r31*l23) ;
a31=(r11*l31)+(r21*l32)+(r31*l33) ;
a12=(r12*l11)+(r22*l12)+(r32*l13) ;
a22=(r12*l21)+(r22*l22)+(r32*l23) ;
a32=(r12*l31)+(r22*l32)+(r32*l33) ;
a13=(r13*l11)+(r23*l12)+(r33*l13) ;
a23=(r13*l21)+(r23*l22)+(r33*l23) ;
a33=(r13*l31)+(r23*l32)+(r33*l33) ;


printf("\n The answer is: ");
printf("\n _ _ " );
printf("\n | |" );
printf("\n | %d %d %d |", a11,a21,a31);
printf("\n | %d %d %d |", a12,a22,a32);
printf("\n | %d %d %d |", a13,a23,a33);
printf("\n |_ _|" );

printf("\n");
printf("\n _____________________ ");
printf("\n |[1] Reuse the program|");
printf("\n |[2] Exit |");
printf("\n |[3] Back to main menu|");
printf("\n |_____________________|");
printf("\n");
printf("\n Enter your choice: ");
scanf("%d",&again);

if(again == 1){
system("cls");}
else if (again==2){
for(x=60;x>=0;x--)
{
system("cls");
printf("Exiting the system in: ");
printf("\n%d",x);
}
system("cls");
printf("\n");
printf("\n");
printf("\n");
printf("\n Exiting the system...");
printf("\n ");
printf("\n GOOD BYE!!!");
printf("\n");
printf("\n");
printf("\n");}

}
}while(again==1);

}

}while(again==3);
}


See More: Conversion from Bottom-up to Top-down design...

Report •

#1
March 26, 2012 at 18:38:51
✔ Best Answer
You just need to design your program from the top down, and then rebuild it piece by piece. You already have all the pieces. Start by creating a structure chart.

main() should not do anything but call other functions. Looks to me like main() should call three functions: mainmenu(), numconvtr() and matrixops(). numconvtr() should call nummenu(), octalconvtr(), etc. Put in stubs for any functions you have not completed yet.

When I analyze crap like this, I like to print it out on one long tractor-feed sheet, or tape all the pages together in sequence, then bracket each level of nesting using a different color of highlighter. It's just a rote exercise from there to piece together each function one at a time.


Report •

#2
March 29, 2012 at 01:35:50
thanks for that

Report •
Related Solutions


Ask Question