Plz,我需要帮助的人。 C ++ GUI问题(使用MFC) [英] Plz, I need help guys. C++ GUI problem (with MFC)

查看:64
本文介绍了Plz,我需要帮助的人。 C ++ GUI问题(使用MFC)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我需要帮助。



我不知道如何使用MFC。



但是,教授要我解决这个问题。



问题是'2 * 4卡诺图最小化'用C ++



另外,我必须用MFC制作GUI。



如何要做这个问题??



请帮助!



我尝试了什么:



Hello guys.

I need a help.

I don`t know how to use MFC.

But, The professor wants me to do this problem.

The Problem is making '2*4 karnaugh map minimizer' with C++

additonally, I have to make GUI with MFC.

how to do this problem ??

plz help!

What I have tried:

// ConsoleApplication9.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//

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

int GetWord();
void PutKar();
void SolveKar();
void SolveQuad();
void SolvePair(int single);
int CountQuadPair(int a);
void PrintKar();
void MatchFunc();

char *charArr = 0; //입력값을 저장할때 값의 주소값을 확인
int karnaughVar[8] = { 8,8,8,8,8,8,8,8 }; // 입력받는 변수를 저장
int karnaughVarNum = 0; //입력받는 변수의 개수를 저장
int errCode = 0;
int karMap[2][5][2] = { 0 }; //카르노맵을 표현하기위한 배열변수
int quad[6] = { 0 }; //함수식을 쓰기위해 어느 쿼드가 그룹되었는지 저장 순서는 0145가 처음 2064가 마지막
int pair[12] = { 0 }; //가로 페어 01 > 13 > 32 > 20 > 45 > 57 > 76 > 64 순 (옆으로 갔다 밑으로) 그다음 세로 페어 04가 처음 26이 마지막
int single[8] = { 0 }; //쿼드나 페어가 안됬을때 저장
char func[50] = { 0 }; 


int main(void)
{
 int i = 0;
 char inPutChar[30];
 char temp[5];

 printf("F = ∑(");
 scanf_s("%[^\n]", inPutChar,10);

 charArr = inPutChar;

 while (GetWord());

 if (errCode) return 0;

 PutKar();

 if (karnaughVarNum == 8)
 {
  sprintf_s(temp, "1");
  strcat_s(func, temp); //모든 함수가 1일때, 연산의 결과 temp에 저장
 }

 else if (karnaughVarNum == 0)
 {
  printf("값을 입력하지 않았습니다.\n"); //변수의 개수가 아무것도 없을 때 출력
  return 0;
 }

 else
 {
  SolveKar();

  MatchFunc();
 }

 PrintKar();


 return 0;
}


int GetWord()
{
 if (strchr(")", *charArr))  // strchr = 문자열에서 문자 검색. 8자리면 수동으로 했을 경우 많은 경우의수를 쓰겠지만 strchr 함수를 사용할 경우 한줄이면된다.
  return 0;


 if (strchr("01234567", *charArr))
 {
  karnaughVar[karnaughVarNum] = *charArr - 48;
  karnaughVarNum++;
  charArr++;
  return 1;   
 }

 else if (strchr(", ", *charArr))
 {
  charArr++;
  return 1;
 }

 else
 {
  printf("잘못 입력하였습니다. 입력할수있는 문자는 숫자(0 ~ 7), 반점, 괄호, 공백입니다.\n");
  errCode = 1;
  return 0;
 }

}

void PutKar() // 함수값을 넣는 과정 (PutKar에서의 순서는 0 1 3 2 
              //                    (                    4 5 7 6)
{
 int i, j;

 for (i = 0; i < 3; i++)
  for (j = 0; j < 4; j++)
   karMap[i][j][1] = 2; //입력받지않은 값은 2로 초기화 
         //페어나 쿼드로 묶여 있으면 1
         //안묶여있으면 0


 for (i = 0; i < 8; i++) 
 {                      
  switch (karnaughVar[i])  //0혹은 1이 들어갔을 때 함수가 출력되도록 함. 나머지 숫자가 들어갈경우 2로 초기화.(0,1이아니므로 출력X)
  {                      
  case 0:
   karMap[0][0][0] = 1;       //-> 최종에 printf에서 1로 출력
   karMap[0][0][1] = 0;       //-> 최종에 printf에서 0으로 출력
   break;
  case 1:
   karMap[0][1][0] = 1;
   karMap[0][1][1] = 0;
   break;
  case 2:
   karMap[0][3][0] = 1;
   karMap[0][3][1] = 0;
   break;
  case 3:
   karMap[0][2][0] = 1;
   karMap[0][2][1] = 0;
   break;
  case 4:
   karMap[1][0][0] = 1;
   karMap[1][0][1] = 0;
   break;
  case 5:
   karMap[1][1][0] = 1;
   karMap[1][1][1] = 0;
   break;
  case 6:
   karMap[1][3][0] = 1;
   karMap[1][3][1] = 0;
   break;
  case 7:
   karMap[1][2][0] = 1;
   karMap[1][2][1] = 0;
   break;
  }
 }

 for (i = 0; i < 2; i++)
 {
  karMap[i][4][0] = karMap[i][0][0]; // 맨앞, 맨뒤가 pair가 될 수 있으므로, (i,4) 함수를 (i,0) 함수와 같게 해준다.
  karMap[i][4][1] = karMap[i][0][1];
 }
}

void SolveKar() // 함수를 풀어, temp에 저장하는 과정
{
 int i, j;
 SolveQuad();

 SolvePair(0);

 SolvePair(1);

 for (i = 0; i < 2; i++)
 {
  for (j = 0; j < 4; j++)
  {
   if (karMap[i][j][0] == 1 && karMap[i][j][1] == 0) // &&는 AND를 의미. (i,j,0)이 1임과 동시에 (i,j,1)이 0이면 싱글로 저장된다.
   {                                                 // 이 과정이 i = 0,1 j = 0,1,2,3 반복. AND는 두 명제가 참일때 1이 됨.
    karMap[i][j][1] = 1;
    single[((i * 4) + j)] = 1;
    printf("single[%d]\n", (i*4)+j); 
   }
  }
 }
}

void SolveQuad()
{
 int i;

 for (i = 0; i < 3; i++)
 {   
  if (karMap[0][i][0] == 1 && karMap[0][i + 1][0] == 1 && karMap[1][i][0] == 1 && karMap[1][i + 1][0] == 1
   && (karMap[0][i][1] == 0 || karMap[0][i + 1][1] == 0 || karMap[1][i][1] == 0 || karMap[1][i + 1][1] == 0))
  {                               //(1 1 0 0)
   karMap[0][i][1] = 1;        //(1 1 0 0) 이면 쿼드, 오른쪽으로 한칸씩 증가함. 8개의 조건을 모두 만족해야 참값
   karMap[0][i + 1][1] = 1;   
   karMap[1][i][1] = 1;       
   karMap[1][i + 1][1] = 1;   //각 항이 쿼드나 페어로 묶여있을 때 개수체크.
   quad[i] = 1;              
   printf("quad[%d]\n", i);  //쿼드의 개수를 프린트함.
  }
 }

 if (karMap[0][0][0] == 1 && karMap[1][0][0] == 1 && karMap[0][3][0] == 1 && karMap[1][3][0] == 1         // (1 0 0 1)
  && (karMap[0][0][1] == 0 || karMap[1][0][1] == 0 || karMap[0][3][1] == 0 || karMap[1][3][1] == 0))   // (1 0 0 1)
 {
  karMap[0][0][1] = 1;
  karMap[0][3][1] = 1;
  karMap[1][0][1] = 1;
  karMap[1][3][1] = 1;
  karMap[1][4][1] = 1;
  karMap[1][4][1] = 1;
  quad[3] = 1;
  printf("quad[3]\n");  
 }  //정사각형 쿼드

 for (i = 0; i < 2; i++)
 {
  if (karMap[i][0][0] == 1 && karMap[i][1][0] == 1 && karMap[i][2][0] == 1 && karMap[i][3][0] == 1
   && (karMap[i][0][1] == 0 || karMap[i][1][1] == 0 || karMap[i][2][1] == 0 || karMap[i][3][1] == 0))
  {
   karMap[i][0][1] = 1;
   karMap[i][1][1] = 1;
   karMap[i][2][1] = 1;
   karMap[i][3][1] = 1;
   karMap[i][4][1] = 1;
   quad[i + 4] = 1; 
   printf("quad[%d]\n", i+4);  
  }
 } //가로 4개가 1일때 (1 1 1 1)
}       //                 (0 0 0 0)

void SolvePair(int single)
{
 int i, j;

 for (i = 0; i < 2; i++) //0,1
 {
  for (j = 0; j < 5; j++) //0,1,2,3,4 ( 4 = 0)
  {
   if (karMap[i][j][0] == 1 && karMap[i][j][1] == 0)
   {
    if (karMap[i + 1][j][0] == 1 && karMap[i + 1][j][1] == single) 
    {
     if (i + 1 <= 1 && j != 4)  //항과 아래항, != -> 같지 않음.
     {
      karMap[i][j][1] = 1;
      karMap[i + 1][j][1] = 1;
      pair[(i * 4) + j + 8] = 1;
      printf("pair[%d]\n", (i*4)+j+8);  
     }
    }

    else if (karMap[i - 1][j][0] == 1 && karMap[i - 1][j][1] == single) //항과 윗항
    {
     if (i - 1 >= 0 && j != 4)
     {
      karMap[i][j][1] = 1;
      karMap[i - 1][j][1] = 1;
      pair[i + j + 8 - 1] = 1;
      printf("pair[%d]\n", (i+j+8-1)); 
     }
    }

    else if (karMap[i][j + 1][0] == 1 && karMap[i][j + 1][1] == single) //항과 오른쪽항
    {
     if (j + 1 <= 4)
     {
      karMap[i][j][1] = 1;
      karMap[i][j + 1][1] = 1;
      if (j == 0)
       karMap[i][4][1] = karMap[i][0][1];
      else if (j == 3)
       karMap[i][0][1] = karMap[i][4][1];
      pair[(i * 4) + j] = 1;
      printf("pair[%d]\n", (i*4)+j); 
     }
    }

    else if (karMap[i][j - 1][0] == 1 && karMap[i][j - 1][1] == single) //항과 왼쪽항
    {
     if (j - 1 >= 0)
     {
      karMap[i][j][1] = 1;
      karMap[i][j - 1][1] = 1;
      if (j == 4)
       karMap[i][0][1] = karMap[i][4][1];
      pair[(i * 4) + j - 1] = 1;
      printf("pair[%d]\n", (i*4)+j-1);
     }
    }
   }
  }
 }
}

int CountQuadPair(int a) //페어, 쿼드의 개수를 'temp'에 저장하는 과정
{
 int i = 0, temp = 0;

 if (a == 1)
 {
  for (i = 0; i < 6; i++)  // quad일 때의 함수의 개수 temp에 저장 6가지 경우의 수. (4개짜리 4개, 6개짜리 2개 0145, 3276)
  {
   if (quad[i] == 1)
    temp += 1;
  }
 }

 else if (a == 2)
 {
  for (i = 0; i < 12; i++) //pair일때의 함수의 개수 temp에 저장. 01 > 13 > 32 > 20 > 45 > 57 > 76 > 64, 04 > 15 > 37 > 26 순으로 연산후 저장
  {
   if (pair[i] == 1)
    temp += 1;
  }
 }

 else if (a == 3)
 {
  for (i = 0; i < 8; i++) // single일 때의 함수의 개수 temp에 저장 0,1,2,3,4,5,6,7
  {
   if (single[i] == 1)
    temp += 1;
  }
 }

 return temp;
}


void PrintKar() // 위에서 저장받은 0,1값을 집어넣음. 
{
 printf("\n");
 printf("x|yz 00    01    11    10\n");
 printf("  ------------------------\n");
 printf("0|   %d |   %d |   %d |   %d |   Quad : %d개\n", karMap[0][0][0], karMap[0][1][0], karMap[0][2][0], karMap[0][3][0], CountQuadPair(1)); //
 printf("  ------------------------   Pair : %d개\n", CountQuadPair(2));
 printf("1|   %d |   %d |   %d |   %d |   Single : %d개\n", karMap[1][0][0], karMap[1][1][0], karMap[1][2][0], karMap[1][3][0], CountQuadPair(3));
 printf("  ------------------------   F : %s\n", func);
}

void MatchFunc() // temp에 저장되어있는 메모리에서 데이터를 가져오며, 최종함수 F에 결과값을 나타내는 과정 배열 'func' 가 함수의 최종연산값.
{
 int quadPairCount = CountQuadPair(1) + CountQuadPair(2) + CountQuadPair(3) - 1, i = 0;
 char temp[10] = { 0 };
 printf("%d\n", quadPairCount+1); 
 //sprintf = 문자배열 저장, 출력.
 if (quad[0] == 1) { sprintf_s(temp, "y`"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (quad[1] == 1) { sprintf_s(temp, "z"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (quad[2] == 1) { sprintf_s(temp, "y"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (quad[3] == 1) { sprintf_s(temp, "z`"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (quad[4] == 1) { sprintf_s(temp, "x`"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (quad[5] == 1) { sprintf_s(temp, "x"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (pair[0] == 1) { sprintf_s(temp, "x`y`"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (pair[1] == 1) { sprintf_s(temp, "x`z"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (pair[2] == 1) { sprintf_s(temp, "x`y"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (pair[3] == 1) { sprintf_s(temp, "x`z`"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (pair[4] == 1) { sprintf_s(temp, "xy`"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (pair[5] == 1) { sprintf_s(temp, "xz"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (pair[6] == 1) { sprintf_s(temp, "xy"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (pair[7] == 1) { sprintf_s(temp, "xz`"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (pair[8] == 1) { sprintf_s(temp, "y`z`"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (pair[9] == 1) { sprintf_s(temp, "y`z"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (pair[10] == 1) { sprintf_s(temp, "yz"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (pair[11] == 1) { sprintf_s(temp, "yz`"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (single[0] == 1) { sprintf_s(temp, "x`y`z`"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (single[1] == 1) { sprintf_s(temp, "x`y`z"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (single[2] == 1) { sprintf_s(temp, "x`yz"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (single[3] == 1) { sprintf_s(temp, "x`yz`"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (single[4] == 1) { sprintf_s(temp, "xy`z`"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (single[5] == 1) { sprintf_s(temp, "xy`z"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (single[6] == 1) { sprintf_s(temp, "xyz"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
 if (single[7] == 1) { sprintf_s(temp, "xyz`"); strcat_s(func, temp); if (quadPairCount > i) { sprintf_s(temp, " + "); strcat_s(func, temp); i++; } }
}

推荐答案

我们不做你的作业:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是和你想的一样困难!



如果遇到具体问题,请询问相关问题,我们会尽力提供帮助。但是我们不打算为你做这一切!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!


参见 MFC桌面应用程序 [ ^ ]。


一些提示:



a)写明文代码,lomg名称和ALL in englisch(也评论)

b)最多使用类一些MVVM架构

c)make子任务(比如计算和GUI

d)使用带有CDocument的向导MFC项目(在你绘制输出的OnDrawDocument中)

e)使用测试数据

f)在错误条件和边缘情况下进行TRACE输出

g)使用VISUAL STUDIO并参观一些教程



祝你好作业
Some tips:

a) write clear code, lomg names and ALL in englisch (also comments)
b) use classes at best some MVVM architecture
c) make sub tasks (like the computation and than GUI
d) use a wizard MFC project with CDocument (in the OnDrawDocument you draw the output)
e) use test data
f) make TRACE output on error conditions and edge cases
g) use VISUAL STUDIO and visit some tutorials

Good luck with your homework


这篇关于Plz,我需要帮助的人。 C ++ GUI问题(使用MFC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