来个能人帮我改一个C语言程序变成C++会吗

白螝 2015-06-04 08:55:18
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#define false 0
#define true 1
#define MAX_ROW 50
#define MAX_COLUMN 50
typedef int bool;
typedef struct
{
float data[MAX_ROW][MAX_COLUMN];
int rows,columns;
} M,*pM;

void inputMatrix(M *m)
{
int i,j;
printf("请输入矩阵的行数和列数:\n");
scanf("%d",&m->rows);
scanf("%d",&m->columns);
printf("请按行输入矩阵的数据:\n");
for(i=0;i<m->rows;i++){
for(j=0;j<m->columns;j++){
scanf("%f",&m->data[i][j]);
}
}
}
void displayMatrix(M *m)
{
int i,j;
for(i=0;i<m->rows;i++){
for(j=0;j<m->columns;j++){
printf("%10.3f ",m->data[i][j]);
}
printf("\n");
}
printf("\n");
}
void transposeMatrix(M *m, M *res)
{
int i,j;
for(i=0;i<m->rows;i++){
for(j=0;j<m->columns;j++){
res->data[j][i]=m->data[i][j];
}
}
}
bool addMatrix(M *a, M *b, M *res)
{
int i,j;
if(a->rows==b->rows && a->columns==b->columns){
for(i=0;i<a->rows;i++){
for(j=0;j<a->columns;j++){
res->data[i][j]=a->data[i][j]+b->data[i][j];
}
}
}else{
printf("矩阵不能相加\n");
return false;
}
res->rows=a->rows;
res->columns=a->columns;
return true;
}
bool multiplyMatrix(M *a, M *b, M *res)
{
int i,j,k;
if(a->columns==b->rows){
for(i=0;i<a->rows;i++){
for(j=0;j<b->columns;j++){
for(k=0;k<a->columns;k++){
res->data[i][j]+=a->data[i][k]*b->data[k][j];
}
}
}
}else{
printf("矩阵不能相乘\n");
return false;
}
res->rows=a->rows;
res->columns=b->columns;
return true;
}
bool scalarMultiplyMatrix(M *m, float n, M *res)
{
int i,j;
for(i=0;i<m->rows;i++){
for(j=0;j<m->columns;j++){
res->data[i][j]=m->data[i][j]*n;
}
}
res->rows=m->rows;
res->columns=m->columns;
return true;
}
bool subtractMatrix(M *a, M *b, M *res)
{
int i,j;
if(a->rows==b->rows && a->columns==b->columns){
for(i=0;i<a->rows;i++){
for(j=0;j<a->columns;j++){
res->data[i][j]=a->data[i][j]-b->data[i][j];
}
}
}else{
printf("矩阵不能相减\n");
return false;
}
res->rows=a->rows;
res->columns=a->columns;
return true;
}
int main()
{
M A,B,res,finalRes,*tmpArg1,*tmpArg2;
bool bErr;
int sel;
char op[32],arg1[32],arg2[32];
//初始化
LABEL:
memset(&A,0,sizeof(M));
memset(&B,0,sizeof(M));
memset(&res,0,sizeof(M));
memset(&finalRes,0,sizeof(M));
printf("按提示输入矩阵A:\n");
inputMatrix(&A);
printf("按提示输入矩阵B:\n");
inputMatrix(&B);
LABEL1:
printf("选择要进行的操作:\n");
printf("1.输入算式\n");
printf("2.矩阵转置\n");
printf("3.打印矩阵\n");
printf("4.重新输入\n");
printf("0.退出\n");
scanf("%d",&sel);
memset(op,0,32);
memset(arg1,0,32);
memset(arg2,0,32);
switch (sel){
case 1:
memset(&finalRes,0,sizeof(M));
scanf("%s",op);
scanf("%s",arg1);
scanf("%s",arg2);
if(!strcmp(arg1,"A")){
tmpArg1=&A;
}else if(!strcmp(arg1,"B")){
tmpArg1=&B;
}else if(!strcmp(arg1,"res")){
tmpArg1=&res;
}
if(!strcmp(arg2,"B")){
tmpArg2=&B;
}else if(!strcmp(arg2,"A")){
tmpArg2=&A;
}else{
tmpArg2=&res;
}
if(!strcmp(op,"add")){
bErr=addMatrix(tmpArg1,tmpArg2,&finalRes);
}else if(!strcmp(op,"sub")){
bErr=subtractMatrix(tmpArg1,tmpArg2,&finalRes);
}else if(!strcmp(op,"mul")){
bErr=multiplyMatrix(tmpArg1,tmpArg2,&finalRes);
}else if(!strcmp(op,"smul")){
bErr=scalarMultiplyMatrix(tmpArg2,atof(arg1),&finalRes);
}
res=finalRes;
if(bErr)displayMatrix(&finalRes);
goto LABEL1;
case 2:
scanf("%s",arg1);
if(!strcmp(arg1,"A")){
transposeMatrix(&A,&finalRes);
}else if(!strcmp(arg1,"B")){
transposeMatrix(&B,&res);
}else if(!strcmp(arg1,"res")){
transposeMatrix(&res,&finalRes);
}
res=finalRes;
displayMatrix(&finalRes);
goto LABEL1;
case 3:
scanf("%s",arg1);
if(!strcmp(arg1,"A")){
displayMatrix(&A);
}else if(!strcmp(arg1,"B")){
displayMatrix(&B);
}else if(!strcmp(arg1,"res")){
displayMatrix(&res);
}
goto LABEL1;
case 4:
goto LABEL;
case 0:
return 0;
}
return 0;
}
...全文
451 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
小虾米醬~ 2019-06-16
  • 打赏
  • 举报
