




已阅读5页,还剩46页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验2 判断某年是否闰年using System;namespace GuoXue public class Write public static void Main() Console.WriteLine(请输入年份:); int year=int.Parse(Console.ReadLine(); if(year%4=0|year%100=0&year%400=0) Console.WriteLine(0是闰年。,year); else Console.WriteLine(0不是闰年。,year); 实验3 日期描述定义一个表示日期的结构类型(包含年、月、日字段和输出该日期的方法),声明一个该类型的变量,提示输入年、月、日的值,然后调用输出方法在屏幕上输出该日期信息using System;namespace GuoXue public class Stu public static void Main() Console.WriteLine(请输入年月日:); Date a=new Date(); a.year=int.Parse(Console.ReadLine(); a.month=int.Parse(Console.ReadLine(); a.day=int.Parse(Console.ReadLine(); a.Dispaly(); public struct Date public int year; public int month; public int day; public void Dispaly() Console.WriteLine(0年1月2日,year,month,day); 2、编程将用户输入的一个三位正整数逆序输出。using System;namespace Guoxueclass A public static void Main() Console.WriteLine(请输入一整数:); Change a=newInt(int.Parse(Console.ReadLine(); class Int private int x; public Int(int m) x = m; change(m); public void change(int x) int m; while (x != 0) m = x % 10; x = x / 10; Console.WriteLine(m); 定义一个Circle(圆)结构,在结构中声明圆的半径字段radius和一个常量PI,并定义有两个方法分别计算矩形的周长和面积。using System;namespace Guoxue class Program static void Main(string args) Circle s=new Circle (3); Console.WriteLine(面积为:0,s.Area() ); Console.WriteLine(周长为:0,s.Len() ); public class Circle private double radius; const double PI = 3.14159; public Circle(double r) radius = r; public double Area() return PI*radius*radius; public double Len() return PI*radius*2; 1 求三个整数的最大值编写一个程序,使用条件运算符求用户输入的三个整数中的最大值。using System;namespace tex4_1 class Program static void Main(string args) Delect a=new Delect(); Console.WriteLine(请输入三个整数:); a.x=int.Parse (Console.ReadLine(); a.y=int.Parse (Console.ReadLine(); a.z=int.Parse (Console.ReadLine(); Console.WriteLine(三个数中最大的数是:0,a.Max (); public class Delect public int x, y, z; public int Max() x = (x y ? x : y); x = (x z ? x : z); return x; 编写一个程序,使用if语句将用户输入的三个整数按从小到大的顺序排序。using System;namespace tex4_2 class Program static void Main(string args) int x, y, z; Paixu a = new Paixu(); Console.WriteLine(请输入三个整数:); x=int.Parse(Console.ReadLine(); y=int.Parse(Console.ReadLine(); z=int.Parse(Console.ReadLine(); a.paixu(ref x, ref y, ref z); Console.WriteLine(三个整数从小到大排序:0,1,2,x,y,z); public class Paixu public void paixu(ref int x,ref int y,ref int z) int t; if (x y) t = x; x = y; y = t; if (x z) t = x; x = z; z = t; if (y z) t = y; y = z; z = t; 1 求指定范围内的所有素数using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace tex4_3 class Program static void Main(string args) Sushu a = new Sushu(); Console.WriteLine(请输入一个整数:); a.m=int.Parse(Console.ReadLine(); Console.WriteLine(素数有:); a.Delect(); public class Sushu public int m; public void Delect() int i, j; bool f; for (i = 2; i = m; i+) f = true; for (j = 2; j = i / 2; j+) if (i % j = 0) f = false; break; if (f) display(i); public void display(int n) int k = 0; Console.Write(0 ,n); k+; if (k % 10 = 0) Console.WriteLine(n); 2 求两个正整数的最大公约数和最小公倍数using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace text_4 class Program static void Main(string args) P a = new P(); Console.WriteLine(输入两个整数:); a.n=int.Parse(Console.ReadLine(); a.m=int.Parse(Console.ReadLine(); int b=P.De (a.m,a.n); a.display (b); public class P public int m, n; public static int De(int m,int n) int t; if (m y?x:y; 2 简单计算器using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace tex5_2 class Program static void Main(string args) int m, n; char s; Console.WriteLine(请输入相关运算:); m=int.Parse(Console.ReadLine(); s=char.Parse(Console.ReadLine(); n=int.Parse(Console.ReadLine(); switch (s) case+: Console.WriteLine( Runsuan.Jia(m,n); break; case-: Console.WriteLine(Runsuan.Jian(m,n); break; case*:Console.WriteLine(Runsuan.Cheng(m,n); break; default: Console.WriteLine(Runsuan.Chu(m,n); break; Console.WriteLine(); class Runsuan public static int Jia(int m, int n) return m + n; public static int Jian(int m, int n) return m - n; public static int Cheng(int m, int n) return m * n; public static int Chu(int m, int n) return m / n; 3 求N!的值用循环的方法求N!(N=0)。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace tex5_3 class Program static void Main(string args) Console.WriteLine(请输入一个大于等于0的整数:); Int n=int.Parse(Console.ReadLine(); Console.WriteLine(Jiecheng.Delecte(n); class Jiecheng public static int Delecte(int n) int s = 1; for (int i = 1; i 0.000001) return number1 / number2; return 0; 点和直线类实验using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace text6_shiyan_1 class Program static void Main(string args) Console.WriteLine(对坐标点进行初始化); Pointp=new Point(Program.Read(), Program.Read(); Console.WriteLine(坐标点为:(0,1),p.X ,p.Y); Console.WriteLine(输入水平距离和垂直距离移动坐标点); p.Move(Program.Read(),Program.Read(); Console.WriteLine(坐标点为:(0,1), p.X, p.Y); Console.WriteLine(输入斜率来创建直线对象:); Line l=new Line(Program.Read (); l.B =Program.Del (p.X ,p.Y,l.A ); Console.WriteLine(直线方程为:y=0x+1,l.A ,l.B ); Console.WriteLine(根据两个Point对象来构造直线对象); Point p1 = new Point(Program.Read() ,Program.Read(); Point p2 = new Point(Program.Read() ,Program.Read(); Line l1 = new Line(p1, p2); l.B = Program.Del(p1.X, p1.Y, l.A); Console.WriteLine(直线方程为:y=0x+1, l.A, l.B); Console.WriteLine(平移直线:); Console.WriteLine(请输入位移:); l.Move(Program.Read (); Console.WriteLine(直线方程为:y=0x+1,l.A ,l.B ); Console.WriteLine(判断某点是否在该直线上:); Console.WriteLine(请输入一个判断是否在直线上:); if (l.Contains(Program.Read(), Program.Read() Console.WriteLine(点在直线上。); else Console.WriteLine(点不再直线上。); public static double Read() return double.Parse(Console.ReadLine(); public static double Del(double x,double y,double a) /根据一个坐标点和斜率求出截距并返回; return y - a * x; public class Line /定义私有的斜率并对其进行封装 private double a; public double A get return a; set a = value; /定义私有的斜率并对其进行封装 private double b; public double B get return b; set b = value; /根据斜率来创建直线对象 public Line(double a) this.a = a; /根据两个Point对象来构造直线对象 public Line(Point P1, Point P2) this.a = (P2.Y - P1.Y) / (P2.X - P1.X); /平移直线 public void Move(double b) this.b += b; /判断某点是否在该直线上 public bool Contains(double x,double y) if (y = this.a * x + this.b) return true; return false; public class Point /定义私有的横坐标并对其进行封装 private double x; public double X get return x; set x = value; /定义私有的纵标并对其进行桂装 private double y; public double Y get return y; set y = value; /对字段x和y进行初始化 public Point(double x, double y) this.x = x; this.y = y; /按指定的水平距离和垂直距离移动坐标点 public void Move(double x, double y) this.x += x; this.y += y; 复数运算实验,重载可以实现的所有操作符。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace text6_kewai2class Programstatic void Main(string args)Comp c1 = new Comp(1,2);Comp c2 = new Comp(3,4);Comp c;c = c1 + c2;Console.WriteLine(c);c = c1 - c2;Console.WriteLine (c);c=c1*c2;Console.WriteLine (c);c=c1/c2;Console.WriteLine(c);class Comp/实部private double x;public double Xget return x; /虚部private double y;public double Yget return y; public Comp(double x, double y)this.x = x;this.y = y;public static Comp operator +(Comp c1, Comp c2)Comp c = new Comp(c1.x + c2.x,c1.y + c2.y);return c;public static Comp operator -(Comp c1, Comp c2)Comp c = new Comp(c1.x - c2.x,c1.y - c2.y);return c;public static Comp operator *(Comp c1, Comp c2)Comp c = new Comp(c1.x*c2.x+c1.y*c2.y,c1.x*c2.y+c1.y*c2.x);return c;public static Comp operator /(Comp c1, Comp c2)double a = c2.x * c2.x + c2.y * c2.y;double b = c1.x * c2.x + c1.y * c2.y;double d=-(c1.x*c2.y-c1.y*c2.x);Comp c = new Comp(b/a,d/a);return c;public override string ToString()StringBuilder str =new StringBuilder ();if (x != 0)str.Append(x);if (y != 0)if (str.Length != 0)str.Append(+);str.Append();str.Append(y);str.Append();str.Append(i);if (str.Length = 0)return 0;elsereturn str.ToString();复数运算实验,重载可以实现的所有操作符。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace text6_kewai2class Programstatic void Main(string args)Comp c1 = new Comp(1,2);Comp c2 = new Comp(3,4);Comp c;c = c1 + c2;Console.WriteLine(c);c = c1 - c2;Console.WriteLine (c);c=c1*c2;Console.WriteLine (c);c=c1/c2;Console.WriteLine(c);class Comp/实部private double x;public double Xget return x; /虚部private double y;public double Yget return y; public Comp(double x, double y)this.x = x;this.y = y;public static Comp operator +(Comp c1, Comp c2)Comp c = new Comp(c1.x + c2.x,c1.y + c2.y);return c;public static Comp operator -(Comp c1, Comp c2)Comp c = new Comp(c1.x - c2.x,c1.y - c2.y);return c;public static Comp operator *(Comp c1, Comp c2)Comp c = new Comp(c1.x*c2.x+c1.y*c2.y,c1.x*c2.y+c1.y*c2.x);return c;public static Comp operator /(Comp c1, Comp c2)double a = c2.x * c2.x + c2.y * c2.y;double b = c1.x * c2.x + c1.y * c2.y;double d=-(c1.x*c2.y-c1.y*c2.x);Comp c = new Comp(b/a,d/a);return c;public override string ToString()StringBuilder str =new StringBuilder ();if (x != 0)str.Append(x);if (y != 0)if (str.Length != 0)str.Append(+);str.Append();str.Append(y);str.Append();str.Append(i);if (str.Length = 0)return 0;elsereturn str.ToString();人民币类实验,重载可以重载的全部操作符。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace text6_kewai1 class Program static void Main(string args) RMB r1 = new RMB(1234); RMB r2 = new RMB(56,7,8); RMB r; Console.WriteLine(r1); Console.WriteLine(r2); r = r1 + r2; Console.WriteLine(r); r = r1 - r2; Console.WriteLine(r); r+; Console.WriteLine(r); r-; Console.WriteLine(r); public class RMB private uint yuan; public uint Yuan get return yuan; private uint jiao; public uint Jiao get return jiao; private uint fen; public uint Fen get return fen; set fen = value; public RMB(uint yuan, uint
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 江苏省泰州市靖江市2024-2025学年八年级下学期6月期末考试数学试卷(含答案)
- 《仓储服务合同》模板
- 在XX市守护青少年心理健康工作推进会上的讲话
- 已亥杂诗其5课件
- 巡护员安全岗前培训内容课件
- 岩石强度课件
- 屋面光伏安全培训内容课件
- 输液港的维护与护理
- 互联网医疗平台股权收购及合作协议书
- 城市综合体项目借款合同股权质押综合运营管理协议
- 2025标准合同范本:餐饮业劳动合同书
- 政府法律顾问聘用合同
- 部编人教版六年级上册道德与法治全册教案
- 2025年共青团入团考试测试题库及答案
- 第13章第2节 人体免疫课件-2025-2026学年北师大版八年级上册生物
- 2025上海科技馆招聘高层次专业技术人才3人备考考试试题及答案解析
- 线路维护材料管理办法
- 2025年外企面试英语常见问题与答案解析
- 2025年6月浙江省高考物理试卷真题(含答案解析)
- 民宿课程题目大全及答案
- 2025年银行内部审计部门财务审计员竞聘考试指南
评论
0/150
提交评论