2
我在卡諾圖的分類有些問題,我不知道怎麼定義卡諾表中的各種情況,如何合羣在卡諾圖細胞
,如果我連續使用「如果」和「其他」的聲明,我認爲這是非常低級的編程,我想要一些算法,將被稱爲品種本身,還是少用「如果」和「其他」的語句 這裏我有卡諾圖的一些分類例如:
我的程序必須知道,這兩個「1」在一個類別中,並且將被分類爲 我怎麼能反覆灌輸這我的計劃,我怎樣才能實現這種分類 這是我的兩個變量卡諾圖碼:
int num_var; // stores the number of variables entered by user
int squ_4[4]; // variable used for a 1-D array for the 4 square Karnaugh map
int a,b,c; // variables for entering and checking values in Karnaugh map squares
char var_name[10]; // character string array
strcpy(var_name,"ABCDRSXYZ"); // character string for variable name
printf("\nThis program works out a Boolean function for a 2,3 and 4 variable Karnaugh map.\n\n");
cout << "Enter number of Karnaugh map variables (2,3 or 4) required: ";
cin >> num_var;
do
{
if(num_var>4)
{
printf("\n Sorry, you have chosen too many variables \n");
printf("\n Please enter 2,3 or 4 variables: ");
cin >> num_var;
}
if(num_var<2)
{
printf("\n Sorry, not enough variables chosen \n");
printf("\n Please enter 2,3 or 4 variables: ");
cin >> num_var;
}
}while(num_var>4 || num_var<2);
do
{
printf("\nVariables are: %c %c \n",var_name[4],var_name[5]); // output variable names
printf("\n Please enter value in Karnaugh map square and press RETURN \n")
for(a=0;a<4;a++)
{
printf("\nEnter 1 or 0 into square %d: ",a);
cin >> squ_4[a]; // store value into array
while(squ_4[a]!=0 && squ_4[a]!=1)
{
printf("\n Value entered in Karnaugh map square %d, was not 1 or 0 \n",a);
printf("\nPlease enter 1 or 0 into square %d: ",a);
cin >> squ_4[a];
}
}
printf("\nYour Karnaugh map is: \n\n\t\t %c'%c \n\t\t %c'%d %d\n\t\t %c %d %d \n",var_name[5],var_name[5],var_name[4],squ_4[0],squ_4[1],var_name[4],squ_4[2],squ_4[3]);
if(squ_4[0]==0 && squ_4[1]==0 && squ_4[2]==0 && squ_4[3]==0)
{
printf("\nThere is no function from the Karnaugh map\n\n");
return 0;
}
printf("\nThe Boolean function is: \n\n ");
if(squ_4[0]==1)
{
printf("%c'%c' ",var_name[4],var_name[5]);
if(squ_4[1]==1 || squ_4[2]==1 || squ_4[3]==1)
{
printf("+ ");
}
}
if(squ_4[1]==1)
{
printf("%c'%c ",var_name[4],var_name[5]);
if(squ_4[2]==1 || squ_4[3]==1)
{
printf("+ ");
}
}
if(squ_4[2]==1)
{
printf("%c%c' ",var_name[4],var_name[5]);
if(squ_4[3]==1)
{
printf("+ ");
}
}
if(squ_4[3]==1)
{
printf("%c%c ",var_name[4],var_name[5]);
}
cout << "\n\n\n\n";
}while(num_var==2);
是否有任何其他方式來實現這樣的事情? :\ – Ahmadreza