怎样将下面的C语言代码改成用C++编写的?(下面程序代码为一部分) 5
#include"stdio.h"#include"stdlib.h"#include"ctype.h"#include"string.h"#include"conio....
#include "stdio.h"
#include "stdlib.h"
#include "ctype.h"
#include "string.h"
#include "conio.h"
#include "malloc.h"
#include "windows.h"
typedef struct //定义结构体
{
char type[20];
int Getsum;
char place[20];
int time;
}family;
family fam[100];
int m;
int menu_select()
{
char c;
do{
system("cls");
printf("\t\t***************************\n");
printf("\t\t**********菜单系统*********\n");
printf("\t\t|| 1.输入月份 ||\n");
printf("\t\t|| 2.输入消费金额 ||\n");
printf("\t\t|| 3.计算消费总和 ||\n");
printf("\t\t|| 4.支出情况 ||\n");
printf("\t\t|| 5.消费分析 ||\n");
printf("\t\t|| 6.按消费价格排序 ||\n");
printf("\t\t|| 7.按消费类别排序 ||\n");
printf("\t\t|| 8.保存数据及结果 ||\n");
printf("\t\t|| 9.退出系统 ||\n");
printf("\t\t***************************\n");
printf("\t\t***************************\n");
printf("\t\t\t请对应选择所需选项(0-9):");
c=getchar();
}while(c<'1'||c>'9');
return(c-'0');
}
void password()
{
char d[6];
char m[6];
m[0]='1',m[1]='2',m[2]='3',m[3]='4',m[4]='5',m[5]='6'; //数组比较
printf("请输入六位数密码:"); //输入密码
for (int n=0;;)
{
for(int i=0;i<6;i++)
{
d[i]=getch();
if(d[i]>='0'||d[i]<='9'||d[i]>='a'||d[i]<='z'||d[i]>='A'||d[i]<='Z')
putchar('*');
}
if(d[0]==m[0]&&d[1]==m[1]&&d[2]==m[2]&&d[3]==m[3]&&d[4]==m[4]&&d[5]==m[5])
{
printf("\n欢迎使用!\n");break;
}
if(d[0]!=m[0]||d[1]!=m[1]||d[2]!=m[2]||d[3]!=m[3]||d[4]!=m[4]||d[5]!=m[5]) //当密码错误时如下
printf("\n密码错误!请重新输入:");
if (n>3)
{
printf("error\n");
exit (0);
}
n++;
}
}
void yuefen(int m)
{
scanf("%d\n",&m);
} 展开
#include "stdlib.h"
#include "ctype.h"
#include "string.h"
#include "conio.h"
#include "malloc.h"
#include "windows.h"
typedef struct //定义结构体
{
char type[20];
int Getsum;
char place[20];
int time;
}family;
family fam[100];
int m;
int menu_select()
{
char c;
do{
system("cls");
printf("\t\t***************************\n");
printf("\t\t**********菜单系统*********\n");
printf("\t\t|| 1.输入月份 ||\n");
printf("\t\t|| 2.输入消费金额 ||\n");
printf("\t\t|| 3.计算消费总和 ||\n");
printf("\t\t|| 4.支出情况 ||\n");
printf("\t\t|| 5.消费分析 ||\n");
printf("\t\t|| 6.按消费价格排序 ||\n");
printf("\t\t|| 7.按消费类别排序 ||\n");
printf("\t\t|| 8.保存数据及结果 ||\n");
printf("\t\t|| 9.退出系统 ||\n");
printf("\t\t***************************\n");
printf("\t\t***************************\n");
printf("\t\t\t请对应选择所需选项(0-9):");
c=getchar();
}while(c<'1'||c>'9');
return(c-'0');
}
void password()
{
char d[6];
char m[6];
m[0]='1',m[1]='2',m[2]='3',m[3]='4',m[4]='5',m[5]='6'; //数组比较
printf("请输入六位数密码:"); //输入密码
for (int n=0;;)
{
for(int i=0;i<6;i++)
{
d[i]=getch();
if(d[i]>='0'||d[i]<='9'||d[i]>='a'||d[i]<='z'||d[i]>='A'||d[i]<='Z')
putchar('*');
}
if(d[0]==m[0]&&d[1]==m[1]&&d[2]==m[2]&&d[3]==m[3]&&d[4]==m[4]&&d[5]==m[5])
{
printf("\n欢迎使用!\n");break;
}
if(d[0]!=m[0]||d[1]!=m[1]||d[2]!=m[2]||d[3]!=m[3]||d[4]!=m[4]||d[5]!=m[5]) //当密码错误时如下
printf("\n密码错误!请重新输入:");
if (n>3)
{
printf("error\n");
exit (0);
}
n++;
}
}
void yuefen(int m)
{
scanf("%d\n",&m);
} 展开
1个回答
展开全部
//Ps:你#include的方式有问题,全部要用<>括起来,如#include<iostream> 其实c++是基本兼容c的
#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <conio.h>
#include <malloc.h>
#include <windows.h>
using namespace std;
typedef class //定义类
{
public:
char type[20];
int Getsum;
char place[20];
int time;
}family;
family fam[100];
int m;
int menu_select()
{
char c;
do{
system("cls");
cout<<"\t\t***************************\n";
cout<<\t\t**********菜单系统************\n";
cout<<"\t\t|| 1.输入月份 ||\n";
cout<<"\t\t|| 2.输入消费金额 ||\n";
cout<<"\t\t|| 3.计算消费总和 ||\n";
cout<<"\t\t|| 4.支出情况 ||\n";
cout<<"\t\t|| 5.消费分析 ||\n";
cout<<"\t\t|| 6.按消费价格排序 ||\n";
cout<<"\t\t|| 7.按消费类别排序 ||\n";
cout<<"\t\t|| 8.保存数据及结果 ||\n";
cout<<"\t\t|| 9.退出系统 ||\n";
cout<<"\t\t***************************\n";
cout<<"\t\t***************************\n";
cout<<"\t\t\t请对应选择所需选项(0-9):";
c=getchar();
}while(c<'1'||c>'9');
return(c-'0');
}
void password()
{
char d[6];
char m[6];
m[0]='1',m[1]='2',m[2]='3',m[3]='4',m[4]='5',m[5]='6'; //数组比较
cout<<"请输入六位数密码:"; //输入密码
for (int n=0;;)
{
for(int i=0;i<6;i++)
{
d[i]=getch();
if(d[i]>='0'||d[i]<='9'||d[i]>='a'||d[i]<='z'||d[i]>='A'||d[i]<='Z')
putchar('*');
}
if(d[0]==m[0]&&d[1]==m[1]&&d[2]==m[2]&&d[3]==m[3]&&d[4]==m[4]&&d[5]==m[5])
{
cout<<"\n欢迎使用!\n";break;
}
if(d[0]!=m[0]||d[1]!=m[1]||d[2]!=m[2]||d[3]!=m[3]||d[4]!=m[4]||d[5]!=m[5]) //当密码错误时如下
cout<<"\n密码错误!请重新输入:";
if (n>3)
{
cout<<"error\n";
exit (0);
}
n++;
}
}
void yuefen(int m)
{
cin>>m;
}
#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <conio.h>
#include <malloc.h>
#include <windows.h>
using namespace std;
typedef class //定义类
{
public:
char type[20];
int Getsum;
char place[20];
int time;
}family;
family fam[100];
int m;
int menu_select()
{
char c;
do{
system("cls");
cout<<"\t\t***************************\n";
cout<<\t\t**********菜单系统************\n";
cout<<"\t\t|| 1.输入月份 ||\n";
cout<<"\t\t|| 2.输入消费金额 ||\n";
cout<<"\t\t|| 3.计算消费总和 ||\n";
cout<<"\t\t|| 4.支出情况 ||\n";
cout<<"\t\t|| 5.消费分析 ||\n";
cout<<"\t\t|| 6.按消费价格排序 ||\n";
cout<<"\t\t|| 7.按消费类别排序 ||\n";
cout<<"\t\t|| 8.保存数据及结果 ||\n";
cout<<"\t\t|| 9.退出系统 ||\n";
cout<<"\t\t***************************\n";
cout<<"\t\t***************************\n";
cout<<"\t\t\t请对应选择所需选项(0-9):";
c=getchar();
}while(c<'1'||c>'9');
return(c-'0');
}
void password()
{
char d[6];
char m[6];
m[0]='1',m[1]='2',m[2]='3',m[3]='4',m[4]='5',m[5]='6'; //数组比较
cout<<"请输入六位数密码:"; //输入密码
for (int n=0;;)
{
for(int i=0;i<6;i++)
{
d[i]=getch();
if(d[i]>='0'||d[i]<='9'||d[i]>='a'||d[i]<='z'||d[i]>='A'||d[i]<='Z')
putchar('*');
}
if(d[0]==m[0]&&d[1]==m[1]&&d[2]==m[2]&&d[3]==m[3]&&d[4]==m[4]&&d[5]==m[5])
{
cout<<"\n欢迎使用!\n";break;
}
if(d[0]!=m[0]||d[1]!=m[1]||d[2]!=m[2]||d[3]!=m[3]||d[4]!=m[4]||d[5]!=m[5]) //当密码错误时如下
cout<<"\n密码错误!请重新输入:";
if (n>3)
{
cout<<"error\n";
exit (0);
}
n++;
}
}
void yuefen(int m)
{
cin>>m;
}
追问
就只是把printf、scanf改成cin、cout吗
追答
还改了struct(变成class)基本上这样就能体现出c++风格了,其实都差不多
如果真想彻底可以用类重写,但所用函数包括主函数main都要修改。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询