2024年4月12日发(作者:)
用visual studio 2005做的
(1)编程输出1到100中能被3整除但不能被5整除的数,并统计有多少个这样的
数。
(2)创建一个控制台应用程序,编写一个函数将十进制数转换成二进制数。程序可以
让用户一直进行转换,直到输入0为止。程序中要对格式转换异常进行处理。
(3)创建一个类,它存储一个int数据成员MyNumber,并给该数据成员创建属性,
当该数据成员被存储时,将其乘以100;当其被读取时,将其除以100。
(4)设计一个类,要求用事件每10秒报告机器的当前时间。
(5)编写一个程序接受用户输入的字符。如果输入的字符是0-9数字中的一个,则
显示“您输入了一个数字”,否则显示“这不是一个数字”。
(6)编写一个程序,该程序使用一个数组存储30个学生的考试成绩,并给各个数组
元素指定一个1-100的随机值,要求利用索引来对数组中的元素进行赋值和显示。然后计
算平均成绩。
(7)编写一个windows应用程序,能将窗体背景颜色1秒钟变换一次。
(8)通过方法重载,使用同一个方法名print分别执行输出整数、双精度数与字符串
的功能。
1.
using System;
using c;
using ;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int sum = 0;
ine("能被3整除但不能被5整除的数 ");
for (int i = 1; i <= 100; i++)
{
if (i % 3 == 0 && i % 5 != 0)
{
("{0,4}",i);
sum++;
}
}
ine("共有 {0}个", sum);
}
}
}
2.
using System;
using c;
using ;
namespace ConsoleApplication2
{
class Program
{
static void Change(int m, int n, out int[] a, out int i)
{
a = new int[20];
i = 0;
while (m != 0)
{
a[i] = m % n;
m = m / n;
i++;
}
}
static void Main(string[] args)
{
try
{
while (true)
{ ("输入一个十进制数(输入0为止):");
int n = 32(ne());
if (n != 0)
{
int m = 2;
int[] s; int i;
Change(n, m, out s, out i);
("转换的二进制为:");
for (int j = i - 1; j >= 0; j--)
{
(s[j]);
}
ine();
}
else
{ return; }
}
}
catch (Exception )
{
("格式转换错误");
}
}
}
}
3.
using System;
using c;
using ;
namespace ConsoleApplication3
{
class MyClass
{
int MyNumber;
public int mynumber
{
get
{
return MyNumber / 100;
}
set
{
MyNumber = value * 100;
}
}
static void Main(string[] args)
{
("请输入任意一个数:");
int a = 32(ne());
MyClass m = new MyClass();
("结果为:");
er = a;
ine("{0}", er);
}
}
}
4.
using System;
using c;
using ;
using ing;
namespace ConsoleApplication4
{
class ClassA
{
public void TimerHandlerA(object obj, EventArgs e) // Event
handler
{
ine(TimeString());
}
}
class Program
{
static void Main()
{
ClassA ca = new ClassA(); //
Create the class object.
MyTimerClass
// Create the timer object.
mc = new MyTimerClass();
d += andlerA; //
Add handler A -- instance.
(100000);
}
}
public class MyTimerClass
{
public event EventHandler Elapsed;
private void OnOneSecond(object obj, EventArgs e)
{
if (Elapsed != null)
Elapsed(obj, e);
}
private MyPrivateTimer; // Private timer
public MyTimerClass() // Constructor
{
MyPrivateTimer = new (); // Create the private
timer.
d += OnOneSecond; // Attach our event
handler.
al = 10000; // 1 second interval.
// Property Enabled is of type bool, and turns the timer on and off.
d = true; // Start the timer.
}
}
}
5.
using System;
using c;
using ;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a;
("请输入一个字符:");
a = 32(ne());
switch (a)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
ine("您输入了一个数字");
break;
default:
ine("这不是一个数字");
break;
}
}
}
6.
using System;
using c;
using ;
namespace ConsoleApplication2
{
class CMyclass
{
public float[] a;
public CMyclass()
{
a = new float[30];
}
public float this[int index]
{
get
{
return a[index];
}
set
{
a[index]=value;
}
}
}
class Program
{
static void Main(string[] args)
{
float avg=0;
CMyclass m=new CMyclass();
Random n=new Random();
for(int i=0;i<30;i++)
{
m[i]=(100);
}
for (int i = 0; i < 30; i++)
{
("{0}", m[i]);
ine();
}
float sum=0;
for(int i=0;i<30;i++)
{
sum+=m[i];
}
avg=sum/30;
ine("avg is {0}",avg);
}
}
}
7.
using System;
using c;
using entModel;
using ;
using g;
using ;
using ;
namespace ConsoleApplication3
{
public partial class Form1 : Form
{
static int i, j, k;
public Form1()
{
InitializeComponent();
i = 100; j = 50; k = 200;
}
private void timer1_Tick(object sender, EventArgs e)
{
al = 1000;
BackColor = gb(i, j, k);
i = i+30;
j = j+100;
k = k+10;
if (i > 255 || j > 255 ||k > 255)
{
i = 100;
j=50;
k=200;
}
}
}
}
8.
using System;
using c;
using ;
namespace ConsoleApplication4
{
class Myclass
{
public int print(int x)
{
return x;
}
public double print(double x)
{
return x;
}
public string print(string x)
{
return x;
}
}
class Program
{
static void Main(string[] args)
{
Myclass m = new Myclass();
int a;
ine("请输入一个整数:");
a = 32(ne());
ine("int a={0}",a,(a));
double b;
ine("请输入一个双精度数:");
b = le(Console .ReadLine ());
ine("double x={0}", b, (b));
string c;
ine("请输入一个字符串:");
c = ng(ne());
ine("string c={0}", c, (c));
();
}
}
}


发布评论