回复

麻烦帮忙改成c++的程序一下 蟹蟹#include<stdio.h>
#include<string.h>
#include<windows.h>
#include<conio.h>
#define bool char
#define true 1
#define false 0
#define NUM 100
// IC卡账户信息
struct cardInfo
{
char sno[20]; // 学号
char name[20]; // 姓名
char cardID[12]; // 卡号
float balance; // 余额
};

// 函数声明
bool login();
void menu(); // 主菜单
void openAccount(); // 开户
void showCardInfo(struct cardInfo card); // 显示账户信息的方法
void showCardInfos(struct cardInfo cards[], int count);
void view(); // 显示所有账户信息
void income(); // 充值
void init(); // 初始化
void saveData(); // 保存数据
void search(); // 查找

struct cardInfo cards[NUM]; // 用来存放所有的账户信息
int TOTALCOUNT = 0; // 记录数
bool isEnd = false; // 是否退出系统

int main()
{

bool bl = 0;
int count = 0; // 用户记录输入输入账号和密码的次数,最多允许输入3次

do
{
if (count == 3)
{
break; // 跳出while循环
}

if (count > 0)
{ // 说明不是第一次登陆
printf("\n\n\t账号或密码错误,请确认后重新登录...");
printf("\n\n\t您还有 %d 次机会<请按回车继续>", 3-count);
getch();
}
count++;
bl = login(); // 调用登陆的方法,实现用户登陆
}while( !bl );

// 问题:当用户登陆成功也会跳出while,如果超过3次也会跳出while

if ( !bl )
{
printf("\n\n\t对不起,您暂无权限...\n\t");
system("exit");
} else // 登陆成功
{
init(); // 初始化数据,即将数据从数据文件读取到系统中

do{
menu(); // 显示主菜单
}while(!isEnd);
}

printf("\n\n\t");
exit;
system("exit /B");
}

// 主菜单
void menu()
{
int flag = 0 ;
system("cls");
printf("\n\t**********************湖南工学院IC卡管理系统**********************");
printf("\n\t************************** 1. IC卡开户 **************************");
printf("\n\t************************** 2. 查询IC卡信息 ***********************");
printf("\n\t************************** 3. 浏览IC卡信息 ***********************");
printf("\n\t************************** 4. IC卡充值 ************************");
printf("\n\t************************** 5. 修改IC卡信息 ***********************");
printf("\n\t************************** 6. 退出系统 ************************");

printf("\n\n\t请选择您要进行的操作(1-6):");
scanf("%d",&flag);
switch(flag)
{
case 1:openAccount(); break;
case 2:search(); break;
case 3:view(); break;
case 4:income(); break;
case 5: break;
case 6:saveData(); isEnd=true; break;
default:break;
}
}

