day09_basicclass

1 String练习

ascii

在这里插入图片描述

	 *1: 写一个方法判断注册的账号和密码是否合法:账号:由数字 字母组成 不能以数字开头 长度>=6
	 *                                       密码:由数字 字母 _ $ 组成 长度>=8 必须包含数字  字母 和特殊字符(_或者$)
	 *2: 写一个方法对字符串进行敏感词过滤:   我叫特朗普 我要进行暴力色情恐怖活动:::特朗普 暴力 色情 恐怖 为敏感词 被*替换
	 *3: 写一个方法对参数字符串反转
	 *4:写一个方法获取参数字符串中所有但不重复的字符:123abc123abcd---123abcd 
	 *5: 写一个方法打印参数字符串中每个字符出现的次数
	 *6: 写一个方法获取参数字符串中所有数字字符对应的最大整数:abc109yh7---9710
	 *7: 写一个方法 去除叠词 :aaabccccb11122276---abcb1276  
	 *8: 写一个方法 对字符串进行转换:我...我....叫....叫....叫....张....张....张....张....张....张....三....三....三....丰---->我叫张三丰
package day09_basic_class;

public class ZuoYe03 {


//	 *1: 写一个方法判断注册的账号和密码是否合法:账号:由数字 字母 组成 不能以数字开头 长度>=6 
//                                         密码:由数字 字母 _ $ 组成 长度>=8 必须包含数字  字母 和特殊字符(_或者$)
    //判断账号和密码 都有判断长度和组成的要求:
	private static boolean pdName(String name) {
		//判断长度
		 if(name.length()<6) {
			 return false;
		 }
		 //遍历字符串:charAt / toCharArray
		 for (int i = 0; i <name.length(); i++) {
			   char c=name.charAt(i);//获取当前字符
			   //首字母不能是数字
			   if(i==0) {
				   if(c>=0&&c<=9) {
					   return false;
				   }
			   }
			   //判断当前字符的类型
			   if(!(c>='0'&&c<='9')&&!(c>='A'&&c<='Z')&&!(c>='a'&&c<='z')) {
				   return false;
			   }
		}
		 return true;
	}
	private static boolean pdPwd(String pwd) {
		//判断长度
		 if(pwd.length()<8) {
			 return false;
		 }
		 //定义一个变量记录_和$是否出现过
		 boolean b_=false;
		//定义一个变量记录数字是否出现过
		 boolean ba=false;
		//定义一个变量记录字母是否出现过
		 boolean b1=false;
		 char[] arr=pwd.toCharArray();
		 for (int i = 0; i <arr.length; i++) {
			   
			   char c=arr[i];//获取当前字符
			   //判断 是否出现过_或者$
			   if(c=='_'||c=='$') {
				   b_=true;
			   }
			   //判断 是否出现数字
			   if(c>='0'&&c<='9') {
				   b1=true;
			   }
			   //判断 是否出现字母
			   if((c>='a'&&c<='z')||(c>='A'&&c<='Z')) {
				   ba=true;
			   }
			   //判断当前字符的类型
			   if(!(c>='0'&&c<='9')&&!(c>='A'&&c<='Z')&&!(c>='a'&&c<='z')&&c!='_'&&c!='$') {
				   return false;
			   }
		 }
		 return b1&&ba&&b_;
	}
	
