佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

搜索
查看: 768|回复: 0

请教C++高手。。。

[复制链接]
Lightning 该用户已被删除
发表于 1-10-2007 12:54 AM | 显示全部楼层 |阅读模式
题目是:
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.......

再次感谢大家的帮忙。。。。
小弟在此致于万二分的谢意。。。。
谢谢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT


本周最热论坛帖子本周最热论坛帖子

ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2026 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 25-3-2026 09:10 AM , Processed in 0.098535 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表