|
查看: 768|回复: 0
|
请教C++高手。。。
[复制链接]
|
|
|
题目是:
write a simple program that will print your registration slip.
Your registration slip should have your name, your home address, subjects in the
semester and the credit hours.
Your program should ask the information from you first and then, after you have entered
all the information, your program need to display them in a neat table.
You can either use the new C++ string class or the old class. (i.e. <string.h> or <string>
Use your pointer to point to the subjects's credit hours.
Please use member functions of the string class such as strcpy,
strlen, strcat or the member functions of the new string class such as string.assign,
stringreplace to manipulate the strings that make up the information.
以下是小弟本身说尝试写出的方程式,但它不能如我所愿的操作。。。请帮小弟更改一下或直接写一个新的方程式给我....
谢谢......
#include <iostream.h>
#include <string.h>
char sub[10];
char crd[10];
int main(){
char slip[1000];
char name[100];
char addr[300];
char sub[10][100];
char crd[10][100];
int n;
int i;
int s;
cout<<"\t\tWelcome to the registration process of USM."<<endl;
cout<<" lease be patient and following the following instructions."<<endl;
cout<<" lease enter your name in CAPITAL letter."<<endl;
cin.getline(name,99);
cout<<" lease enter your home address."<<endl;
cin.getline(addr,299);
cout<<" lease enter the numbers of subject taken."<<endl;
cin>>s;
n=s-1;
for(i=0;i<n;i++){ //problem is here
cout<<" lease enter the subject taken in this semester following"<<endl;
cout<<"by it's credit hours."<<endl;
cin.getline(sub,99);
cin.getline(crd,99);
}
strcpy(slip,"----------------------------------------------------\n" ;
strcat(slip,"| NAME: " ;
strcat(slip,name);
strcat(slip," |\n" ;
strcat(slip,"| HOME ADDRESS: " ;
strcat(slip,addr);
strcat(slip,"|" ;
for(i=0;i<n;i++){
strcat(slip,sub);
strcat(slip,crd);
}
cout<<slip;
return 0;
}
one more things is i don't know how to use pointer in this question...dunno where to put.......
再次感谢大家的帮忙。。。。
小弟在此致于万二分的谢意。。。。
谢谢
 |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|