	public static boolean regist(String name,String pwd) {
		return pdName(name)&&pdPwd(pwd);
	}
	
//	 *2: 写一个方法对字符串进行敏感词过滤:   我叫特朗普 我要进行暴力色情恐怖活动:::特朗普 暴力 色情 恐怖 为敏感词 被*替换
	public static String test02(String str) {
		String newStr=str;
		String[] arr= {"特朗普","暴力","恐怖","枪","色情"};
		for (int i = 0; i < arr.length; i++) {
			newStr=newStr.replace(arr[i],getXing(arr[i]));
		}
		System.out.println(str+"::::"+newStr);
		return newStr;
	}
	//根据字符串 获取等长度的星
	private static String getXing(String str) {
		String xing="";
		for (int i = 0; i < str.length(); i++) {
			xing+="*";
		}
		return xing;
	}
//	 *3: 写一个方法对参数字符串反转
	 public static String reverse(String str) {
		 String strNew="";
		 for (int i = 0; i < str.length(); i++) {
			 strNew=str.charAt(i)+strNew;
		}
		 System.out.println(str+"::::"+strNew);
		 return strNew;
	 }
//	 *4:写一个方法获取参数字符串中所有但不重复的字符:123abc123abcd---123abcd
	  public static String test04(String str) {//123abc123abcd
		  String newStr="";
		  //遍历字符串
		  for (int i = 0; i < str.length(); i++) {
			  char c=str.charAt(i);
			  //判断当前字符是否存在于newStr中
			  if(!newStr.contains(c+"")) {//newStr.indexOf(c)==-1
				   newStr+=c;
			  }
		  }
		  System.out.println(str+"::::"+newStr);
		  return newStr;
	  }
//	 *5: 写一个方法打印参数字符串中每个字符出现的次数
	  public static void test051(String str) {//123abc123abcd
		   //获取str中都有那些字符
		   String ss=test04(str);//123abcd
		   //判断ss中的字符在str中出现的次数
		   for (int i = 0; i < ss.length(); i++) {
			    //获取当前字符
			   char c=ss.charAt(i);
			   //获取当前字符在str中出现的次数
			    int ciShu=0;
			    for (int j = 0; j < str.length(); j++) {
					  char cc=str.charAt(j);
					  ciShu+=cc==c?1:0;
				}
			    System.out.println(str+"中字符 "+c+" 出现的次数是"+ciShu);
		   }
	  }
	  public static void test052(String str) {//123abc123abcd
		  //遍历当前字符串
		  for (int i = 0; i < str.length(); i++) {
			  //获取当前字符
			  char c=str.charAt(i);
			  //判断当前字符在前面是否出现过
			  boolean b=false;
			  for (int j = 0; j < i; j++) {
				  char cc=str.charAt(j);
				  if(cc==c) {
					  b=true;
					  break;
				  }
			  }
			  if(b) {//当前字符c在前面出现过 就不在统计当前字符的次数了
				 continue;
			  }
			  //统计当前字符出现的次数
			  int ciShu=1;
			  for (int j = i+1; j < str.length(); j++) {
				  char cc=str.charAt(j);
				  if(cc==c) {
					 ciShu++;
				  }
			  } 
			  System.out.println(str+"中字符:::: "+c+" 出现的次数是"+ciShu);
		 }
	  }
//	 *6: 写一个方法获取参数字符串中所有数字字符对应的最大整数:abc109yh7---9710
	  public static int test06(String str) {
		  //获取所有的数字字符
		  String ss="";
		  for (int i = 0; i < str.length(); i++) {
			   char c=str.charAt(i);
			   if(c>='0'&&c<='9') {
				   ss+=c;
			   }
		  }
		  //把字符串转化为字符数组
		  char[] arr=ss.toCharArray();
		  //对数组进行排序
		  for (int i = 0; i < arr.length-1; i++) {
			   for (int j = i+1; j < arr.length; j++) {
				   if(arr[i]<arr[j]) {
					   char k=arr[i];arr[i]=arr[j];arr[j]=k;
				   }
			   }
		   }
		  //根据数组获取一个int
		  int n=0;
		  // 8 6 4 3 1---->86431
		  for (int i = arr.length-1,k=1; i >=0; i--,k*=10) {
			   n+=(arr[i]-'0')*k;
	      }
		  System.out.println(str+"::::"+ss+"::::"+n);
		  return n;
	  }
//	 *7: 写一个方法 去除叠词 :aaabccccb11122276---abcb1276 
	  //  "abcb"
	  public static String test07(String str) {
		  String ss="";
		  for (int i = 0; i < str.length(); i++) {
			  char c=str.charAt(i);
			  //判断是是不是第一个字符
			  if(i==0) {
				  ss+=c;
			  }else {
				  //获取当前字符前面的字符
				  char cc=str.charAt(i-1);
				  //判断当前字符是不是和前面的字符一致
				  if(cc!=c) {
					  ss+=c;
				  }
			  }
		  }
		  System.out.println(str+"::::"+ss);
		  return ss;
	  }
//	 *8: 写一个方法 对字符串进行转换:我...我....叫....叫....叫....张....张....张....张....张....张....三....三....三....丰---->我叫张三丰
	  public static String test08(String str) {
		  String ss="";
		  //替换所有的.
		  ss=str.replace(".", "");
		  System.out.println(str+"::::"+ss);
		  //去除叠词
		  ss=test07(ss);
		  System.out.println(str+"::::"+ss);
		  return ss;
	  }
		public static void main(String[] args) {
			// TODO Auto-generated method stub
			test02("我叫特朗普 我要进行暴力色情恐怖活动");
			reverse("abc12344");
			test04("123abc123kkk");
			test051("11133454566767sbsdbsdb");
			test052("11133454566767sbsdbsdb");
			test06("abc198aksj0861");
			test07("abaaabbb111shshshdddd");
			test08("我...我....叫....叫....叫....张....张....张....张....张....张....三....三....三....丰");
		}
		