// 用户登录方法
bool login()
{
char name[20]; // 存储用户输入的账号
char pwd[20], ch; // 存储用户输入的密码
int index = 0; // 输入密码的位数

system("cls");

printf("\n\t**********************湖南工学院IC卡管理系统**********************");
printf("\n\n\t请输入您的账号:");
// 获取用户输入的账号
scanf("%s", name);

printf("\n\t请输入您的密码:");
// 获取用户输入的密码
while ( (ch=getch()) != 13 ) // 不是回车键
{
if ( ch ==8 ) // 如果是退格 Backspace
{
if(index <= 0)
{
index = 0;
}
else
{
printf("\b \b");
index --;
}
}
else
{
pwd[index++] = ch;
putch('*');
}
}
pwd[index] = '\0';
//scanf("%s", pwd); // 当用户输入密码时,如何用掩码的方式显示 ***

// 比较用户输入的账号和密码是否正确。如果用户输入的账号是yc 并且密码是 123321,则认为是合法的用户,那么跳转到主界面,否则提示错误。
if ( strcmp("yc",name) == 0 && strcmp("123321", pwd) == 0)
{
return true;
} else
{
return false;
}
}

// 开户
void openAccount()
{
struct cardInfo card; // 声明结构体变量
int result;
FILE *fp; // 声明一个文件指针,用来指向打开的这个文件

system("cls");

printf("\n\t**********************湖南工学院IC卡管理系统**********************");
printf("\n\t************************** IC卡开户 **************************");
printf("\n\t*********************** 请输入以下信息 ************************");
printf("\n\n\t请输入学号:");
scanf("%s", card.sno);

printf("\n\t请输入卡号:");
scanf("%s", card.cardID);

printf("\n\t请输入姓名:");
scanf("%s", card.name);

printf("\n\t请输入充值金额:");
scanf("%f", &card.balance);

printf("\n\n\t您输入的信息为:");
showCardInfo(card);

result = MessageBox(NULL, "您确定要添加此账号信息吗?", "确认提示", MB_YESNO|MB_ICONINFORMATION);
if (result == 6) // 说明确定添加
{
strcpy(cards[TOTALCOUNT-1].sno, card.sno);
strcpy(cards[TOTALCOUNT-1].cardID, card.cardID);
strcpy(cards[TOTALCOUNT-1].name, card.name);
cards[TOTALCOUNT-1].balance = card.balance;
TOTALCOUNT++;

// 将这个数据写入到数据文件
/*
打开一个数据文件
fopen(要打开的数据文件路径, 打开的方式);
*/
fp = fopen("cards.txt","a"); // 以追加的方式打开文件
/*
将要保存的数据写入到这个打开的文件中
fwrite() 写入数据到指定文件中,它里面包含四个参数
第一个参数:要写入数据文件的数据的地址 -> 要将用户输入的这个IC卡账号信息写入到数据文件 -> 即这个账号结构体的地址
第二个参数:要写入数据文件的数据的大小 -> 要将这个结构体数据写入到数据文件,所以我要写入的数据文件大小应该就是这个结构体大小
第三个参数:要写入几个这个的大小 -> 这里我们只需要保存一个IC卡账户信息
第四个参数:写入到那个数据文件 -> 这里是写入到我们打开的这个数据文件fp
*/
fwrite(&card, sizeof(struct cardInfo), 1, fp);

// 关闭文件
fclose(fp);

printf("\n\n\t卡户成功<请按回车键返回>\n\n\t");
}
else
{
printf("\n\n\t不添加\n\n\t");
}
}

// 用来显示指定的账户信息
void showCardInfo(struct cardInfo card)
{
printf("\n\n\t 卡号 \t\t 学号 \t\t学生姓名 \t\t 余额 ");
printf("\n\t%-15s\t%-12s\t%-20s\t%-6.2f\t",card.cardID,card.sno,card.name,card.balance);
printf("\n\n\t");
}

// 浏览账户信息
void view()
{
system("cls");
printf("\n\t**********************湖南工学院IC卡管理系统**********************");
printf("\n\t************************ 浏览账户信息 ************************");

if (TOTALCOUNT>0)
{
// 显示数据
showCardInfos(cards, TOTALCOUNT);
printf("\n\n\t<请按回车返回>");
}
else
{
printf("\n\n\t暂无账号信息<请按回车返回>");
}
getch();

}

// 显示单个账户信息
void showCardInfos(struct cardInfo cards[], int count)
{
int i = 0;

printf("\n\n\t 卡号 \t\t 学号 \t\t学生姓名 \t\t 余额 ");
for(i; i<count-1; i++)
{
printf("\n\t%-15s\t%-12s\t%-20s\t%-6.2f\t", cards[i].cardID, cards[i].sno, cards[i].name, cards[i].balance);
}
printf("\n\n\n\t************************ 共 %d 条数据 ************************", count-1);
printf("\n\n\t");
}


// 初始化系统,用来读取本系统中的数据所有数据
void init()
{
FILE *fp;
if ( (fp = fopen("cards.txt", "r") ) != NULL)
{
// 循环读取数据到结构体数组中
while( !feof(fp) ) // feof file end of: 到文件最后了吗
{
/*
fread() 用来从指定的数据文件读取数据
第一个参数:将数据读到哪里 -> 将数据从数据文件读到结构体数据中
第二个参数:每个读多大 -> 每次读取一个结构体那么大
第三个参数:每次读几个这样的大小
第四个参数:从哪里读 -> 从打开的数据文件中读
*/
fread(&cards[TOTALCOUNT], sizeof(struct cardInfo), 1, fp);
TOTALCOUNT++;
}
fclose(fp);
}
}

// 充值
void income()
{
char cardID[12]; // 用来存放用户输入的充值卡卡号
int i = 0;
float money;

system("cls");

printf("\n\t**********************湖南工学院IC卡管理系统**********************");
printf("\n\t************************ 账户充值中心 ************************");

// 先判断系统中有没有用户信息
if (TOTALCOUNT > 0) {
printf("\n\n\t请输入要充值的卡号:");
scanf("%s", cardID);

// 从系统中查找有没有这个卡号
for (i=0; i<TOTALCOUNT-1; i++)
{
if (strcmp(cardID, cards[i].cardID) == 0)
{ // 如果是相等的,则说明这个用户找到了
// 显示这个账号,然后提醒输入输入充值的金额
printf("\n\n\t您要充值的账户信息如下:");
showCardInfo(cards[i]);

printf("\n\n\t请输入充值金额:");
scanf("%f", &money);

// 修改此账户的余额
cards[i].balance += money;

// 将数据写入到数据文件
printf("\n\n\t充值成功<请按回车键返回>");
break;
}
}

// 第一种是找到了退出循环,第二种是没找到退出循环
if ( i >= TOTALCOUNT-1 )
{
printf("\n\n\t暂无该账号信息<请按回车返回>");
}
}
else
{
printf("\n\n\t暂无账号信息<请按回车返回>");
}
getch();
}

// 保存数据
void saveData()
{
FILE *fp;
int i = 0;

if (TOTALCOUNT > 0) { // 说明有数据要保存
fp = fopen("cards.txt","w"); // 以追加的方式打开文件

/*
将要保存的数据写入到这个打开的文件中
fwrite() 写入数据到指定文件中,它里面包含四个参数
第一个参数:要写入数据文件的数据的地址 -> 要将用户输入的这个IC卡账号信息写入到数据文件 -> 即这个账号结构体的地址
第二个参数:要写入数据文件的数据的大小 -> 要将这个结构体数据写入到数据文件,所以我要写入的数据文件大小应该就是这个结构体大小
第三个参数:要写入几个这个的大小 -> 这里我们只需要保存一个IC卡账户信息
第四个参数:写入到那个数据文件 -> 这里是写入到我们打开的这个数据文件fp
*/
for(i=0; i<TOTALCOUNT-1; i++)
{
fwrite(&cards[i], sizeof(struct cardInfo), 1, fp);
}
// 关闭文件
fclose(fp);
}
else
{
remove("cards.txt");
}
}

// 查找
void search()
{
char sno[20]; // 用来存放用户输入的充值卡卡号
int i=0, index = 0, len = 0, count = 0;
bool isFind = false; // 是否找到
struct cardInfo cd[NUM]; // 满足条件的账户信息

system("cls");

printf("\n\t**********************湖南工学院IC卡管理系统**********************");
printf("\n\t************************ 账户查询中心 ************************");

// 先判断系统中有没有用户信息
if (TOTALCOUNT > 0) {
printf("\n\n\t请输入要查询的学生学号:");
scanf("%s", sno);

// 从系统中查找有没有这个卡号
for (i=0; i<TOTALCOUNT-1; i++) // 模糊查找
{
isFind = true;
for(index=0,len=(int)strlen(sno); index<len; index++)
{
if(cards[i].sno[index] != sno[index] ) // 说明不匹配
{ isFind = false;
break;} }
// 如果所有的字符都能匹配则满足条件
if (isFind)
{ cd[count] = cards[i];
count++;} }
// 第一种是找到了退出循环,第二种是没找到退出循环
if ( count > 0)
{printf("\n\n\t满足条件的信息如下:");
showCardInfos(cd, count+1); }
else
{printf("\n\n\t暂无该账号信息<请按回车返回>");}}
else
{printf("\n\n\t暂无账号信息<请按回车返回>"); }
getch(); }
penghuahuijuan 2015-06-09
  • 打赏
  • 举报
回复
cout<<"请输入矩阵的行数和列数:"<<endl; endl就是表示回车:\n // scanf("%d",&m->rows); cin>>m->rows;
苏叔叔 2015-06-09
  • 打赏
  • 举报
回复
你是要这种效果:

#include <iostream>
#include <iomanip>
#include <memory>
#include <cstring>
#define MAX_ROW 50
#define MAX_COLUMN 50
using namespace std;
typedef struct
{
	float data[MAX_ROW][MAX_COLUMN];
	int rows, columns;
} M, *pM;

void inputMatrix(M *m)
{
	int i, j;
	//printf("请输入矩阵的行数和列数:\n");
	cout << "请输入矩阵的行数和列数:\n";
	//scanf("%d", &m->rows);
	cin >> m->rows;
	//scanf("%d", &m->columns);
	cin >> m->columns;
	//printf("请按行输入矩阵的数据:\n");
	cout << "请按行输入矩阵的数据:\n";
	for (i = 0; i < m->rows; i++) {
		for (j = 0; j < m->columns; j++) {
			//scanf("%f", &m->data[i][j]);
			cin >> m->data[i][j];
		}
	}
}
void displayMatrix(M *m)
{
	int i, j;
	for (i = 0; i < m->rows; i++) {
		for (j = 0; j < m->columns; j++) {
			//printf("%10.3f ", m->data[i][j]);
			cout.setf(ios::fixed);
			cout.precision(3);
			cout << setw(10) << m->data[i][j];
		}
		//printf("\n");
		cout << endl;
	}
	//printf("\n");
	cout << endl;
}
void transposeMatrix(M *m, M *res)
{
	int i, j;
	for (i = 0; i < m->rows; i++) {
		for (j = 0; j < m->columns; j++) {
			res->data[j][i] = m->data[i][j];
		}
	}
}
bool addMatrix(M *a, M *b, M *res)
{
	int i, j;
	if (a->rows == b->rows && a->columns == b->columns) {
		for (i = 0; i < a->rows; i++) {
			for (j = 0; j < a->columns; j++) {
				res->data[i][j] = a->data[i][j] + b->data[i][j];
			}
		}
	}
	else {
		//printf("矩阵不能相加\n");
		cout << "矩阵不能相加\n";
		return false;
	}
	res->rows = a->rows;
	res->columns = a->columns;
	return true;
}
bool multiplyMatrix(M *a, M *b, M *res)
{
	int i, j, k;
	if (a->columns == b->rows) {
		for (i = 0; i < a->rows; i++) {
			for (j = 0; j < b->columns; j++) {
				for (k = 0; k < a->columns; k++) {
					res->data[i][j] += a->data[i][k] * b->data[k][j];
				}
			}
		}
	}
	else {
		//printf("矩阵不能相乘\n");
		cout << "矩阵不能相乘\n";
		return false;
	}
	res->rows = a->rows;
	res->columns = b->columns;
	return true;
}
bool scalarMultiplyMatrix(M *m, float n, M *res)
{
	int i, j;
	for (i = 0; i < m->rows; i++) {
		for (j = 0; j < m->columns; j++) {
			res->data[i][j] = m->data[i][j] * n;
		}
	}
	res->rows = m->rows;
	res->columns = m->columns;
	return true;
}
bool subtractMatrix(M *a, M *b, M *res)
{
	int i, j;
	if (a->rows == b->rows && a->columns == b->columns) {
		for (i = 0; i < a->rows; i++) {
			for (j = 0; j < a->columns; j++) {
				res->data[i][j] = a->data[i][j] - b->data[i][j];
			}
		}
	}
	else {
		//printf("矩阵不能相减\n");
		cout << "矩阵不能相减\n";
		return false;
	}
	res->rows = a->rows;
	res->columns = a->columns;
	return true;
}
int main()
{
	M A, B, res, finalRes, *tmpArg1, *tmpArg2;
	bool bErr;
	int sel;
	char op[32], arg1[32], arg2[32];
	//初始化
LABEL:
	memset(&A, 0, sizeof(M));
	memset(&B, 0, sizeof(M));
	memset(&res, 0, sizeof(M));
	memset(&finalRes, 0, sizeof(M));
	//printf("按提示输入矩阵A:\n");
	cout << "按提示输入矩阵A:\n";
	inputMatrix(&A);
	//printf("按提示输入矩阵B:\n");
	cout << "按提示输入矩阵A:\n";
	inputMatrix(&B);
LABEL1:
	//printf("选择要进行的操作:\n");
	cout << "选择要进行的操作:\n";
	//printf("1.输入算式\n");
	cout << "1.输入算式\n";
	//printf("2.矩阵转置\n");
	cout << "2.矩阵转置\n";
	//printf("3.打印矩阵\n");
	cout << "3.打印矩阵\n";
	//printf("4.重新输入\n");
	cout << "4.重新输入\n";
	//printf("0.退出\n");
	cout << "0.退出\n";
	//scanf("%d", &sel);
	cin >> sel;
	memset(op, 0, 32);
	memset(arg1, 0, 32);
	memset(arg2, 0, 32);
	switch (sel) {
	case 1:
		memset(&finalRes, 0, sizeof(M));
		//scanf("%s", op);
		cin >> op;
		//scanf("%s", arg1);
		cin >> arg1;
		//scanf("%s", arg2);
		cin >> arg2;
		if (!strcmp(arg1, "A")) {
			tmpArg1 = &A;
		}
		else if (!strcmp(arg1, "B")) {
			tmpArg1 = &B;
		}
		else if (!strcmp(arg1, "res")) {
			tmpArg1 = &res;
		}
		if (!strcmp(arg2, "B")) {
			tmpArg2 = &B;
		}
		else if (!strcmp(arg2, "A")) {
			tmpArg2 = &A;
		}
		else {
			tmpArg2 = &res;
		}
		if (!strcmp(op, "add")) {
			bErr = addMatrix(tmpArg1, tmpArg2, &finalRes);
		}
		else if (!strcmp(op, "sub")) {
			bErr = subtractMatrix(tmpArg1, tmpArg2, &finalRes);
		}
		else if (!strcmp(op, "mul")) {
			bErr = multiplyMatrix(tmpArg1, tmpArg2, &finalRes);
		}
		else if (!strcmp(op, "smul")) {
			bErr = scalarMultiplyMatrix(tmpArg2, atof(arg1), &finalRes);
		}
		res = finalRes;
		if (bErr)displayMatrix(&finalRes);
		goto LABEL1;
	case 2:
		//scanf("%s", arg1);
		cin >> arg1;
		if (!strcmp(arg1, "A")) {
			transposeMatrix(&A, &finalRes);
		}
		else if (!strcmp(arg1, "B")) {
			transposeMatrix(&B, &res);
		}
		else if (!strcmp(arg1, "res")) {
			transposeMatrix(&res, &finalRes);
		}
		res = finalRes;
		displayMatrix(&finalRes);
		goto LABEL1;
	case 3:
		//scanf("%s", arg1);
		cin >> arg1;
		if (!strcmp(arg1, "A")) {
			displayMatrix(&A);
		}
		else if (!strcmp(arg1, "B")) {
			displayMatrix(&B);
		}
		else if (!strcmp(arg1, "res")) {
			displayMatrix(&res);
		}
		goto LABEL1;
	case 4:
		goto LABEL;
	case 0:
		return 0;
	}
	return 0;
}
赵4老师 2015-06-09
  • 打赏
  • 举报
