当前位置:编程学习 > C/C++ >>

以下C++程序错在哪里,为什么始终编译不通过?

/*表示一个人的姓名、性别、身份证号、及出生年月*/ #include<iostream.h> #include<string.h> #include<time.h> class Date{ int year,month,day; public: void setDate(int y,int m,int d){ year=y; month=m; day=d;} int getYear(){return year;} int getMonth(){return month;} int getDay(){return day;} bool isLeapYear(){ return year%400==0||year%4==0&&year%100!=0; } void print(){ cout<<year<<"."<<month<<"."<<day; } }; class Person{ char name[20]; char sex; char idno[20]; Date birthdate; pudlic: void setName(char * p){ if(strlen(p)<=19) strcpy(name,p); else strcpy(name,"unknown"); } char * getName(){return name;} void setSex(char s){ if(s=='m'||s=='f') sex=s; else sex='u'; } char getSex(){return sex;} void setIdno(char * id){ if(strlen(id)==15||strlen(id)==18||strlen(id)==19) strcpy(idno,id); else strcpy(idno,"unknown"); } char * getIdno(){return idno;} void setBirthdate(int year,int month,int day){ birthdate.setDate(year,month,day); } int getAge(){ time_t ltime; //说明time_t结构变量ltime time(& ltime); //取得当地时间 tm * today=localtime(& ltime); //转换为本地时间 int ctyear=today->tm_year+1900; //取得当年年份 return ctyear-birthdate.getYear();//返回当前年龄 } void show(){ cout<<(sex=='f'?"她是":"他是")<<getName()<<",身份证号为"<<getIdno()<<";"; cout<<"出生日期为"; birthdate.print(); cout<<";年龄为"<<getAge()<<endl; } }; void main(){ Person a,b; a.setIdno("320113199004094814"); a.setName("王翰"); a.setSex('m'); a.setBirthdate(1990,4,9); a.show(); b=a; b.show(); b.setIdno("320113198909024815"); b.setName("李丽"); b.setSex('f'); b.setBirthdate(1989,9,2); b.show; }
追问:过去的可以用
#include<iostream.h>
#include<string.h>
#include<time.h>

我们学的内容比较老,一直用的是iostream.h
还是谢谢你啦
答案:1. 
#include <iostream>
#include <string>
#include <time.h>
2.
include下面添加:
using namespace std;
3.
"public" 打错了
4.
最后一行show函数少了括号
其他:最烦这种贴代码不贴错误的了 输入错误而已
class Person{
 char name[20];
 char sex;
 char idno[20];
 Date birthdate;
pudlic:        //嘿嘿,这里打错字了,是public,不是pudlic
 void setName(char * p){
  if(strlen(p)<=19)
   strcpy(name,p);
  else
   strcpy(name,"unknown");
 } class Person类中的public写错了!!!你写成pudlic:!!!写代码要认真!!! 

上一个:关于c语言指针的问题
下一个:VB语言程序设计一道编程题。。。求解

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,