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

2018-12-29 20:14

金陵科技学院实验报告

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


C#程序设计实验报告(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2017电大开放英语3unit6形考测试(2)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: