下面的程序可以输出ASCII字符与所对应的数字的对照表。修改下列程序,使其可以输出字母a 到z与所对应的数字的对照表。 #include<iostream> #include<cstring> #include <iomanip> using namespace std; class Table { public: Table(int p) { i=p; } void ascii( ); protected : int i; }; void Tab
时间: 2024-02-29 12:54:49 浏览: 27
le::ascii( ) { int j; for (j=0; j<=127;) { cout << setw(3) << j << " " << (char)j << " "; j++; if (j%8 == 0) cout << endl; } } int main( ) { Table t(0); t.ascii( ); return 0; }
修改后的程序如下:
```cpp
#include<iostream>
#include<cstring>
#include <iomanip>
using namespace std;
class Table {
public:
Table(int p)
{
i=p;
}
void alphabet( ); // 修改函数名称
protected :
int i;
};
void Table::alphabet( ) { // 修改函数名称
int j;
for (j=97; j<=122; j++) // 修改循环条件
{
cout << (char)j << " " << setw(3) << j << " "; // 修改输出格式
if ((j-96)%4 == 0) // 修改换行条件
cout << endl;
}
}
int main( ) {
Table t(0);
t.alphabet( ); // 调用修改后的函数
return 0;
}
```
输出结果如下:
```
a 97 b 98 c 99 d 100
e 101 f 102 g 103 h 104
i 105 j 106 k 107 l 108
m 109 n 110 o 111 p 112
q 113 r 114 s 115 t 116
u 117 v 118 w 119 x 120
y 121 z 122
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)