




已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验2-3 结果 55int i = 5, j = 5, p, q, s; p = (i+) + (i+) + (i+); q = (+j) + (+j) + (+j); int t = 0; s = i + t + j + t + p + t + q; Console.WriteLine(s);实验2-4 结果:False False int x, y; bool z1, z2; x = 1; y = 0; z1 = (x 1) & (+y 0); z2 = (x 1) & (+y 0); Console.WriteLine(0,1,z1,z2); 结果:8,8,10 int x = 10, y = 9, a, b, c; a = (-x = y+) ? -x : +y; b = x+; c = y; Console.WriteLine(0,1,2, a, b, c);实验3-1 编程:由键盘输入3个整数a,b,c,输出其中最小的数。 int a, b, c; Console.Write(输入三个整数:); a = Convert.ToInt32(Console.ReadLine(); b = Convert.ToInt32(Console.ReadLine(); c= Convert.ToInt32(Console.ReadLine(); if (a b & a c) Console.WriteLine(a); else if (b a & b = a & a = A & a = 0 & a = 0 & ch = a & ch = A & ch = Z) n2+; else if (ch = ) n3+; ch = (Char)Console.Read(); Console.WriteLine(数字: + n1 + 字母: + n2 + 空格: + n3);实验4-4 编写一程序求出所有的水仙花数。水仙花数是指一个3位数,其各位数字的立方和恰好等于该数本身。例如,153=1*1*1+5*5*5+3*3*3,所以153是水仙花数。 int i, a,b,c,sum; for (i = 100; i 1000; i+) a = i / 100; b = (i - a * 100) / 10; c = i % 10; sum = a * a * a + b * b * b + c * c * c; if (i = sum) Console.WriteLine(水仙花数是:0, i); 实验5-4 设计一个windows应用程序,界面如下图所示,连续输入一串数字,然后进行从小到大排序。 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) string str = textBox1.Text; string strs = str.Split(,); int a = new int10; for (int i = 0; i strs.Length; i+) ai = Convert.ToInt32(strsi); Array.Sort(a); for (int i = 0; i 9; i+) label3.Text = label3.Text + ai + ,; label3.Text = label3.Text + a9; 实验6-2 有一3*3 矩阵,求出两条对角线元素值之和;int, score; int i, j, sum; score = new int3, 3; for (i = 0; i 3; i+) for (j = 0; j 3; j+) scorei, j = int.Parse(Console.ReadLine(); for (i = 0; i 3; i+) for (j = 0; j 3; j+) Console.Write(0,4:d, scorei, j); Console.WriteLine(); sum = score0, 0 + score1, 1 + score2, 2 + score2, 0 + score0, 2; Console.WriteLine(对角线元素之和为0, sum); Console.Read();实验7-1 在c#中编写一个控制台应用程序,要求实现以下功能:设计一个Retangle类,提供通过length和width字段计算面积和周长的两个方法,并用 main方法来测试程序。Retangl r = new Retangl(4, 5); Console.WriteLine(周长为: + r.getL(); Console.WriteLine(面积为: + r.getS(); class Retangl double s, l; public Retangl(double w, double h) s = w * h; l = 2 * (w + h); public double getL() return l; public double getS() return s; P256 第二题class Program static void Main(string args) int sn, x, ss; double cc, yc, sc; string name; Console.WriteLine(请输入有几个学生); sn = Convert.ToInt32(Console.ReadLine(); Student a = new Studentsn; for (int i = 0; i sn; i+) Console.WriteLine(请输入学生姓名:); name = Convert.ToString(Console.ReadLine(); Console.WriteLine(请输入学生学号:); x = Convert.ToInt32(Console.ReadLine(); Console.WriteLine(请输入学生C+成绩:); cc = Convert.ToDouble(Console.ReadLine(); Console.WriteLine(请输入学生英语成绩:); yc = Convert.ToDouble(Console.ReadLine(); Console.WriteLine(请输入学生数学成绩:); sc = Convert.ToDouble(Console.ReadLine(); Student s = new Student(name, x, cc, yc, sc); ai = s; for (int j = 0; j sn; j+) Console.WriteLine(aj); for (int j = 0; j sn; j+) Console.WriteLine(aj.toString(); Student temp ; for (int i = 0; i sn - 1; i+) for (int j = 0; j aj + 1.getArrage() temp = aj; aj = aj + 1; aj + 1 = temp; for (int j = 0; j sn; j+) Console.WriteLine(aj.toString2(); P256 第五题class Program static void Main(string args) CPerson cp = new CPerson(aaa,101,m); CStudent cs = new CStudent(bbb, 102, f, 98); CTeacher ct = new CTeacher(ccc, 103, f, 54); Console.WriteLine(cp); Console.WriteLine(cs); Console.WriteLine(ct); Console.ReadKey(); class CPerson public string name,sex; public int num; public CPerson(string name, int num, string sex) = name; this.num = num; this.sex = sex; public override string ToString() return 姓名: + name + 编号: + num + 性别 + sex; class CStudent : CPerson public float gread; public CStudent(string name, int num, string sex,float gread): base(name, num, sex) this.gread = gread; public override string ToString() return base.ToString()+ 成绩:+gread; class CTeacher : CPerson public int age; public CTeacher(string name, int num, string sex,int age) : base(name, num, sex) this.age = age; public override string ToString() return base.ToString() + 年龄: + age ; 设计一个windows应用程序,在该程序中定义一个学生类和班级类,以处理每个学生的学号、姓名、计算机的期末考试成绩,要求:(1)能显示计算机成绩最高分的学生名单;(2)能统计全班学生计算机的平均成绩;其中学生类名为Student,包含字段(学号,姓名,计算机成绩);班级类名为StudentList,包含一个Student类型的数组(用来保存全班学生的信息)以及若干个实现上述要求的方法等;用户操作界面设计:首先让用户能输入一个学生的信息,当单击“添加”按钮时把这些信息添加到班级对象的学生数组中。当单击“完成”按钮时调用班级类的方法来显示所要求统计的统计结果。对象名属性名属性值TextBox1TextnullTextBox2TextnullTextBox3Textnullbutton1Text添加Button2Text完成StudentList类:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace WindowsFormsApplication3 class StudentList public Student a = new Student3; public StudentList() for (int i = 0; i a.Length; i+) ai = new Student(); public string f3(int m) float t = a0.Computer; string max = a0.Name; for (int i = 0; i m - 1; i+) if (ai.Computer ai + 1.Computer) t = ai + 1.Computer; max = ai + 1.Name; return max; public float f9(int m) float t = 0; for (int i = 0; i m; i+) t += ai.Computer; return (t / m); 学生类:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace WindowsFormsApplication3 class Student private int id; private string name; private float computer; public int ID get return id; set id = value; public string Name get return name; set name = value; public float Computer get return computer; set if (value 100) computer = 0; else computer= value; Form1:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace WindowsFormsApplication3 public partial class Form1 : Form publi
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 键盘的使用课件
- 土建现场安全培训
- 小学语文《太阳》教学课件设计
- 少儿拼音班课件
- 钓鱼分类游戏课件
- 广东河北自考试题及答案
- 广东广东美学自考试题及答案
- 冷库考试题及答案大全
- 烤灯考试题及答案
- 抗震减灾考试题及答案
- 陕旅版小学六年级上册全册英语教案
- 海洋工程装备概述
- 第5章 相交线与平行线 复习课件
- 幼儿园玩具售后服务承诺及保证措施方案
- 2025年江苏省高考招生统一考试高考真题物理试卷(真题+答案)
- CJ/T 191-2004板式换热机组
- 《智能机电系统设计与开发》课件 第三章-机械系统设计与开发
- 食品卫生考试试题及答案
- T/CECS 10187-2022无机复合聚苯不燃保温板
- 睾丸常见肿瘤超声诊断要点
- 重症医学科肺康复综合体系建设
评论
0/150
提交评论