/eschool/video/c/
1.开发控制台应用程序,实现一个欢迎界面的功能。
首先程序提示用户输入姓名,然后显示"欢迎XXX进入C#的世界"。
最后显示一段鼓励的话,如"A ZA A ZA Fighting!"
2.已知两个矩形的长和宽,编程求它们的面积和周长。
假设,矩形1的长和宽分别为50和20;矩形2的长和宽分别为5.6和4.5.
3.写出一个控制台应用程序,实现一个string类型变量转换为一个int类型变量的多种方法。
4.编写一个控制台程序,将用户输入的以秒为单位计算的时间长度拆分为以时、分、秒计算,并输出。
5.编写程序,输出100以内个位数为6且能被3整除的所有的数。
6.编写程序,使用if语句将输入的三个整数按从小到大的顺序排序。
7.编写一个简单的计算器程序,能够根据用户从键盘输入的运算指令和整数,进行简单的加减乘除运算。
8.合数就是非素数,即除了1和它本身之外还有其他约数的正整数。
编写一个程序求出指定数据范围(假设10-100)内的所有合数。
9.定义两个方法,分别求两个正整数的最大公约数和最小公倍数。
其中,最大公约数的计算采用辗转除法;最小公倍数的计算采用先计算最大公约数。
然后再用两个数的积去除最大公约数未求得。
在Main方法中实现两个待求正整数的输入及结果的输出。
10.定义一个方法,给三个整数按从小到大的顺序排序并求其和及平均值。
其中,三个待求整数及其排序后的结果由引用参数传递;其和由输出参数传递;
平均值由返回值返回。在Main方法中实现三个待求整数的输入及结果的输出。
11.用重载方法实现两个整数或三个浮点数的排序,按照从小到大的顺序将排序结果输出。
12.创建一个类,它存储一个int数据成员MyNumber,并该该数据成员创建属性。当该数据成员被存储时,将其乘以100;当其被读取时,将其除以100.
13.在控制台应用程序中创建student类,并声明构造函数及构造函数的重载。
要求类定义中包含:学好(字符串),姓名(字符串),年龄(整形)和性别(布尔型)。
输出性别时,根据对应的布尔值,输出"男"或"女"。
要求:使用字段时可声明为公有,可以不使用属性。
声明三种不同的构造函数,包括:1).可初始化学好、姓名、性别与年龄字段值的构造函数;2).只初始化姓名的构造函数;3).声明默认的无参构造函数。
实现用不同的初始化方式来声明3个不同的对象,并输出相应成员的值。
14.在控制台应用程序中创建Car类,在类中定义字段和属性。
私有字段包括mcolor和mwheels,公有属性包括Color和Wheels。
构造对象mycar,并设置属性颜为"红",轮子数为4,最后输出
属性的值。
要求:设计完成后,利用单步执行(快捷键F11),了解属性的调用过程。
15.定义一个描述复数的类Complex并测试。Complex类中包含两个私有字段,
用于保存复数的实部和虚部,相应属性用于访问字段。
另外还定义有两个方法,分别用于对两个复数进行加、减四则运算,
且有带参数的构造函数,用于在创建复数对象时初始化复数的实部和虚部。
17.创建一个描述图书信息的类并测试。
类中应保存有图书的书号、标题、作者、出版社、价格等信息。
18.定义一个描述园的类Circle。类中包含一个私有字段radius,
用于保存圆的半径,一个属性Radius,用于读取和设置radius字段,
并定义有一个默认构造函数和一个带参数的构造函数,用于初始化对象。
另外,定义一个包含Main方法的类,在该类中定义一个方法CompareCircle,
用于比较两个圆的大小,其中待比较的圆对象由参数传递,
在Main方法中利用默认构造函数,创建一个半径为5的圆circle1,
利用带参数的构造函数创建三个圆circle2、circle3、circle4(半径分别为8、9、5),
并调用方法CompareCircle比较circle1和其他三个圆的大小。
19.编写一个矩形类,私有数据成员为矩形的长(len)和宽(wid),
类包括取矩形的长度Len、取矩形的宽度Wid、
求矩形的周长,求面积、修改矩形的长度和宽度为对应的形参值等公用属性和方法。
另外,无参构造函数将Len和Wid设置为0,有参构造函数设置Len和Wid的值。
分别实例化不同的对象并调用相应成员。
20.定义多边形类Polygon,在类中定义字段、属性和虚方法;
由基类Polygon创建派生类Square和Pentagon。在派生类中实现方法重写;
在程序中实例化类的对象并且调用类的方法实现多态性。
/
/1.开发控制台应用程序,实现一个欢迎界面的功能。
//首先程序提示用户输入姓名,然后显示"欢迎XXX进入C#的世界"。
//最后显示一段鼓励的话,如"A ZA A ZA Fighting!"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace exercise
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入您的姓名:");
string s = Console.ReadLine();
Console.WriteLine("欢迎" + s + "进入C#的世界!");
Console.WriteLine("A ZA A ZA Fighting!");
}
}
//2.已知两个矩形的长和宽,编程求它们的面积和周长。
//假设,矩形1的长和宽分别为50和20;矩形2的长和宽分别为5.6和4.5.
/
/长、宽由键盘输入。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace exercise
{
class Program
{
static void Main(str
ing[] args)
{
Console.WriteLine("请输入第1个矩形的长和宽:");
float a1 = Convert.ToSingle(Console.ReadLine());
float b1 = Convert.ToSingle(Console.ReadLine());
Console.WriteLine("请输入第2个矩形的长和宽:");
float a2 = Convert.ToSingle(Console.ReadLine());
float b2 = Convert.ToSingle(Console.ReadLine());
Console.WriteLine("第1个矩形的周长是{0},面积是{1}", 2 * (a1 + b1), a1 * b1);
Console.WriteLine("第2个矩形的周长是{0},面积是{1}", 2 * (a2 + b2), a2 * b2);
}
}
c++string类型}
//3.写出一个控制台应用程序,实现一个string类型变量转换为一个int类型变量的多种方法。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace exercise
{
class Program
{
static void Main(string[] args)
{
try
{
string s = Console.ReadLine();
int i = Convert.ToInt32(s);    //第1种方法
int j = Int32.Parse(s);        //第2种方法
Console.WriteLine("{0},{1}", i, j);
}
catch (Exception ex)
{
Console.WriteLine("有错误");
}
}
}
//4.编写一个控制台程序,将用户输入的以秒为单位计算的时间长度拆分为以时、分、秒计算,并输出。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace exercise
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("请输入整数");
int t = Int32.Parse(Console.ReadLine());
int h = t / 3600;
int m = t % 3600 / 60;
int s = t % 60;
Console.WriteLine(t + "秒转换为:");
Console.WriteLine("{0}小时{1}分{2}秒", h, m, s);
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine("有错误");
}
}
}
/
/5.编写程序,输出100以内个位数为6且能被3整除的所有的数。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace exercise
{
class Program
{
static void Main(string[] args)
{
try
{
for (int i = 1; i < 100; i++)
if ((i % 10 == 6) && (i % 3 == 0))
Console.WriteLine(i);
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine("有错误");
}
}
}
//6.编写程序,使用if语句将输入的三个整数
按从小到大的顺序排序。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace exercise
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("请输入三个整数:");
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
int c = Convert.ToInt32(Console.ReadLine());
int t;
if (a > b)
{
t = a; a = b; b = t;
}
if (b > c)
{
t = b; b = c; c = t;
}
if (a > b)
{
t = a; a = b; b = t;
}
Console.WriteLine("排序后为:{0},{1},{2}", a, b, c);
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine("有错误");
}
}
}
/
/7.编写一个简单的计算器程序,能够根据用户从键盘输入的运算指令和整数,进行简单的加减乘除运算。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace exercise
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("请输入两个运算数字:");
int a = Int32.Parse(Console.ReadLine());
int b = Int32.Parse(Console.ReadLine());
Console.WriteLine("请输入运算符号:");
char s = Convert.ToChar(Console.ReadLine());
switch (s)
{
case '+':
Console.WriteLine(a + "+" + b + "={0}", a + b);
break;
case '-':
Console.WriteLine(a + "-" + b + "={0}", a - b);
break;
case '*':
Console.WriteLine(a + "*" + b + "={0}", a * b);
break;
case '/':
Console.WriteLine(a + "/" + b + "={0}", (Single)a / b);
break;
default:
Console.WriteLine("输入的运算符有误!");
break;
}
}
catch (Exception ex)
{
Console.WriteLine("有错误");
}
}
}
/
/8.合数就是非素数,即除了1和它本身之外还有其他约数的正整数。
//编写一个程序求出指定数据范围(假设10-100)内的所有合数。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace exercise
{
class Program
{
static void Main(string[] args)
{
try
{
for (int i =10;i<100;i++)
for (int j=2;j<i/2;j++)
if (i % j == 0)
{
Console.Write(i);
Console.Write(" ");
break;
}
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine("有错误");
}
}
}
//9.定义两个方法,分别求两个正整数的最大公约数和最小公倍数。
//其中,最大公约数的计算采用辗转除法;最小公倍数的计算采用先计算最大公约数。
/
/然后再用两个数的积去除最大公约数未求得。
//在Main方法中实现两个待求正整数的输入及结果的输出。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace exercise
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入两个正整数:");
int i = Convert.ToInt32(Console.ReadLine());
int j = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("最大公约数是:{0}", gcd(i, j));
Console.WriteLine("最小公倍数是: {0}", gcm(i, j));
}
public static int gcd(int a, int b)
{
int max = a > b ? a : b;            // 如果a>b,则max=a;如果a<b,则max=b。
int r = a % b;
while (r != 0)
{
a = b; b = r; r = a % b;
}
return b;
}
public static int gcm(int a, int b)
{
return a * b / gcd(a, b);
}
}
//10.定义一个方法,给三个整数按从小到大的顺序排序并求其和及平均值。
//其中,三个待求整数及其排序后的结果由引用参数传递;其和由输出参数传递;
//平均值由返回值返回。在Main方法中实现三个待求整数的输入及结果的输出。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace exercise
{
class Program
{
static void Main(string[] args)
{
try
{
int s = 0;
Console.WriteLine("请输入3个正整数:");
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
int c = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("平均值为:" + function(ref a, ref b, ref c, out s));
Console.WriteLine("排序后:{0},{1},{2}", a, b, c);
Console.WriteLine("和为:" + s);
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。