		//对字符串进行压缩:字符是非数字的
		//aaabbbbcccdabiiiioooo--->a3b4c3dabi4o4
		//a3b4c3dabi4o4---->aaabbbbcccdabiiiioooo
		
		//写一个方法对字符串进行转换:大写转化为小写 小写转换为大写  删除数字
		
}

2 String的再次练习

public static void main(String[] args) {
    test01("aaabbbbcccdabiiiioooo");
    test02("a3b4c3dabi4o4");
    test03("a3b4c3dabi4o4YYYTWTWTW");
}   
//对字符串进行压缩:字符是非数字的
//aaabbbbcccdabiiiioooo--->a3b4c3dabi4o4
//aaabccccdddee   -------->a3b
//                  ciShu=3
public static String test01(String str) {
    String ss="";
    //添加第一个字符
    ss+=str.charAt(0);
    //定义一个记录当前字符出现的次数
    int ciShu=1;
    for (int i = 1; i < str.length(); i++) {
        //判断当前字符是不是等于前面的字符
        char c=str.charAt(i);
        char cc=str.charAt(i-1);
        if(c==cc) {
            ciShu++;
        }else {
            //判断次数是否等于1
            if(ciShu!=1) {
                ss+=ciShu;
            }
            ss+=c;
            //此时的次数 应该记录当前字符的出现的次数
            ciShu=1;
        }
    }
    ss+=ciShu>1?ciShu:"";//最后需要判断 最后一个字符的次数是否需要加进来
    System.out.println(str+":::"+ss);
    return ss;
}
//a3b4c3dabi4o4---->aaabbbbcccdabiiiioooo
public static String test02(String str) {
    String ss="";
    for (int i = 0; i < str.length(); i++) {
        //获取当前字符
        char c=str.charAt(i);
        //判断当前字符的类型
        if(c>'9'||c<'0') {
            ss+=c;
        }else {
            //前面字符在添加c-'0'-1次
            for (int j = 1; j <=c-'0'-1; j++) {
                ss+=str.charAt(i-1);
            }
        }
    }
    System.out.println(str+":::"+ss);
    return ss;
}

//写一个方法对字符串进行转换:大写转化为小写 小写转换为大写  删除数字
public static String test03(String str) {
    String ss="";
    for (int i = 0; i < str.length(); i++) {
        //获取当前字符
        char c=str.charAt(i);
        //判断当前字符的类型
        if(c>='a'&&c<='z'){
            //转化为大写
            //ss+=(c+"").toUpperCase();
            ss+=(char)(c-('a'-'A'));
        }else if(c>='A'&&c<='Z'){
            //转化为大写
            //ss+=(c+"").toLowerCase();
            ss+=(char)(c+('a'-'A'));
        }else if(c>'9'||c<'0') {
            ss+=c;
        }
    }
    System.out.println(str+":::"+ss);
    return ss;
}
package day09_basic_class;

