77范文网 - 专业文章范例文档资料分享平台

C#程序设计实验报告(3)

来源:网络收集 时间:2018-12-29 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

金陵科技学院实验报告

Console.WriteLine(s.Swap(a, b)); Console.WriteLine(s.Swap(ref a,ref b)); }

class Swaper {

public string Swap(int x, int y) {

int temp; temp = x; x = y; y = temp; return 后:x={0},y={1}\

}

public string Swap(ref int x, ref int y) {

int temp; temp = x; x = y; y = temp;

return string.Format(\按引用传参交换之后:x={0},y={1}\x, y);

} } }

}2、定义一个方法,实现数组的排序。 using System;

using System.Collections.Generic; using System.Text;

namespace second.two {

class Program {

string.Format(\

9

金陵科技学院实验报告

public class sort {

public void change(int[] a) {

Console.WriteLine(\排序前,数组顺序为:\ show(a); int i, j, m;

for (i = 0; i < 10; i++) {

m = a[i];

j = i - 1; //a[j]为数组前一个值

while (j >= 0 && m > a[j])//判断i下标的数是否大于j下标的数

{

a[j + 1] = a[j];//如果i下标大于j把j往后移一个位

j--; }

a[j+1] = m; //当不大于j的时候就把M的值放到i下标下面 j+1 是为了下标减到最前时考虑 -1 + 1 还是下标的最前面

}

Console.WriteLine(\排序后,数组顺序为:\ show(a); }

void show(int[] a) { int i;

for (i = 0; i < 10; i++) {

Console.Write(\ }

Console.WriteLine(); } }

10

金陵科技学院实验报告

static void Main(string[] args) {

int[] a ={ 4, 7, 1, 2, 5, 8, 9, 10, 3, 6 }; sort s=new sort(); s.change(a); } } }

3、定义一个学生类,把学生类当作对象来传递。

using System;

using System.Collections.Generic; using System.Linq; using System.Text;

namespace second.three {

class Program {

public class student {

public void st() {

int a = 999; } }

public class st {

public void aa(student s) {

Console.WriteLine(s); } }

static void Main(string[] args) {

11

金陵科技学院实验报告

student s=new student(); st s1 = new st(); s1.aa(s);

} } }

4、定义一个方法,求两个数的和和差,通过参数把这两个值带回。

using System;

using System.Collections.Generic; using System.Linq; using System.Text;

namespace second.four {

class Program {

public class sum {

public void ab(out int m, out int n,int a, int b) {

m = a + b; n = a - b; } }

static void Main(string[] args) {

sum s = new sum(); int a = 10; int b = 3; int m, n;

s.ab(out m, out n, a, b);

Console.WriteLine(\

12

金陵科技学院实验报告

} } }

5、用构造函数重载,实现矩形的面积,圆的面积,梯形的面积;

using System;

using System.Collections.Generic; using System.Linq; using System.Text;

namespace secong.five {

class Program {

public class square {

public double area; public square() { } public square(double a) {

area = a * a * 3.14; }

public square(double a, double b) {

area = a * b; }

public square(double a, double b, double h) {

area = (a + b) / 2 * h; } }

static void Main(string[] args) {

double a, b, h,area; a = 2; b = 5; h = 3;

13

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库C#程序设计实验报告(3)在线全文阅读。

C#程序设计实验报告(3).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/397728.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: