資源簡介
1、輸入如下正確的常量說明串:
const count=10,sum=81.5,char1=‘f’,max=169,str1=“h*54 2..4S!AAsj”, char2=‘@’,str2=“aa!+h”;
輸出:
count(integer,10)
sum(float,81.5)
char1(char, ‘f’)
max(integer,169)
str1(string,“h*54 2..4S!AAsj”)
char2(char, ‘@’)
str2(string,“aa!+h”)
int_num=2; char_num=2; string_num=2; float_num=1.
2、輸入類似如下的保留字const錯誤的常量說明串:
Aconstt count=10,sum=81.5,char1=‘f’;
輸出類似下面的錯誤提示信息:
It is not a constant declaration statement!
Please input a string again!
3、輸入類似如下含常量名或常量值錯誤的常量說明串:
const count=10,12sum=81.5,char1=‘ff’,max=0016;
輸出類似下面的錯誤提示信息:
count(integer,10)
12sum(Wrong! It is not a identifier!)
char1(Wrong! There are more than one char in ‘’.)
max(Wrong! The integer can’t be started with ‘0’.)
int_num=1; char_num=0; string_num=0; float_num=0.
代碼片段和文件信息
#include
using?namespace?std;
int?char_num=0string_num=0int_num=0float_num=0; //?字符值類型,0=字符,1=字符串,2=整數,3=浮點數
class?zifu //建立字符類,存儲一個字符串的信息
{
public:
int?i;
char?name[20];
char?data[20];
int?dataname;
void?display()
{
i=0;
while(name[i]!=‘\0‘)
{
cout< i++;
}
cout<<“=“;
i=0;
while(data[i]!=‘\0‘)
{
cout< }
cout< cout< }??
};
void?input(char?a[]) //輸入函數
{
char??stand[6]=“const“;
int?i=0judge=0;
gets(a);
for(i=0;i<5;i++)
{
if(a[i]==stand[i])
judge++;
}
if(judge!=5?||?a[5]!=‘?‘)
{
cout<<“It?is?not?a?constant?declaration?statement!?“;?
cout<<“Please?input?a?string?again!“< input(a);
}
}
void?sort(zifu?aclass[]char?b[]int?&?integerint?&?tag)?//識別函數tag?類標記?integer?當前查找的位置(從第七個開始)
{
int?i=0;
while(b[++integer]!=‘=‘)
{
if(b[integer]!=‘?‘)
aclass[tag].name[i]=b[integer];
i++; //獲取字符串名
}
aclass[tag].name[i]=‘\0‘;
i=0;?
++integer;
while(b[integer]!=‘‘?&&?b[integer]!=‘;‘)???//獲取字符串值、值類型
{
if(b[integer]>=‘0‘?&&?b[integer]<=‘9‘)//?字符值類型,0=字符,1=字符串,2=整數,3=浮點數
aclass[tag].dataname=2;
else?if(b[integer]==‘.‘) //浮點數判斷。。。真麻煩
{?
aclass[tag].dataname=3;
while(b[integer]!=‘‘?&&?b[integer]!=‘;‘)
{
aclass[tag].data[i]=b[integer];
integer++;i++;
}
}
else?if(b[integer]>=‘a‘?&&?b[integer]<=‘z‘)
ac
- 上一篇:控制臺俄羅斯方塊C++源碼
- 下一篇:C++實現簡單編譯器
評論
共有 條評論