public class LianXi02 {
	public static void main(String[] args) {
		for (int i = 0; i < 10; i++) {
			//System.out.println( Student02.suiJIName());
			System.out.println(new Student02());
		} 
	}
}
//创建一个类Student 属性 名字 性别 分数 年龄  
//所有属性私有化 重写tostring方法和equals方法 要求名字属性相同就返回true
//要求无参数的构造方法 返回一个四个属性都是随机的数据
class Student02{
	private String name;
	private int age;
	private char sex;
	private float score;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public char getSex() {
		return sex;
	}
	public void setSex(char sex) {
		this.sex = sex;
	}
	public float getScore() {
		return score;
	}
	public void setScore(float score) {
		this.score = score;
	}
	@Override
	public String toString() {
		return "Student02 [name=" + name + ", age=" + age + ", sex=" + sex + ", score=" + score + "]";
	}
	//常规协定,该协定声明相等对象必须具有相等的哈希码
	public int hashCode() {
	    return this.name.hashCode();
	}
	@Override
	public boolean equals(Object obj) {
		if(obj== null) {return false;}
		//判断类型
		if(!(obj instanceof Student02)) {return false;}
		//向下转型
		Student02 s=(Student02)obj;
		return s.name.equals(this.name)&&s.age==this.age&&s.sex==this.sex&&s.score==this.score;
	}
	public Student02(String name, int age, char sex, float score) {
		super();
		this.name = name;
		this.age = age;
		this.sex = sex;
		this.score = score;
	}
	public Student02() {
		this.name=suiJIName();
		this.sex=Math.random()>0.5?'男':'女';
		this.score=(int)(Math.random()*1001+0)/10.0f;   //0.0-100.0
		this.age=(int)(Math.random()*8+18);
	}
	public static String suiJIName() {
		//随机4个字符:数字 字母
		String name="";
		for (int i = 0; i < 4; i++) {
			 double n=Math.random();
			 char c;
			 if(n<10.0/62) {//随机数字
				 //随机字符:'0'-'9'
				 c=(char)(Math.random()*10+'0');
			 }else  if(n<36.0/62) {//随机大写字母
				 c=(char)(Math.random()*26+'A');
			 }else {
				 c=(char)(Math.random()*26+'a');
			 }
			 name+=c;
		}
		return name;
	}
	
	
}

3 Date

	 *Date:日期
	 *注意1: Date类中的大部分方法 都是过时的:::(有更前面更安全的替代者  但不影响当前类的使用) 
	 *       Date类是完全按美国人对日期的认知进行设计的  信息太少 转化为其他民族描述日期的算法 比较麻烦
	 *       不易于实现国际化
	 *    2: 注意导包:我们java开发使用的是java.util.Date
	 *    3: 日期也可以用毫秒值来记录:毫秒值是相当于历元(1970-1-1 0:0:0)
	 *构造方法:
	 *    1:无参数
	 *       Date() :获取的是当前时间
	 *    2:参数是毫秒值
	 *       Date(long date) :获取的是毫秒值对应的时间
	 *    3:参数是年月日 时分秒	
	 *        年-1900 月-1
	 *        Date(int year, int month, int date, int hrs, int min, int sec) 
	 *        Date(int year, int month, int date) 
	 *普通方法:
	 *    1 比较
	 *      boolean after(Date when)  
	 *      boolean before(Date when)   
	 *    2 设置和获取时间参数
	 *      int getXxx()
	 *      void setXxx(int xxx)  
	 *    3 Date与毫秒值之间的转换
	 *      long getTime();获取当前时间对象对应的毫秒值  
	 *      void setTime(long time); 设置当前时间对象表示的时间为参数毫秒值对应的时间 
	 *    4 String toLocaleString():获取当前操作系统的日期表示格式
package day09_basic_class;

import java.util.Date;

public class Demo06Date {
	public static void main(String[] args) {
		Date d1=new Date();
		System.out.println(d1);//Thu Sep 08 11:40:17 CST 2022
		d1=new Date(1);//距离历元1毫秒的时间:::
		System.out.println(d1);//Thu Jan 01 08:00:00 CST 1970
		
		d1=new Date(2022-1900, 9-1, 8, 11, 49, 0);
		System.out.println(d1);//Sun Oct 08 11:49:00 CST 3922
		
		Date d2=new Date(0);
		System.out.println(d2);
		System.out.println(d1.after(d2));
		
		//设置时间参数
		d2.setYear(2022-1900);
		d2.setMonth(9-1);
		d2.setDate(8);
		System.out.println(d2);
		
		//获取时间参数
		System.out.println(date2Str(new Date()));
		d2=new Date(2000-1900,1-1,1);
		System.out.println(date2Str(d2));
		System.out.println(d2.getTime()/1000/3600/24/365);
		d2.setTime(0);
		System.out.println(date2Str(d2));
		
		System.out.println(d2.toLocaleString());//1970-1-1 8:00:00
		
	}
	//写一个方法获取参数date的字符串表示形式:xxxx年xx月xx日 星期x xx:xx:xx
	public static String date2Str(Date d) {
		String weeks="日一二三四五六";//(0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday)
		int year=d.getYear()+1900;
		int month=d.getMonth()+1;
		int date=d.getDate();
		int hour=d.getHours();
		int minute=d.getMinutes();
		int second=d.getSeconds();
		int week=d.getDay();//(0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday
		return year+"年"+month+"月"+date+"日 星期"+weeks.charAt(week)+" "+hour+":"+minute+":"+second;
	}

}

