C#认证考试试题汇编:第一单元:1,11 第二单元:1,11

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Text1_1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入一个正整数");
int n =Convert.ToInt32( Console.ReadLine());
int result = 0;
if(n%2!=0)
for(int i=1;i<=n;i+=2)
{
result+= i;
}
else
for(i=0;i<=n;i+=2)
{
result+=i;
}
Console.WriteLine(result);
Console.WriteLine("按回车结束");
Console.Readkey();
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test1_11
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入原字符串:");
string s_text = Console.ReadLine();
Console.WriteLine("请输入密钥字符串:");
string s_key = Console.ReadLine();
if(s_text.Length!=s_key.Length)
Console.WriteLine("密钥与字符串长度必须相等");
string ch=null;
string s_result = null ;
for (int i = 0; i < s_text.Length; i++)
{
ch+=s_text[i];
s_result+= (char)(ch[i] ^ s_key[i]);
}
Console.WriteLine(s_result);
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test2_11
{
class Animal
{
private bool m_sex;
private int m_age;
public Animal()
{
m_sex = false;
}
public bool Sex
{
get { return m_sex; }
set { m_sex = value; }
}
public int Age
{
get { return m_age; }
set { m_age=value; }
}
public virtual void Introduce()
{
if (Sex == true)
Console.WriteLine("this is a male Animal");
if (Sex == false)
Console.WriteLine("this is a female Animal");
}
}
class Dog:Animal
{
public Dog()
{
Sex = true;
}
public override void Introduce()
{
if (Sex == true)
Console.WriteLine("this is a male Dog");
if (Sex == false)
Console.WriteLine("this is a female Dog");
}
}
class Cat:Animal
{
public override void Introduce()
{
if (Sex == true)
Console.WriteLine("this is a male Cat");
if (Sex == false)
Console.WriteLine("this is a female Cat");
}
}
}
浙公网安备 33010602011771号