您的位置:首页 > 理论基础 > 数据结构算法

MFC学习笔记1 建立工程 C数据结构

2017-11-21 16:52 465 查看
本系列学习笔记来源于《VC++就业培训宝典之MFC视频教程》,记录自己系统化学习VC++过程

简介

MFC(Microsoft Foundation Classes) 微软基础类库。

MFC 还提供了一个应用程序框架,例如应用程序导和类向导自动生成的代码,大大减少了软件开发者的工作量,提高了开发效率。

学习环境: VC++6.0

第一个控制台程序



点组件-全部重建, 编译,执行



输入数字计算

// First.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
int main(int argc, char* argv[])
{
printf("input numbers !\n");
int a,b;
scanf("%d %d", &a, &b);
printf("%d + %d= %d \n", a,b,a+b);
return 0;
}




全局变量与全局函数

#include "stdafx.h"
#include <stdio.h>
int g_nTet = 32;
int g_nT2 = 11;
void Test(){
int a,b;
scanf("%d %d", &a, &b);
printf("%d + %d= %d \n", a,b,a+b);
}
int main(int argc, char* argv[])
{
printf("input numbers !\n");
Test();
return 0;
}




结构体

成员变量默认是公有的

struct SInfo
{
int nNumber;
char sName[20];
float fSalary;
}




成员变量默认是私有的

#include "stdafx.h"
#include <stdio.h>
int g_nTet = 32;
int g_nT2 = 11;
struct SInfo { int nNumber; char sName[20]; float fSalary; };
class CTest{
public:
int a,b;
char sName[20];
void Display(){
printf("a=%d,b=%d,Name=%s",a,b,sName);
}
};
void Test(){
int a,b;
scanf("%d %d", &a, &b);
printf("%d + %d= %d \n", a,b,a+b);
}
int main(int argc, char* argv[])
{
printf("input numbers !\n");
Test();
return 0;
}





代码格式设置



设置:

- Number 红色

- String 紫色

清除输入缓存与switch分支语句

// First.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
int g_nT2 = 11;

void Test()
{
int a,b;
char c;
const int t=10;
scanf("%d %d",&a,&b);
printf("请输入运算符号:[+、-、*、/]");
//输入缓存的清理
fflush(stdin);
scanf("%c",&c);
int nRet = 0;
switch(c)
{
case '+':
nRet = a+b;
break;
case '-':
nRet = a-b;
break;
case '*':
nRet= a*b;
break;
case '/':
nRet = a/b;
break;
}
printf("运行结果:%d%c%d=%d\n",a,c,b,nRet);

}
int main(int argc,char* argv[])
{
g_nT2 = 122;
Test();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: