修改前
#include<iostream>
#include<cstring>
#include <iomanip>
using namespace std;
class Table
{
public:
Table(int p)
{
i=p;
}
void ascii( );
protected :
int i;
};
void Table::ascii( )
{
int k=1;
for (; i<127; i++)
{
cout<<setw(4)<<i<<" "<<(char)i;
if ((k)%12==0)
cout<<"\n";
k++;
}
cout<<"\n";
}
class Der_table:public Table
{
public:
Der_table(int p,char *m):Table(p)
{
c = new char[strlen(m) + 1];
strcpy(c, m);
}
void print( );
protected:
char *c;
};
void Der_table::print( )
{
cout<<c<<"\n";
Table::ascii();
}
int main()
{
Der_table ob1(32,"ASCII value---char");
ob1.print();
return 0;
}
提示:修改后的main测试函数为:
int main()
{ Der_table ob('a','z',"ASCII value---char");
ob.print();
return 0;
}
修改后
#include<iostream>
#include<cmath>
#define _CRT_SECURE_NO_WARNINGS //这个宏定义最好要放到.c文件的第一行
#pragma warning(disable:4996)
#include<cstring>
#include<string.h>
#include <iomanip>
using namespace std;
class Table
{
public:
Table(char p, char q)
{
i = (int)p;
j = (int)q;
}
void ascii();
protected:
int i;
int j;
};
void Table::ascii()
{
int k = 1;
for (; i <= j; i++)
{
cout << setw(4) << i << " " << (char)i;
if ((k) % 12 == 0)
cout << "\n";
k++;
}
cout << "\n";
}
class Der_table :public Table
{
public:
Der_table(char p, char q, const char* m) :Table(p, q)
{
c = new char[strlen(m) + 1];
strcpy(c, m);
}
void print();
protected:
char* c;
};
void Der_table::print()
{
cout << c << "\n";
Table::ascii();
}
//int main()
//{
// Der_table ob1(32, "ASCII value---char");
// ob1.print();
// return 0;
//}
//提示:修改后的main测试函数为:
int main()
{
Der_table ob('a', 'z', "ASCII value---char");
ob.print();
return 0;
}