C#认证二单元 第一题

1:运行结果

代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Txst2_1
{
class Animal
{
private Boolean m_sex;
private int m_age;
public bool Sex
{
get { return m_sex; }
set { m_sex = false; }
}
public int Age
{
get { return m_age; }
set { m_age = value; }
}
public virtual string Introduce()
{
if (Sex == true)
return "This is a male Animal";
else
return "This is a female Animal";
}
}
class Dog:Animal
{
public Dog()
{
Sex = true;
}
public override string Introduce()
{
if (Sex == true)
return "This is a male Dog";
else
return "This is a female Dog";
}
}
class Cat:Animal
{
public override string Introduce()
{
if (Sex == true)
return "This is a male Cat";
else
return "This is a female Cat";
}
}
class Program
{
static void Main(string[] args)
{
Animal ani = new Animal();
Console.WriteLine(ani.Introduce());
Animal dog = new Dog();
Console.WriteLine(dog.Introduce());
Animal cat = new Cat();
Console.WriteLine(cat.Introduce());
Console.Read();
}
}
}

时间: 2024-08-06 16:00:39

C#认证二单元 第一题的相关文章

POJ 1830 【高斯消元第一题】

首先...使用abs()等数学函数的时候,浮点数用#include<cmath>,其它用#include<cstdlib>. 概念: [矩阵的秩] 在线性代数中,一个矩阵A的列秩是A的线性无关的纵列的极大数目.类似地,行秩是A的线性无关的横行的极大数目. 此题如果有解,解的个数便是2^(自由变元个数),因为每个变元都有两种选择,既1 << n 对于r以下的行,必定全是0,那么如果a[i][n]!=0 必然出现矛盾,于是判定无解. 1 #include <iostr

C#R认证第二单元第一题

namespace Txst2_1{ class Animal { private Boolean m_sex; private int m_age; public bool Sex { get { return m_sex; } set { m_sex = false; } } public int Age { get { return m_age; } set { m_age = value; } } public virtual string Introduce() { if (Sex =

第五,六,九,十二单元练习

第五,六单元练习 1.新建用户组,shengchan,caiwu,jishu 2.新建用户要求如下: * tom 是shengchan组的附加用户 * harry 是caiwu组的附加用户 * leo 是jishu组的附加用户 * 新建admin用户,此用户不属于以上提到的三个部门 3.新建目录要求如下: * /pub目录为公共存储目录对所有用户可以读,写,执行,但用户只能删除属于自己的文件 * /sc 目录为生产部存储目录只能对生产部人员可以写入, 并且生产部人员所建立的文件都自动归属到she

一道模板元编程题源码解答(replace_type)

今天有一同学在群上聊到一个比较好玩的题目(本人看书不多,后面才知是<C++模板元编程>第二章里面的一道习题), 我也抱着试一试的态度去完成它, 这道题也体现了c++模板元编程的基础和精髓: 类型就是数据. 题目如下所述: Write a ternary metafunction replace_type<c,x,y> that takes an arbitrary compound type c as its first parameter, and replaces all oc

matlab_exercise(4)----第一题

第二次作业-----第一题 题目: 1.某零售店有9种商品的单件进价(元).售价(元)及一周的销量如下表, 问哪种商品的单件利润最大,哪种商品的单件利润最小: 按收入由小到大,列出所有商品及其收入: 求这一周该10种商品的总收入和总利润. 货号 1 2 3 4 5 6 7 8 9 单件进价 7.15 8.25 3.20 10.30 6.68 12.03 16.85 17.51 9.30 单件售价 11.10 15.00 6.00 16.25 9.90 18.25 20.80 24.15 15.5

2016/1/12 第一题 输出 i 出现次数 第二题 用for循环和if条件句去除字符串中空格 第三题不用endwith 实现尾端字符查询

1 import java.util.Scanner; 2 3 4 public class Number { 5 6 private static Object i; 7 8 /* 9 *第一题 mingrikejijavabu中字符“i” 出现了几次,并将结果输出*/ 10 public static void main(String[] args) { 11 12 String r ="imingrikejijavabi"; 13 14 15 //第一种 截取 16 int a=

第十二单元练习题

<<<第十二单元练习>>> 1.在server主机中把/etc目录打包压缩到/mnt中,名字为etc.tar.gz 2.复制server主机中的etc.tar.gz到desktop主机的/mnt中 3.同步server主机中的/etc中的所有文件到desktop主机中/mnt中,包含链接文

leetcode中第一题twosum问题解答算法的可行性证明

leetcode中第一题twosum问题解答算法的可行性证明 一.引入 关于leetcode中第一题twosum问题,网上已有不少高人做出过解答,并提出了切实可行的算法实现.我在解答该题时参考了博客http://www.zixue7.com/article-9576-1.html的解答.为让读者更直观地阅读和理解本文,先简要摘录以上博客的内容如下: 题目还原 Two Sum Given an array of integers, find two numbers such that they a

第五届在线编程大赛月赛第一题:完全平方数的个数

第五届在线编程大赛月赛第一题:完全平方数的个数 题目详情: 给定整数区间[A,B]问其中有多少个完全平方数. 输入格式: 多组数据,包含两个正整数A,B 1<=A<=B<=2000000000. 输出格式: 每组数据输出一行包含一个整数,表示闭区间[A,B]中包含的完全平方数的个数. 答题说明: 输入样例 1 1 1 2 3 10 3 3 输出样例: 1 1 2 0 java代码: import java.util.Scanner; public class One { public s