4 Date练习

package day09_basic_class;

import java.util.Date;

public class LianXi03 {
	public static void main(String[] args) {
		System.out.println(changeStr2Int("12345"));
		get2("2000-1-1");
	}
//	 *1  获取参数字符串表示的时间距离当前时间的天数::参数字符串格式:xxxx-xx-xx
//	 *   publc static int get1(String str);   
	public static int get1(String str) {
		 //获取年月日
		 String yearStr=str.substring(0, str.indexOf("-"));
		 String monthStr=str.substring(str.indexOf("-")+1, str.lastIndexOf('-'));
		 String dayStr=str.substring(str.lastIndexOf('-')+1);
		 //吧字符串转化为整数
		 int year=changeStr2Int(yearStr);
		 int month=changeStr2Int(monthStr);
		 int day=changeStr2Int(dayStr);
		 //创建一个date对象
		 Date date1=new Date(year-1900, month-1, day);
		 //获取当前时间
		 Date date2=new Date();
		 //获取差值
		 int days=(int)(Math.abs(date1.getTime()-date2.getTime())/1000/3600/24);
		 return days;
	}
	private static int changeStr2Int(String str) {//12345
		int n=0;
		for (int i = str.length()-1,k=1; i >=0; i--,k*=10) {
			//获取当前字符
			char c=str.charAt(i);
			 n+=(c-'0')*k;
		}
		return n;
	}
//	 *2 获取参数字符串表示的时间在100天后对应的date::参数字符串格式:xxxx-xx-xx
//	 *   publc static Date get2(String str); 
	public static Date get2(String str) {
		 //获取年月日
		 String yearStr=str.substring(0, str.indexOf("-"));
		 String monthStr=str.substring(str.indexOf("-")+1, str.lastIndexOf('-'));
		 String dayStr=str.substring(str.lastIndexOf('-')+1);
		 //吧字符串转化为整数
		 int year=changeStr2Int(yearStr);
		 int month=changeStr2Int(monthStr);
		 int day=changeStr2Int(dayStr);
		 //创建一个date对象
//		 Date date1=new Date(year-1900, month-1, day);
//		 date1.setDate(date1.getDate()+100);
		 
		 //date1.setTime(date1.getTime()+1000*3600*24*100);
		 
		 Date date1=new Date(year-1900, month-1, day+100);
		 System.out.println(date1.toLocaleString());
		 return date1;
	}
}

5 Calendar

    * Calendar:日历:
     * 注意事项1:Calendar类是抽象类:通过其静态方法static Calendar getInstance()  获取其子类对象
     *        2: Calendar中包含了所有和时间相关的参数 来实现国际化
     *       
     * 普通方法:
     *    1 比较
     *       boolean after(Object when)  
             boolean before(Object when)  
          2 设置和获取指定的时间参数
             int get(int field)  
             void set(int field, int value)  
          3 在指定参数字段 添加指定值
             void add(int field, int amount)  
          4 calendar与date之间的转换
             Date getTime() ;获取当前日历对象对应的相同时间的日期对象 
             void setTime(Date date);吧当前日历对象的时间设置为参数日期对象表示的时间
          5 calendar与毫秒值之间的转换
              long getTimeInMillis()  ;获取当前日历对象表示的时间对应的毫秒值
              void setTimeInMillis(long time) ;设置当前日历对象表示的时间为参数毫秒值对应的时间 
