簡單類及成員實例【C#】

簡單類及成員實例(C#)

題目描述

簡單類及成員實例。定義了如下圖所示類Student,根據下圖和給出代碼,補寫缺失的代碼。

using System;
namespace sample{

? ? class Student {
? ? ? ? public string studentid;//學號
? ? ? ? public string studentname;//姓名
? ? ? ? private string birthplace;//籍貫
? ? ? ? private DateTime birthdate;//出生日期
? ? ? ? /

? ? ? ? //請填寫代碼,實現類的無參和有參構造函數、
? ? ? ? //屬性StudentId、StudentName、BirthPlace、BirthDate、Age

? ? ? ? /
? ? }

? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? Student zs = new Student("201753501234", "zs");
? ? ? ? ? ? zs.BirthDate = DateTime.Parse("1988-12-10");
? ? ? ? ? ? zs.BirthPlace = "jinan";
? ? ? ? ? ? string s = "name:{0},no:{1},native:{2},age:{3}";
? ? ? ? ? ? Console.WriteLine(s,zs.StudentName,zs.StudentId,zs.BirthPlace,zs.Age);
? ? ? ? }
? ? }
}

輸入

輸出

輸出姓名、學號、籍貫、年齡等信息

樣例輸入

copy

樣例輸出

name:zs,no:201753501234,native:jinan,age:33

提示

1、年齡Age是只讀屬性,

2、學號StudentId、姓名StudentName、出生日期BirthDate、籍貫BirthPlace為一般屬性;

3、構造函數有無參和有參兩種;

        public Student(string s1,string s2){studentid = s1;studentname = s2;}public DateTime BirthDate{get { return birthdate; }set { birthdate = value; }}public string BirthPlace{get { return birthplace; }set { birthplace = value; }}public string StudentName{get { return studentname; }}public string StudentId{get { return studentid; }}public string Age{get{DateTime now = new DateTime();now = DateTime.Parse("2021-12-10");TimeSpan ts = now - birthdate;int age = ts.Days / 365;return age.ToString();}}

?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/536238.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/536238.shtml
英文地址,請注明出處:http://en.pswp.cn/news/536238.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

C#組成考題字符串【C#】

C#組成考題字符串 題目描述 假定已經獲取題庫中的試題號,并存放在數組arrayKT中。例如, int [] arrayKT{10,13,18,19,20,22,30,31}。定義一個靜態成員方法,該方法實現從上述數組中隨機抽出n(narrayKT.Length-1)道考題,并組成一個考題字符串…

c#統計字符串中數字字符的個數【C#】

c#統計字符串中數字字符的個數 題目描述 假設有一個GetNumber方法(參數為字符串strSource),編寫一個靜態方法可以用來統計字符串strSource中數字字符的個數。 輸入 輸入一個字符串strSource輸出 strSource字符串中數字字符的個數樣例輸入 s…

c#隨機數的產生與輸出【C#】

c#隨機數的產生與輸出 題目描述 編寫一個實例方法Method01。該方法使用Random類隨機產生n個3位數字(如636)的隨機正整數,并把產生的隨機數存入數組中并輸出該數組int num Convert.ToInt32(Console.ReadLine()); using System; using System…

C#統計字符出現的個數【C#】

C#統計字符出現的個數 題目描述 編寫一個實例方法getCountChar方法。該方法參數有兩個,第一個參數可以是字符串s,第二個參數為字符c,方法返回值為第二個參數在第一個參數中出現次數。例如,CountChar("6221982",2)返回…

C# teacher類【C#】

C# teacher類 題目描述 定義一個教師類Teacher,具體要求如下: 1、私有字段工號no(string)、姓名name(string)、出生日期birthday(DateTime)、性別sex(SexFlag&#xff0…

c#簡單類的繼承【C#】

c#簡單類的繼承 題目描述 編寫代碼實現:定義了三個類Bird、Mapie、Eagle。其中Bird為抽象類,定義了一個抽象方法Eat()。Mapie類和Eagle類為Bird的派生類。Mapie類中重寫了Eat()方法,重載了一個Eat(int time)方法。Eagle類中也重寫了Eat()方…

c#計算長方形的面積(繼承問題)【C#】

c#計算長方形的面積(繼承問題) 題目描述 根據給出的代碼,補全缺失的代碼,輸入兩個數字為長方形的長和寬,從而得出長方形的面積。 using System; namespace InheritanceApplication { class Shape { pub…

C#委托、類和事件的驗證【C#】

C#委托、類和事件的驗證 題目描述 程序由兩部分組成,如下代碼所示。第一部分定義了委托、類和事件。第二部分進行驗證。 using System; namespace HelloWorldApplication { public delegate void DelegateRing();public class Bell{ public event DelegateRing R…

接口實例(C#,IShape)【C#】

接口實例(C#,IShape) 題目描述 接口實例。接口和類如下圖所示,根據給出代碼,補寫缺失的代碼,然后在Program類的靜態Main方法中驗證所實現的類。 using System; namespace Myinterface { public interface IShape…

c#補充print(多態性問題)【C#】

c#補充print(多態性問題) 題目描述 根據給出代碼,補寫缺失代碼,當print函數內為整數的時候,輸出整數的三次方,為浮點數,輸出其二次方,為字符串時,直接輸出。 using Sys…

1439: 2.4.5 Fractions to Decimals 分數化小數

1439: 2.4.5 Fractions to Decimals 分數化小數 時間限制: 1 Sec 內存限制: 64 MB提交: 194 解決: 13題目描述 寫一個程序,輸入一個形如N/D的分數(N是分子,D是分母),輸出它的小數形式。 如果小數有循環節的話,把循環節放在一對圓…

Problem B: 求各位數字之和

#include <stdio.h> #include <stdlib.h> int main() { int n,sum0,m; while(~scanf("%d",&n)) { while(n>0) { mn%10; nn/10; summ; } printf("%d\n",sum); sum0; } return 0; }

Problem C: 判斷字符串是否為回文

#include <stdio.h> #include <stdlib.h> int main() { int i,j,n; char str[10]; gets(str); nstrlen(str); for(i0,jn-1;i<j;i,j--) { if(str[i]!str[j]) { printf("No\n"); break; } } if(i>j)printf("Yes\n"); return 0; }

Problem A: 童年生活二三事

斐波那契數列:F(n)F(n-1)F(n-2) #include <stdio.h> #include <stdlib.h> int f(int n) {int b;if(n1)b1;if(n2)b2;if(n>2)bf(n-1)f(n-2);return b; }int main() {int a,n;while(~scanf("%d",&n)&&n!0){af(n);printf("%d\n",a…

Problem C: 01字串

#include <stdio.h> #include <stdlib.h>int main() {int i,j,n0,m0;char a[129][8];for(i0;i<128;i){for(j0;j<7;j){a[i][j]n%2;nn/2;}m;nm;}for(i0;i<128;i){for(j6;j>0;j--)printf("%d",a[i][j]);printf("\n");}return 0; }

漢諾塔III

#include <stdio.h> #include <stdlib.h> int main() {int fx(int );int n,m;while(~scanf("%d",&n)){mfx(n);printf("%d\n",m);}return 0; } int fx(int n) {int m;if(n1)m2;if(n>1)m3*fx(n-1)2;return m; }

Problem B: C語言習題 學生成績輸入和輸出

Problem B: C語言習題 學生成績輸入和輸出 Description 編寫一個函數print&#xff0c;打印一個學生的成績數組&#xff0c;該數組中有5個學生的數據&#xff0c;每個學生的數據包括num(學號)、name(姓名)、score3。編寫一個函數input&#xff0c;用來輸入5個學生的數據。 I…

Problem E:結構體---點坐標結構體

Problem E: 結構體—點坐標結構體 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 585 Solved: 395 [Submit][Status][Web Board] Description 定義一個表示點坐標的結構體&#xff0c;輸入兩個點的坐標&#xff0c;輸出這兩個點中點的坐標 Input 第一個點的坐標&…

Problem F: 結構體--學生信息排序

Problem F: 結構體–學生信息排序 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 378 Solved: 192 [Submit][Status][Web Board] Description 定義存放一個學生信息的結構體類型&#xff0c;學生信息包括&#xff1a;姓名&#xff0c;學號&#xff0c;性別&#xff0c;…

Problem D: 分數減法——結構體

Problem D: 分數減法——結構體 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 604 Solved: 462 [Submit][Status][Web Board] Description 分數可以看成是由字符’/’分割兩個整數構成&#xff0c;可以用結構體類型表示。請用結構體類型變量計算兩個分數的差。 注意&…