回复
面向对象只是一种编程思想。 再抽象的编程语言,最后不都变成汇编代码了吗?我们完全可以说汇编语言是面向对象、脚本化、动态化、泛函化、并行化、分布化的语言。 请牢记:源代码本身的书写是否结构化或面向对象或符合设计模式或敏捷…并不重要,重要的是你是否使用结构化或面向对象或符合设计模式或敏捷…的方法命名标识符、阅读、修改、检查、测试源代码。 意思是你程序结构看上去再合理,再简洁,也不一定比看上去一团乱麻的程序结构在运行或修改时更不易出错,更方便修改,出错了更容易找到哪里出错和具体出错的原因,更容易改正错误。 试对比 图书馆(对图书的分类够结构化了吧) 和 搜索引擎(可看作是扁平化任何结构数据,仅支持全文检索) 哪个处理信息更方便、更高效。 所以 与其费劲去重构代码让其看上去更简洁、更合理 不如费劲学习grep、sed、awk、……这类全文搜索和批处理编辑的工具。 结构越复杂,越难修改,越难除错。 有时(甚至大多数时候),看上去越合理、越简洁的代码,运行起来性能越差,出错时查找原因越难,找到出错原因后改正越费劲。 程序员要做的不是尽力避免错误,而是聚焦在快速发现并改正错误。真正以快速方式轻易解决错误,“快速的失败”远胜过“预防错误”。Fred George
  • 打赏
  • 举报
回复
感觉可以直接移植啊
lizhi5518 2015-06-09
  • 打赏
  • 举报
回复
...想变成C++代码``首先你得有个类`` 把你写的函数全部封装成类成员函数就行了 = =
幻夢之葉 2015-06-09
  • 打赏
  • 举报
回复
C++本来就支持C语法(几乎)
小白求指教 2015-06-08
  • 打赏
  • 举报
回复
这样做有意义吗?用C完成就完成了,何必要用C++
  • 打赏
  • 举报
回复
printf("请输入矩阵的行数和列数:\n"); cout<<"请输入矩阵的行数和列数:"<<endl; endl就是表示回车:\n // scanf("%d",&m->rows); cin>>m->rows;
  • 打赏
  • 举报
回复
引用 4 楼 wyfcogue 的回复:
scanf和printf是C语言的吧,得改成cout,cin,这个要怎么改
#include<iostream.h> cout<<变量; cin>>变量; 就行了
cutmelon 2015-06-08
  • 打赏
  • 举报
回复
我觉得楼主的意思不是改代码吧,应该是把原来的结构化编码改成oo编码,输入输出之类都是细枝末节了
赵4老师 2015-06-08
  • 打赏
  • 举报
回复
记不得哪位C++大牛在哪本学习C++的书的前言里面说过 “用C语言1000行源码能完成的工作千万不要用C++重写!”
xingyanxiao 2015-06-05
  • 打赏
  • 举报
回复
引用 4 楼 wyfcogue的回复:
scanf和printf是C语言的吧,得改成cout,cin,这个要怎么改
不会很难啊……这个里面主要是输入输出 字符串操作 bool这些
jiqiang01234 2015-06-05
  • 打赏
  • 举报
回复
改为c++的目的何在?只是为了熟悉c++的语法?
白螝 2015-06-05
  • 打赏
  • 举报
回复
引用 5 楼 xingyanxiao 的回复:
[quote=引用 4 楼 wyfcogue的回复:]scanf和printf是C语言的吧,得改成cout,cin,这个要怎么改
不会很难啊……这个里面主要是输入输出 字符串操作 bool这些[/quote]头文件那怎么改,bool要删掉吗
白螝 2015-06-05
  • 打赏
  • 举报
回复
头文件那C++的怎么改
白螝 2015-06-04
  • 打赏
  • 举报
回复
scanf和printf是C语言的吧,得改成cout,cin,这个要怎么改
ggsjj 2015-06-04
  • 打赏
  • 举报
回复
C++中bool应该算关键字,感觉typedef int bool应该算非法
白螝 2015-06-04
  • 打赏
  • 举报
回复
ForestDB 2015-06-04
  • 打赏
  • 举报
回复
这就是C++程序。

64,281

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