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

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

題目描述

根據給出代碼,補寫缺失代碼,當print函數內為整數的時候,輸出整數的三次方,為浮點數,輸出其二次方,為字符串時,直接輸出。

using System;
namespace PolymorphismApplication
{
? ?class Printdata
? ?{
? ? ? /******************************************/
? ? ? ? ?在此處補寫代碼,并只提交此處的代碼
? ?/******************************************/
? ? ? static void Main(string[] args)
? ? ? {
? ? ? ? ?Printdata p = new Printdata();
? ? ? ? ?
? ? ? ? ?p.print(2);
? ? ? ??
? ? ? ? ?p.print(1.23);
? ? ??
? ? ? ? ?p.print("Hello world");
? ? ? ? ?Console.ReadKey();
? ? ? }
? ?}
}
?

輸入

?

輸出

8
1.5129
Hello world

樣例輸出

8
1.5129
Hello world
        public void print(int a){Console.WriteLine(a*a*a);}public void print(double a){Console.WriteLine(a*a);}public void print(String a){Console.WriteLine(a);}

?

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

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

相關文章

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;可以用結構體類型表示。請用結構體類型變量計算兩個分數的差。 注意&…

Problem G: C語言習題 醫生值班

Problem G: C語言習題 醫生值班 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 847 Solved: 102[Submit][Status][Web Board]Description 醫院內科有A,B,C,D,E,F,G,H共七位醫生&#xff0c;每人在一周內要值一次夜班&#xff0c;排班的要求是&#xff1a; &#xff08;1&a…

Problem A: 刪除區間內的元素(線性表)

Problem A: 刪除區間內的元素&#xff08;線性表&#xff09; Time Limit: 1 Sec Memory Limit: 2 MBSubmit: 75 Solved: 24[Submit][Status][Web Board]Description 若一個線性表L采用順序存儲結構&#xff0c;其中元素都為整數。設計一個算法&#xff0c;刪除元素值在[x,y…

問題 B: 調整表中元素順序(線性表)

問題 B: 調整表中元素順序&#xff08;線性表&#xff09; 時間限制: 1 Sec 內存限制: 2 MB提交: 28 解決: 11[提交][狀態][討論版]題目描述 若一個線性表L采用順序存儲結構存儲&#xff0c;其中所有元素都為整數。設計一個算法&#xff0c;將所有小于0的元素移到所有大于0的…

Problem C: 順序表基本運算(線性表)

問題 C: 順序表基本運算&#xff08;線性表&#xff09; 時間限制: 1 Sec 內存限制: 128 MBDescription 編寫一個程序&#xff0c;實現順序表的各種基本運算&#xff08;假設順序表的元素類型為char&#xff09;&#xff0c;主函數已給出&#xff0c;請補充每一種方法。 1、初…

Problem D: 鏈表的基本運算(線性表)

Problem D: 鏈表的基本運算&#xff08;線性表&#xff09; Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 18 Solved: 10Description 編寫一個程序&#xff0c;實現鏈表的各種基本運算&#xff08;假設順序表的元素類型為char&#xff09;&#xff0c;主函數已給出&#…

Problem B: 結構體---職工信息結構體

Problem B: 結構體---職工信息結構體 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 504 Solved: 306編寫程序&#xff0c;定義一個存放職工信息的結構體類型&#xff0c;職工信息包括職工姓名、工作年限、工資總額。初始化5名職工的信息&#xff0c;對工作年限超過30年的…

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

Problem C: 結構體---點坐標結構體 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 663 Solved: 444[Submit][Status][Web Board]Description 定義一個表示點坐標的結構體&#xff0c;輸入兩個點的坐標&#xff0c;輸出這兩個點中點的坐標 Input 第一個點的坐標&#xff08…

Problem D: 編程題B-向量的數量積

Problem D: 編程題B-向量的數量積 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 164 Solved: 148Description 已知兩個非零向量a&#xff08;x1&#xff0c;y1&#xff09;&#xff0c;b&#xff08;x2&#xff0c;y2&#xff09;&#xff0c;則有abx1x2y1y2&#xff0c;…

Problem E: 高于均分的學生

Problem E: 高于均分的學生 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 67 Solved: 45Description 輸入n(<100)個學生的姓名、學號和成績&#xff0c;將其中高于平均成績的姓名、學號和成績輸出。 Input 第一行為學生人數 n 第二行到第n1行&#xff0c;每行一個學生…

Problem E: 建立鏈表(線性表)

Problem E: 建立鏈表(線性表) Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 323 Solved: 207Description &#xff08;線性表&#xff09;設鍵盤輸入n個英語單詞&#xff0c;輸入格式為n, w1, w2, …,wn,其中n表示隨后輸入英語單詞個數&#xff0c;試編一程序&#xff0c…