帮忙看看程序!!!等待诸位指点啊~~~~~~~~~~~~~~~~~~
程序一:
#include<iostream.h>
#include<stdio.h>
class Table
{
//**1**
int x;
int y;
int z;
public:
void print(int x,int y,int z);
};
void Table::print (int x,int y,int z)
{
//**2**
printf("%d*%d=%d",x,y,z);
if(z<10) printf(" "); ////////////A
}
class Table9:public Table
{
public:
void print();
};
void Table9::print()
{
//**3**
int i,j;
int x,y,z;
for (i=1;i<10;i++)
{
for(j=1;j<i+1;j++)
{
x=i;
y=j;
z=i*j;
Table::print(y,x,z);
}
printf("\n");
}
}
main()
{
//**4**
Table9 temp;
temp.print();
return 0;
问题是在将标为A的地方改为cout<<" ";为什么就起不到控制格式的效果了呢?
程序2:
#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<fstream.h>
#define N 10
typedef struct ss
{char num[10];
int s;
} STU;
void fun(STU a[],STU *s)
{
static ss temp=a[0];
for(int i=1;i<N;i++)
if(temp.s>a[i].s)
temp=a[i];
*s=temp; /////////B
}
void main( )
{
STU a[N]={{"A01",81},{"A02",89},{"A03",66},{"A04",87},{"A05",77},{"A06",90},{"A07",79},{"A08",61},{"A09",80},{"A10",71}},m;
fun(a,&m);
cout<<"***** The original date *****"<<endl;
cout<<"The lowest :"<<m.num<<m.s<<endl;
/**************************/
ofstream fin("out1.dat");
fun(a,&m);
fin<<m.num<<m.s<<endl;
fin.close();
/**************************/
}
问题是将标为B的地方改为s=&temp;就会出现乱码,这又是为什么呢?
希望诸位指点啊????