public static void main(String[] args) {
    Calendar c1=Calendar.getInstance();
    System.out.println(c1);
    //java.util.GregorianCalendar[time=1662624880991,areFieldsSet=true,areAllFieldsSet=true,
    //lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Shanghai",offset=28800000,dstSavings=0,
    //useDaylight=false,transitions=19,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,
    //YEAR=2022,MONTH=8,WEEK_OF_YEAR=37,WEEK_OF_MONTH=2,DAY_OF_MONTH=8,DAY_OF_YEAR=251,DAY_OF_WEEK=5,
    //DAY_OF_WEEK_IN_MONTH=2,AM_PM=1,HOUR=4,HOUR_OF_DAY=16,MINUTE=14,SECOND=40,MILLISECOND=991,
    //ZONE_OFFSET=28800000,DST_OFFSET=0]
    System.out.println(c1.get(Calendar.YEAR));
    System.out.println(c1.get(Calendar.MONTH)+1);
    System.out.println(c1.get(Calendar.DAY_OF_MONTH));
    System.out.println(calendar2Str(c1));
    //c1.set(Calendar.YEAR, c1.get(Calendar.YEAR)-1);//去年的今天
    //c1.add(Calendar.YEAR, -1);//去年的今天
    c1.add(Calendar.DAY_OF_MONTH, 1);//明天
    System.out.println(calendar2Str(c1));
    Date d1=new Date(0);//历元
    //c1.setTime(d1);
    System.out.println(calendar2Str(c1));
    //d1=c1.getTime();
    System.out.println(d1.toLocaleString());

    System.out.println(c1.getTimeInMillis());
    System.out.println(System.currentTimeMillis());
    //吧c1设置为历元
    c1.setTimeInMillis(0);
    System.out.println(calendar2Str(c1));

}
public static String calendar2Str(Calendar c) {
    //获取所有的时间参数
    String weeks=" 日一二三四五六";
    int year=c.get(Calendar.YEAR);
    int month=c.get(Calendar.MONTH)+1;
    int day=c.get(Calendar.DAY_OF_MONTH);
    int week=c.get(Calendar.DAY_OF_WEEK);//日-1, 一-2 .....六-7
    int hour=c.get(Calendar.HOUR_OF_DAY);
    int minute=c.get(Calendar.MINUTE);
    int second=c.get(Calendar.SECOND);
    return year+"年"+month+"月"+day+"日 星期"+(weeks.charAt(week))+" "+hour+":"+minute+":"+second;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
解释下列代码#include <iostream> #include <string> using namespace std; class Date { public: Date(int year, int month, int day) : year_(year), month_(month), day_(day) {}; friend ostream& operator<<(ostream& os, const Date& date) { os << date.year_ << "-" << date.month_ << "-" << date.day_; return os; } private: int year_; int month_; int day_; }; class Person { public: Person(const string& name, const Date& birthday) : name_(name), birthday_(birthday) {}; virtual ~Person() {}; protected: string name_; Date birthday_; }; class Teacher : public Person { public: Teacher(const string& id, const string& name, const Date& birthday, const string& major, const string& affiliation) : Person(name, birthday), id_(id), major_(major), affiliation_(affiliation) {}; void PrintInfo() const { cout << "Name: " << name_ << endl; cout << "Birthday: " << birthday_ << endl; cout << "Teacher ID: " << id_ << endl; cout << "Teaching Major: " << major_ << endl; cout << "Affiliation: " << affiliation_ << endl; cout << "The basic information: " << id_ << ' ' << name_ << ' ' << birthday_ << ' ' << major_ << ' ' << affiliation_ << endl; } private: string id_; string major_; string affiliation_; }; class Student : public Person { public: Student(const string& id, const string& name, int score, const Date& birthday) : Person(name, birthday), id_(id), score_(score) {}; void PrintInfo() const { cout << "Name: " << name_ << endl; cout << "Birthday: " << birthday_ << endl; cout << "Student ID: " << id_ << endl; cout << "Student Score: " << score_ << endl; cout << "The basic information: " << id_ << ' ' << name_ << ' ' << score_ << endl; cout << birthday_ << endl; } private: string id_; int score_; }; int main() { Date student_birthday(1976, 5, 27); //修改学生出生日期 Student student("2023007", "kxiong", 92, student_birthday); student.PrintInfo(); Date teacher_birthday(1998, 1, 7); //修改教师出生日期 Teacher teacher("20210058", "xsong", teacher_birthday, "Computer Science", "CTBu"); teacher.PrintInfo(); return 0; }
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值