想用C#做点东西,请高手指点下

hejianbo1985 2007-10-11 09:24:01
学了C#已经快1个月了,想做点实际的东西,请各位告诉我一些题目以及主要实现的功能.
不管谁只要说了一个题目以及一些详细的东西的,都给10分以上的分.谢谢!!!!!!!
...全文
121 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyi8808 2007-10-11
  • 打赏
  • 举报
回复
计算表达式的代码用的是“银河”的代码(VB版):
http://www.cnblogs.com/skyivben/archive/2005/10/31/265861.html

// VBExpression.cs - 动态生成数学表达式并计算其值
// 表达式使用 Visual Baisc 语法,可带一个的自变量(x)
// 可使用 pi、e 等常量,sin、cos、tan、log、sqrt 等函数
// 例子:e + sqrt(log(pi ^ e) * x) + sin(x * pi / 180)

using System;
using System.CodeDom.Compiler;
using Microsoft.VisualBasic;
using System.Reflection;
using System.Text;
using System.Globalization;

namespace Skyiv.Util
{
sealed class Expression
{
object instance;
MethodInfo method;

public Expression(string expression)
{
if (expression.ToUpper(CultureInfo.InvariantCulture).IndexOf("RETURN") < 0) expression = "Return " + expression;
string className = "Expression";
string methodName = "Compute";
CompilerParameters p = new CompilerParameters();
p.GenerateInMemory = true;
CompilerResults cr = new VBCodeProvider().CompileAssemblyFromSource
(
p,
string.Format
(
@"Option Explicit Off
Option Strict Off
Imports System, System.Math, Microsoft.VisualBasic
NotInheritable Class {0}
Public Function {1}(x As Double) As Double
{2}
End Function
End Class",
className, methodName, expression
)
);
if(cr.Errors.Count > 0)
{
string msg = "Expression(\"" + expression + "\"): \n";
foreach (CompilerError err in cr.Errors) msg += err.ToString() + "\n";
throw new Exception(msg);
}
instance = cr.CompiledAssembly.CreateInstance(className);
method = instance.GetType().GetMethod(methodName);
}

public double Compute(double x)
{
return (double)method.Invoke(instance, new object [] { x });
}
}
}
wuyi8808 2007-10-11
  • 打赏
  • 举报
回复
// Calc.cs - 表达式计算器
// 编译方法: csc /t:winexe Calc.cs VBExpression.cs

using System;
using System.Windows.Forms;
using Skyiv.Util;

namespace Skyiv
{
class Calc : Form
{
TextBox tbxA1, tbxA2, tbxA3;

Calc()
{
Text = "表达式计算器";
StartPosition = FormStartPosition.CenterScreen;
Width = 400;
Height = 200;

Label lblA1 = new Label();
lblA1.Text = "表达式(&E)";
lblA1.Parent = this;
lblA1.Top = 23;
lblA1.Left = 10;
lblA1.AutoSize = true;

tbxA1 = new TextBox();
tbxA1.Parent = this;
tbxA1.Top = 20;
tbxA1.Left = 80;
tbxA1.Width = 300;
tbxA1.BorderStyle = BorderStyle.FixedSingle;

Label lblA2 = new Label();
lblA2.Text = "自变量(&X)";
lblA2.Parent = this;
lblA2.Top = 48;
lblA2.Left = 10;
lblA2.AutoSize = true;

tbxA2 = new TextBox();
tbxA2.Parent = this;
tbxA2.Top = 45;
tbxA2.Left = 80;
tbxA2.Width = 300;
tbxA2.BorderStyle = BorderStyle.FixedSingle;

Button btnA3 = new Button();
btnA3.Text = "计算(&C)";
btnA3.Parent = this;
btnA3.Top = 70;
btnA3.Left = 10;
btnA3.Width = 62;
btnA3.Click += new EventHandler(Calc_Clicked);

tbxA3 = new TextBox();
tbxA3.Parent = this;
tbxA3.Top = 70;
tbxA3.Left = 80;
tbxA3.Width = 300;
tbxA3.BorderStyle = BorderStyle.FixedSingle;
tbxA3.ReadOnly = true;


TextBox tbxA4 = new TextBox();
tbxA4.Text = @"
表达式使用 Visual Baisc 语法,可带一个的自变量(x)
可使用 pi、e 等常量,sin、cos、tan、log、sqrt 等函数
例子:x * cos(x * pi / sqrt(25 * 6^4)) + log(E^10)";
tbxA4.Parent = this;
tbxA4.Top = 95;
tbxA4.Left = 10;
tbxA4.Width = 370;
tbxA4.Height = 65;
tbxA4.BorderStyle = BorderStyle.None;
tbxA4.Multiline = true;
tbxA4.ReadOnly = true;
}

void Calc_Clicked(object sender, EventArgs ea)
{
(sender as Control).Enabled = false;
try
{
double x = 0;
if (tbxA2.Text.Trim().Length != 0)
{
try
{
x = double.Parse(tbxA2.Text);
}
catch
{
try
{
x = (new Expression(tbxA2.Text)).Compute(0);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "自变量出错");
}
}
}
tbxA3.Text = (new Expression(tbxA1.Text)).Compute(x).ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "表达式出错");
}
finally
{
(sender as Control).Enabled = true;
}
}

[STAThread]
static void Main(string [] args)
{
Application.Run(new Calc());
}
}
}
wuyi8808 2007-10-11
  • 打赏
  • 举报
回复

一个表达式计算器,用C#写的,利用了VB编译器的强劲性能,可以计算任何合法的VB表达式,可以有一个自变量(x),也可以不要自变量。


wuyi8808 2007-10-11
  • 打赏
  • 举报
回复
如果说计算器,这个应该不错吧,先乘除后加减这些都是意思啦。
http://www.cnblogs.com/skyiv/archive/2007/08/21/Calc.html
yjlove51 2007-10-11
  • 打赏
  • 举报
回复
做个博客系统
pepsibeast 2007-10-11
  • 打赏
  • 举报
回复
作个同学录吧,很有意思的,仿照chinaren那样子。
Code従業員 2007-10-11
  • 打赏
  • 举报
回复
最后在程序的基础上,增加算法,可以实现到解决一些函数的问题,又可以卖初中生了.
Code従業員 2007-10-11
  • 打赏
  • 举报
回复
做好计算器后,可以考虑做个算式解答器,如输个式子"1+3*(5+4)"只要一打"="号就出结果(最好可以显示递等式的过程),做好可以高价卖给周边的小学生,有商机哦.
Code従業員 2007-10-11
  • 打赏
  • 举报
回复
做个计算器,实用也有成就感.一些细节也很有思想启迪,比如先乘除后加减如何做啊,这些.
linsoo 2007-10-11
  • 打赏
  • 举报
回复
Winform的话可以做做俄罗斯方块什么的游戏,也可以做做 图书馆管理系统 什么的...

Webform的话可以从新闻发布系统开始,有后台管理包括新闻添加修改删除,最好能无限分类
netnpc 2007-10-11
  • 打赏
  • 举报
回复
你可以做一个简单的 数据的增删改 查询统计 的功能. 比如 你可以给自己做一个 日志 系统 ,记录一下每天的消费状况和每天的生活描述. 然后每周出 一个总结(消费总结) 等等 每月可以再做一个月总结 (当然 你也可以实现 查询每个月里哪次消费高,哪次消费低) 最好 还包括 用户权限的限制 就是 这个系统可以适合多数人用的

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