第一篇:C#程序設(shè)計(jì)實(shí)驗(yàn)報(bào)告
實(shí)驗(yàn)報(bào)告書寫要求
實(shí)驗(yàn)報(bào)告原則上要求學(xué)生手寫,要求書寫工整。若因課程特點(diǎn)需打印的,標(biāo)題采用四號(hào)黑體,正文采用小四號(hào)宋體,單倍行距。紙張一律采用A4的紙張。
實(shí)驗(yàn)報(bào)告書寫說明
實(shí)驗(yàn)報(bào)告中實(shí)驗(yàn)?zāi)康暮鸵?、?shí)驗(yàn)儀器和設(shè)備、實(shí)驗(yàn)內(nèi)容與過程、實(shí)驗(yàn)結(jié)果與分析這四項(xiàng)內(nèi)容為必需項(xiàng)。教師可根據(jù)學(xué)科特點(diǎn)和實(shí)驗(yàn)具體要求增加項(xiàng)目。
填寫注意事項(xiàng)
(1)細(xì)致觀察,及時(shí)、準(zhǔn)確、如實(shí)記錄。(2)準(zhǔn)確說明,層次清晰。
(3)盡量采用專用術(shù)語來說明事物。
(4)外文、符號(hào)、公式要準(zhǔn)確,應(yīng)使用統(tǒng)一規(guī)定的名詞和符號(hào)。(5)應(yīng)獨(dú)立完成實(shí)驗(yàn)報(bào)告的書寫,嚴(yán)禁抄襲、復(fù)印,一經(jīng)發(fā)現(xiàn),以零分論處。
實(shí)驗(yàn)報(bào)告批改說明
實(shí)驗(yàn)報(bào)告的批改要及時(shí)、認(rèn)真、仔細(xì),一律用紅色筆批改。實(shí)驗(yàn)報(bào)告的批改成績(jī)采用五級(jí)記分制或百分制,按《金陵科技學(xué)院課堂教學(xué)實(shí)施細(xì)則》中作業(yè)批閱成績(jī)?cè)u(píng)定要求執(zhí)行。
實(shí)驗(yàn)報(bào)告裝訂要求
實(shí)驗(yàn)批改完畢后,任課老師將每門課程的每個(gè)實(shí)驗(yàn)項(xiàng)目的實(shí)驗(yàn)報(bào)告以自然班為單位、按學(xué)號(hào)升序排列,裝訂成冊(cè),并附上一份該門課程的實(shí)驗(yàn)大綱。
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
實(shí)驗(yàn)項(xiàng)目名稱: C#基礎(chǔ)編程 實(shí)驗(yàn)學(xué)時(shí): 6 同組學(xué)生姓名: 實(shí)驗(yàn)地點(diǎn): 1318 實(shí)驗(yàn)日期: 10月5日-10月19日 實(shí)驗(yàn)成績(jī): 批改教師: 批改時(shí)間:
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
實(shí)驗(yàn)1 C#基礎(chǔ)編程
一、實(shí)驗(yàn)?zāi)康?/p>
1、熟悉Visual Studio.NET開發(fā)環(huán)境。
2、掌握C#應(yīng)用程序的基本操作過程。
3、掌握C#的數(shù)據(jù)類型,運(yùn)算符以及表達(dá)式的使用。
4、掌握分支和循環(huán)語句的使用方法。
5、掌握一維數(shù)組,二維數(shù)組及數(shù)組型數(shù)組的使用。
二、實(shí)驗(yàn)要求
(1)編寫程序要規(guī)范、正確,上機(jī)調(diào)試過程和結(jié)果要有記錄(2)做完實(shí)驗(yàn)后給出本實(shí)驗(yàn)的實(shí)驗(yàn)報(bào)告。
三、實(shí)驗(yàn)設(shè)備、環(huán)境
安裝有Visual Studio.NET軟件。
四、實(shí)驗(yàn)步驟
1、分析題意。
2、根據(jù)題目要求,新建項(xiàng)目。
3、編寫并輸入相關(guān)的程序代碼。
5、運(yùn)行與調(diào)試項(xiàng)目。
6、保存項(xiàng)目。
五、實(shí)驗(yàn)內(nèi)容
1、編寫一個(gè)簡(jiǎn)單的控制臺(tái)應(yīng)用程序,打印一行文字(如你的姓名)。
using System;using System.Collections.Generic;using System.Linq;using System.Text;
namespace one.first {
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine(“我叫王蕾!”);
}
} }
2、編寫一個(gè)簡(jiǎn)單的Windows應(yīng)用程序,在窗體Load事件中書寫代碼,標(biāo)簽中顯示你的姓名。
using System;using System.Collections.Generic;using System.ComponentModel;
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;
namespace one.second {
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = “Windows 程序”;
Label lblShow = new Label();
lblShow.Location = new Point(20, 30);
lblShow.AutoSize = true;
lblShow.Text = “王蕾!”;
this.Controls.Add(lblShow);
}
} }
3、編寫一個(gè)一個(gè)程序,用來判斷輸入的是大寫字母,小寫字母,數(shù)字還是其他的字符。
using System;using System.Collections.Generic;using System.Text;
namespace one.third {
class Program
{
static void Main(string[] args)
{
Console.WriteLine(“請(qǐng)輸入一個(gè)字符:”);
char c = Convert.ToChar(Console.ReadLine());
if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
Console.WriteLine(“這是一個(gè)字母”);
if(char.IsDigit(c))
Console.WriteLine(“這是一個(gè)數(shù)字”);
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
}
} }
4、分別用while,do-while,for循環(huán)求1到100的和。
using System;using System.Collections.Generic;using System.Text;
namespace one.forth.one {
class Program
{
static void Main(string[] args)
{
int i = 1, sum = 0;
while(i <= 100)
{
sum = sum + i;
i++;
}
Console.WriteLine(“1到100的自然數(shù)之和為:” + sum);
}
} } using System;using System.Collections.Generic;using System.Text;
namespace one.forth.two {
class Program
{
static void Main(string[] args)
{
int i = 1, sum = 0;
do
{
sum = sum + i;
i++;
}
while(i <= 100);
Console.WriteLine(“1到100的自然數(shù)的和為:” + sum);
}
}
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
} using System;using System.Collections.Generic;using System.Text;
namespace one.forth.three {
class Program
{
static void Main(string[] args)
{
int i , sum = 0;
for(i = 1;i <= 100;i++)
{
sum = sum + i;
}
Console.WriteLine(“1到100的自然數(shù)的和為:” + sum);
}
} }
5、定義一個(gè)一維數(shù)組,用隨機(jī)數(shù)為此賦值,用foreach循環(huán)輸出其中的內(nèi)容。
using System;using System.Collections.Generic;using System.Linq;using System.Text;
namespace first.five {
class Program
{
static void Main(string[] args)
{
int[] a = {0,1,2,3,4};
foreach(int i in a)
{
Console.WriteLine(a[i]);
}
}
} }
6、實(shí)現(xiàn)二維數(shù)組的輸入和輸出。
using System;using System.Collections.Generic;using System.Linq;
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
using System.Text;
namespace first.six {
class Program
{
static void Main(string[] args)
{
int[,] a = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } };
{
for(int i = 0;i < 2;i++)
{
for(int j = 0;j < 3;j++)
{ Console.WriteLine(a[i, j]);}
}
}
}
} }
7、實(shí)現(xiàn)數(shù)組型數(shù)組的輸入和輸出。
using System;using System.Collections.Generic;using System.Linq;using System.Text;
namespace first.seven {
class Program
{
static void Main(string[] args)
{
int[][] a = new int[][] { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 } };
for(int i = 0;i < a.Length;i++)
{
for(int j = 0;j < a[i].Length;j++)
{
Console.WriteLine(a[i][j]);
}
}
}
} }
六、實(shí)驗(yàn)體會(huì)(遇到問題及解決辦法,編程后的心得體會(huì))
剛開始編程的時(shí)候覺得無從下手,盡管我們已經(jīng)學(xué)了好幾種高級(jí)編程語言,但每個(gè)都
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
有其獨(dú)特的地方,稍不留神就會(huì)混淆。
通過這次實(shí)驗(yàn),我體會(huì)到課后復(fù)習(xí)鞏固的重要性。在編程的時(shí)候,很多內(nèi)容都不記得,需要去翻書。不得不說,實(shí)驗(yàn)是鞏固課程的好方法!本次實(shí)驗(yàn),我熟悉Visual Studio.NET開發(fā)環(huán)境;掌握了C#應(yīng)用程序的基本操作過程;掌握了C#的數(shù)據(jù)類型,運(yùn)算符以及表達(dá)式的使用;掌握了分支和循環(huán)語句的使用方法以及一維數(shù)組,二維數(shù)組及數(shù)組型數(shù)組的使用。
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
實(shí)驗(yàn)項(xiàng)目名稱: 類與對(duì)象 實(shí)驗(yàn)學(xué)時(shí): 6 同組學(xué)生姓名: 實(shí)驗(yàn)地點(diǎn): 1318 實(shí)驗(yàn)日期: 10月26日-11月9日 實(shí)驗(yàn)成績(jī): 批改教師: 批改時(shí)間:
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
實(shí)驗(yàn)2 類與對(duì)象
一、實(shí)驗(yàn)?zāi)康?、要?/p>
(1)掌握類的定義和使用;
(2)掌握類的數(shù)據(jù)成員,屬性的定義和使用;
(3)掌握方法的定義,調(diào)用和重載以及方法參數(shù)的傳遞;(4)掌握構(gòu)造函數(shù)的定義和使用。
二、實(shí)驗(yàn)要求
(1)編寫程序要規(guī)范、正確,上機(jī)調(diào)試過程和結(jié)果要有記錄;(2)做完實(shí)驗(yàn)后給出本實(shí)驗(yàn)的實(shí)驗(yàn)報(bào)告。
三、實(shí)驗(yàn)設(shè)備、環(huán)境
安裝有Visual Studio.NET軟件。
四、實(shí)驗(yàn)步驟
1、分析題意;
2、根據(jù)題目要求,新建項(xiàng)目;
3、編寫并輸入相關(guān)的程序代碼;
5、運(yùn)行與調(diào)試項(xiàng)目;
6、保存項(xiàng)目。
五、實(shí)驗(yàn)內(nèi)容
1、定義一個(gè)方法,實(shí)現(xiàn)兩個(gè)數(shù)的交換(分別把參數(shù)按值傳遞和按引用傳遞)。
using System;using System.Collections.Generic;using System.Text;
namespace second.one {
class Program
{
static void Main(string[] args)
{
Swaper s = new Swaper();
Console.WriteLine(“輸入x的值:”);
int a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(“輸入y的值:”);
int b=Convert.ToInt32(Console.ReadLine());
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
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}“,x,y);
}
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、定義一個(gè)方法,實(shí)現(xiàn)數(shù)組的排序。using System;using System.Collections.Generic;using System.Text;
namespace second.two {
class Program
{
string.Format(”
按
值
傳
參
交
換
之
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
public class sort
{
public void change(int[] a)
{
Console.WriteLine(“排序前,數(shù)組順序?yàn)椋骸?;
show(a);
int i, j, m;
for(i = 0;i < 10;i++)
{
m = a[i];
j = ib;
}
}
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(“{0}+{1}={2};{0}-{1}={3}”,a,b,m,n);
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
}
} }
5、用構(gòu)造函數(shù)重載,實(shí)現(xiàn)矩形的面積,圓的面積,梯形的面積;
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;
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
square s = new square(a,b);
Console.WriteLine(“求矩形面積,長(zhǎng)為a={0},寬為b={1},面積area={2}”,a,b,s.area);
square i = new square(a);
Console.WriteLine(“求圓形面積,半徑a={0},面積area={1}”, a, i.area);
square j = new square(a, b, h);
Console.WriteLine(“求梯形面積,上底為a={0},下底為b={1},高為h={2}面積area={3}”, a, b,h, j.area);
}
} }
6、設(shè)計(jì)一個(gè)windows應(yīng)用程序,在該程序中定義一個(gè)學(xué)生類和班級(jí)類,以處理每個(gè)學(xué)生的學(xué)號(hào),姓名,語文,數(shù)學(xué)和英語成績(jī),要求:
1)能查詢每個(gè)學(xué)生的總成績(jī)。2)能顯示全班前三名的名單。
3)能顯示單科成績(jī)最高分和不及格的學(xué)生名單。4)能統(tǒng)計(jì)全班學(xué)生的平均成績(jī)。
5)能顯示各科成績(jī)不同分?jǐn)?shù)段的學(xué)生人數(shù)的百分比。
Student類: using System;using System.Collections.Generic;using System.Text;namespace Test2_6 {
public class Student
{
public string stuNo;
public string name;
public double chinese;
public double math;
public double english;
public double sumScore
{
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
get { return chinese + math + english;}
}
} } StudentList類: using System;using System.Collections.Generic;using System.Text;namespace Test2_6 {
public class StudentList:Student
{
int snums;
public Student[] stu=new Student[50];
public StudentList()
{
snums = 0;
}
public void addstu(Student s)
{
stu[snums] = s;
snums++;
}
public int searchstu(string name)
{
int i;
for(i = 0;i < snums;i++)
{
if(stu[i].name == name)break;
}
if(i == snums)return-1;
else return i;
}
//給所有成績(jī)排序,用后面實(shí)現(xiàn)前三名的排名
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
public void ProThree()
{
for(int i = 0;i < snums;i++)
{
int k = i;
for(int j = i + 1;j < snums;j++)
if(stu[j].sumScore > stu[k].sumScore)k = j;
if(k!= i)
{
Student temp;
temp = stu[k];
stu[k] = stu[i];
stu[i] = temp;
}
}
}
//顯示單科成績(jī)的最高分
public int HighScore(int k)
{
int p = 0;
if(k == 0)
{
for(int i = 1;i < snums;i++)
if(stu[i].math > stu[p].math)p = i;
}
else if(k == 1)
{
for(int i = 1;i < snums;i++)
if(stu[i].chinese > stu[p].chinese)p = i;
}
else
{
for(int i = 1;i < snums;i++)
if(stu[i].chinese > stu[p].chinese)p = i;
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
}
return p;
}
//顯示不及格名單
public string BuhgName(int k)
{
string name=“ ”;
if(k == 0)
{
for(int i = 0;i < snums;i++)
if(stu[i].math < 60)name +=stu[i].name+“n”;
}
else if(k == 1)
{
for(int i = 0;i < snums;i++)
if(stu[i].chinese < 60)name += stu[i].name + “n”;
}
else
{
for(int i = 0;i < snums;i++)
if(stu[i].english < 60)name += stu[i].name + “n”;
}
return name;
}
public string getHL()
{
string Maxer = “ ”, Loser = “ ”;
Maxer += “單科數(shù)學(xué)最高:” + stu[HighScore(0)].name + “n”;
Maxer += “ 單科語文最高:” + stu[HighScore(1)].name + “n”;
Maxer += “ 單科英語最高:” + stu[HighScore(2)].name + “n”;
Loser += “單科數(shù)學(xué)掛科名單:” +BuhgName(0)+ “n”;
Loser += “單科語文掛科名單:” + BuhgName(1)+ “n”;
Loser += “單科英語掛科名單:” + BuhgName(2)+ “n”;
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
return Maxer + “n” + Loser;
}
//全班的平均成績(jī)
public string SumScore()
{
double sum = 0;
double avg=0;
for(int i = 0;i < snums;i++)
{
sum = sum + stu[i].sumScore;
}
avg = sum / snums;
return “班級(jí)總分平均分:”+avg;
}
//各科成績(jī)不同分?jǐn)?shù)段的學(xué)生百分比
//英語成績(jī)各分?jǐn)?shù)段百分比
public string PerC()
{
double per1, per2, per3, per4, per5;
double sumC1 = 0, sumC2 = 0, sumC3 = 0, sumC4 = 0, sumC5 = 0;
for(int i = 0;i < snums;i++)
{
if((stu[i].chinese > 90)&&(stu[i].chinese <= 100))
{
sumC1++;
}
else if((80 <= stu[i].chinese)&&(stu[i].chinese < 90))
{
sumC2++;
}
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
else if((70<=stu[i].chinese)&&(stu[i].chinese < 80))
{
sumC3++;
}
else if((60<=stu[i].chinese)&&(stu[i].chinese < 70))
{
sumC4++;
}
else
{sumC5++;}
}
per1 = sumC1 / snums;
per2 = sumC2 / snums;
per3 = sumC3 / snums;
per4 = sumC4 / snums;
per5 = sumC5 / snums;
return “語文成績(jī)百分比:”+“n”+“90~100:”+per1+“ 80~90:”+per2+“ 80~70:”+per3+“ 70~60:”+per4+“ 60以下的:”+per5;
}
//數(shù)學(xué)成績(jī)各分?jǐn)?shù)段百分比
public string PerM()
{
double per1, per2, per3, per4, per5;
double sumC1 = 0, sumC2 = 0, sumC3 = 0, sumC4 = 0, sumC5 = 0;
for(int i = 0;i < snums;i++)
{
if((stu[i].math> 90)&&(stu[i].math <= 100))
{
sumC1++;
}
else if((80 <= stu[i].math)&&(stu[i].math < 90))
{
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
sumC2++;
}
else if((70 <= stu[i].math)&&(stu[i].math < 80))
{
sumC3++;
}
else if((60 <= stu[i].math)&&(stu[i].math < 70))
{
sumC4++;
}
else
{ sumC5++;}
}
per1 = sumC1 / snums;
per2 = sumC2 / snums;
per3 = sumC3 / snums;
per4 = sumC4 / snums;
per5 = sumC5 / snums;
return string.Format(“數(shù)學(xué)成績(jī)百分比:” + “n” + “90~100:” + per1 + “ 80~90:” + per2 + “ 80~70:” + per3 + “ 70~60:” + per4 + “ 60以下的:” + per5);
}
//英語成績(jī)各分?jǐn)?shù)段百分比
public string PerE()
{
double per1, per2, per3, per4, per5;
double sumC1 = 0, sumC2 = 0, sumC3 = 0, sumC4 = 0, sumC5 = 0;
for(int i = 0;i < snums;i++)
{
if((stu[i].english > 90)&&(stu[i].english <= 100))
{
sumC1++;
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
}
else if((80 <= stu[i].english)&&(stu[i].english < 90))
{
sumC2++;
}
else if((70 <= stu[i].english)&&(stu[i].english < 80))
{
sumC3++;
}
else if((60 <= stu[i].english)&&(stu[i].english < 70))
{
sumC4++;
}
else
{ sumC5++;}
}
per1 = sumC1 / snums;
per2 = sumC2 / snums;
per3 = sumC3 / snums;
per4 = sumC4 / snums;
per5 = sumC5 / snums;
return string.Format(“數(shù)學(xué)成績(jī)百分比:” + “n” + “90~100:” + per1 + “ 80~90:” + per2 + “ 80~70:” + per3 + “ 70~60:” + per4 + “ 60以下的:” + per5);
}
} } From窗體代碼: using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
using System.Windows.Forms;namespace Test2_6 {
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public StudentList sl = new StudentList();
private void btnAdd_Click(object sender, EventArgs e)
{
Student s = new Student();
s.stuNo = txtStuNo.Text;
s.name = txtName.Text;
s.chinese = Convert.ToDouble(txtChina.Text);
s.math = Convert.ToDouble(txtMath.Text);
s.english = Convert.ToDouble(txtEng.Text);
sl.addstu(s);
MessageBox.Show(“添加成功”);
}
private void btnSearch_Click(object sender, EventArgs e)
{
int pos = sl.searchstu(this.textBox1.Text);
if(pos!=-1)
{
label7.Text = this.textBox1.Text + “的總成績(jī):sl.stu[pos].sumScore;
}
else { MessageBox.Show(”不存在這個(gè)人!“);}
}
private void btnFinish_Click(object sender, EventArgs e)
{
label7.Text = ”前3名:“+”n“;
” + 金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
for(int i = 0;i < 3;i++)
{
sl.ProThree();
label7.Text+= sl.stu[i].name+“n”;
}
label7.Text += sl.getHL()+“n”;
label7.Text += Convert.ToString(sl.SumScore())+“n”;
label7.Text += sl.PerC()+“n”;
label7.Text += sl.PerM()+“n”;
label7.Text += sl.PerE()+“n”;
}
} }
六、實(shí)驗(yàn)體會(huì)(遇到問題及解決辦法,編程后的心得體會(huì))
通過本次實(shí)驗(yàn),我掌握了類的定義與使用;掌握了類的數(shù)據(jù)成員,屬性的定義和使用;掌握了方法的定義,調(diào)用和重載以及方法參數(shù)的傳遞以及構(gòu)造函數(shù)的定義和使用。值得注意的是:本次實(shí)驗(yàn)中return的使用以及所在的位置,類型轉(zhuǎn)換時(shí)也經(jīng)常用到
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
實(shí)驗(yàn)項(xiàng)目名稱: 繼承與多態(tài) 實(shí)驗(yàn)學(xué)時(shí): 6 同組學(xué)生姓名: 實(shí)驗(yàn)地點(diǎn): 1318 實(shí)驗(yàn)日期: 11月16日-11月30日 實(shí)驗(yàn)成績(jī): 批改教師: 批改時(shí)間:
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
實(shí)驗(yàn)3 繼承與多態(tài)
一、實(shí)驗(yàn)?zāi)康?、要?/p>
(1)掌握類的繼承性與多態(tài)性;
(2)掌握虛方法的定義以及如何使用虛方法實(shí)現(xiàn)多態(tài);(3)掌握抽象類的定義以及如何使用抽象方法實(shí)現(xiàn)多態(tài);
二、實(shí)驗(yàn)要求
(1)編寫程序要規(guī)范、正確,上機(jī)調(diào)試過程和結(jié)果要有記錄;(2)做完實(shí)驗(yàn)后給出本實(shí)驗(yàn)的實(shí)驗(yàn)報(bào)告。
三、實(shí)驗(yàn)設(shè)備、環(huán)境
安裝有Visual Studio.NET軟件。
四、實(shí)驗(yàn)步驟
1、分析題意;
2、根據(jù)題目要求,新建項(xiàng)目;
3、編寫并輸入相關(guān)的程序代碼;
5、運(yùn)行與調(diào)試項(xiàng)目;
6、保存項(xiàng)目。
五、實(shí)驗(yàn)內(nèi)容
1、設(shè)計(jì)一個(gè)Windows應(yīng)用程序,在該程序中首先構(gòu)造一個(gè)學(xué)生基本類,再分別構(gòu)造小學(xué)生、中學(xué)生、大學(xué)生派生類,當(dāng)輸入相關(guān)數(shù)據(jù),單擊不用的按鈕時(shí),將分別創(chuàng)建不同的學(xué)生類對(duì)象,并輸出當(dāng)前學(xué)生的總?cè)藬?shù),該學(xué)生的姓名,學(xué)生類型,平均成績(jī)。
Student類: using System;using System.Collections.Generic;using System.Text;namespace Test3_1 {
public abstract class Student
{
protected string name;
protected int age;
public static int number;
public Student(string name, int age)
{
this.name = name;
this.age = age;
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
number++;
}
public string Name
{
get { return name;}
}
public abstract double Average();
}
public class Pupil : Student
{
protected double chinese;
protected double math;
public Pupil(string name, int age, double chinese, double math)
: base(name, age)
{
this.chinese = chinese;
this.math = math;
}
public override double Average()
{
return(chinese + math)/ 2;
}
}
public class Middle : Student
{
protected double chinese;
protected double math;
protected double english;
public Middle(string name, int age, double chinese, double math, double english)
: base(name, age)
{
this.chinese = chinese;
this.math = math;
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
this.english = english;
}
public override double Average()
{
return(chinese + math + english)/ 3;
}
}
public class College : Student
{
protected double required;
protected double elective;
public College(string name, int age, double required, double elective)
: base(name, age)
{
this.required = required;
this.elective = elective;
}
public override double Average()
{
return(required + elective)/ 2;
}
} } Form窗體內(nèi)的代碼:
using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace Test3_1 {
public partial class Form1 : Form
{
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
public Form1()
{
InitializeComponent();
}
private void btnSmall_Click(object sender, EventArgs e)
{
Pupil),Convert.ToDouble(txtMath.Text));
lblShow.Text += “總?cè)藬?shù):” +Convert.ToString(Student.number)+ “,” + “姓名:” + p.Name + “,” + “小學(xué)生” + “,” + “平均成績(jī)?yōu)椋骸?+ p.Average()+“n”;
}
private void btnMiddle_Click(object sender, EventArgs e)
{
Middle Convert.ToInt32(txtAge.Text),m
=
new
Middle(txtName.Text,Convert.ToDouble(txtChinese.Text), p
=
new Pupil(txtName.Text,Convert.ToInt32(txtAge.Text),Convert.ToDouble(txtChinese.TextConvert.ToDouble(txtMath.Text),Convert.ToDouble(TxtEnglish.Text));
lblShow.Text += “總?cè)藬?shù):” + Convert.ToString(Student.number)+ “,” + “姓名:” + m.Name + “,” + “中學(xué)生” + “,” + “平均成績(jī)?yōu)椋骸?+ m.Average()+ “n”;
}
private void btnBig_Click(object sender, EventArgs e)
{
College Convert.ToInt32(txtAge.Text), Convert.ToDouble(txtMath.Text));
lblShow.Text += “總?cè)藬?shù):” + Convert.ToString(Student.number)+ “,” + “姓名:” + c.Name + “,” + “大學(xué)生” + “,” + “平均成績(jī)?yōu)椋骸?+ c.Average()+ “n”;
}
}
c
=
new
College(txtName.Text,Convert.ToDouble(txtChinese.Text),金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
}
2、設(shè)計(jì)一個(gè)Windows應(yīng)用程序,在該程序中定義平面圖形抽象類和派生類圓,矩形和三角形。
Figure類代碼: using System;using System.Collections.Generic;using System.Text;namespace Test3_2 {
public abstract class Figure
{
public abstract double Area();
}
public class Circle:Figure
{
double radius;
public Circle(double r)
{
radius = r;
}
public override double Area()
{
return radius * radius * 3.14;
}
}
public class JUxing:Figure
{
double chang;
double kuan;
public JUxing(double c, double k)
{
this.chang = c;
this.kuan = k;
}
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
public override double Area()
{
return chang * kuan;
}
}
public class San:Figure
{
double bian;
double heigth;
public San(double b, double h)
{
this.bian = b;
this.heigth = h;
}
public override double Area()
{
return bian * heigth / 2;
}
} } Form窗體代碼: using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace Test3_2 {
public partial class Form1 : Form
{
public Form1()
{
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
InitializeComponent();
}
private void btnCircle_Click(object sender, EventArgs e)
{
Circle c=new Circle(Convert.ToInt32(TxtChang.Text));
lblShow.Text = “圓的面積為:” + c.Area();
}
private void btnJu_Click(object sender, EventArgs e)
{
JUxing
j
=
new JUxing(Convert.ToInt32(TxtChang.Text),Convert.ToInt32(TxtHigh.Text));
lblShow.Text = “矩形的面積為:” + j.Area();
}
private void btnSan_Click(object sender, EventArgs e)
{
San
s
=
new
San(Convert.ToInt32(TxtChang.Text), Convert.ToInt32(TxtHigh.Text));
lblShow.Text = “三角形的面積為:” + s.Area();
}
} }
3、定義一個(gè)Person類,包含姓名字段和一個(gè)方法,早上8:30學(xué)生開始上課,教師開始講課。分別用new關(guān)鍵字,虛方法,抽象類實(shí)現(xiàn)多態(tài)性。
New關(guān)鍵字: using System;using System.Collections.Generic;using System.Text;
namespace third.three {
class Program
{
static void Main(string[] args)
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
{
Student s=new Student(“學(xué)生”);
Teacher t=new Teacher(“教師”);
Console.WriteLine(s.name+s.work());
Console.WriteLine(t.name+t.work());
Console.ReadLine();
}
}
public class Person
{
public string name;
public interface method
{ string work();}
}
public class Student:Person
{
public Student(string name)
{ this.name = name;}
public string work()
{ return “早上8:30開始上課”;}
}
public class Teacher:Person
{
public Teacher(string name)
{ this.name = name;}
public string work()
{ return “開始講課”;}
} } 虛方法: using System;using System.Collections.Generic;using System.Text;
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
namespace third.three.two {
class Program
{
static void Main(string[] args)
{
Student s = new Student(“張三”,“學(xué)生”);
PersonWork(s);
Teacher t=new Teacher(“李斯”,“教師”);
PersonWork(t);
}
private static void PersonWork(Person Person)
{ Console.WriteLine(Person.Work());}
}
public class Person
{
public string name;
public Person(string name)
{ this.name = name;}
public virtual string Work()
{ return string.Format(“Person{0}:早上8:30開始”,name);}
}
public class Student : Person
{
private string type;
public Student(string name, string type)
: base(name)
{ this.type = type;}
public override string Work()
{
return string.Format(“Person{0}:早上8:30開始上課”, name);
}
}
public class Teacher : Person
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
{
private string type;
public Teacher(string name, string type)
: base(name)
{ this.type = type;}
public override string Work()
{
return string.Format(“Person{0}:開始講課”, name);
}
} }
抽象類: using System;using System.Collections.Generic;using System.Text;
namespace third.three.three {
class Program
{
static void Main(string[] args)
{
Student s = new Student(“張三”, “學(xué)生”);
PersonWork(s);
Teacher t = new Teacher(“李斯”, “教師”);
PersonWork(t);
}
private static void PersonWork(Person person)
{
Console.WriteLine(person.Work());
}
}
public abstract class Person
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
{
public string name;
public Person(string name)
{ this.name = name;}
public abstract string Work();
}
public class Student : Person
{
private string type;
public Student(string name, string type)
: base(name)
{
this.type = type;
}
public override string Work()
{
return string.Format(“Person{0}:早上8:30開始上課”, name);
}
}
public class Teacher : Person
{
private string type;
public Teacher(string name, string type)
: base(name)
{
this.type = type;
}
public override string Work()
{
return string.Format(“Person{0}:開始講課”, name);
}
} }
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
六、實(shí)驗(yàn)體會(huì)(遇到問題及解決辦法,編程后的心得體會(huì))
通過本次實(shí)驗(yàn),我理解了類的繼承性與多態(tài)性;掌握了虛方法的定義以及如何用虛方法來實(shí)現(xiàn)多態(tài);掌握了抽象類的定義以及如何用抽象方法來實(shí)現(xiàn)多態(tài)。這次實(shí)驗(yàn)與前兩次不同,采用Windows應(yīng)用程序,既涉及到代碼段也涉及到界面的設(shè)計(jì)。所以,勉強(qiáng)通過實(shí)驗(yàn)。
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
實(shí)驗(yàn)項(xiàng)目名稱: 接口、文件和流 實(shí)驗(yàn)學(xué)時(shí): 6 同組學(xué)生姓名: 實(shí)驗(yàn)地點(diǎn): A205 實(shí)驗(yàn)日期: 12月7日-12月21日 實(shí)驗(yàn)成績(jī): 批改教師: 批改時(shí)間:
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
實(shí)驗(yàn)4 接口、文件和流
一、實(shí)驗(yàn)?zāi)康?/p>
(1)掌握接口的定義及使用方法;
(2)掌握流,序列化和反序列化的概念和使用方法;(3)掌握流文件的讀寫操作類及其使用方法;
(4)掌握OpenFileDialog,SaveFileDialog等控件的使用。
二、實(shí)驗(yàn)要求
(1)編寫程序要規(guī)范、正確,上機(jī)調(diào)試過程和結(jié)果要有記錄;(2)做完實(shí)驗(yàn)后給出本實(shí)驗(yàn)的實(shí)驗(yàn)報(bào)告。
三、實(shí)驗(yàn)設(shè)備、環(huán)境
安裝有Visual Studio.NET軟件。
四、實(shí)驗(yàn)步驟
1、分析題意;
2、根據(jù)題目要求,新建項(xiàng)目;
3、編寫并輸入相關(guān)的程序代碼;
5、運(yùn)行與調(diào)試項(xiàng)目;
6、保存項(xiàng)目。
五、實(shí)驗(yàn)內(nèi)容
1、定義一個(gè)Person類,包含姓名字段和一個(gè)方法,早上8:30學(xué)生開始上課,教師開始講課。用接口來實(shí)現(xiàn)。
using System;using System.Collections.Generic;using System.Text;namespace Test4_1 {
class Program
{
static void Main(string[] args)
{
Student s = new Student(“張三”,“學(xué)生”);
Console.WriteLine(s.Work());
Teacher t = new Teacher(“李四”,“老師”);
Console.WriteLine(t.Work());
}
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
public abstract class Person
{
public string name;
public Person(string name)
{
this.name = name;
}
}
interface IPerson
{
string type { get;}
string Work();
}
public class Student :Person, IPerson
{
public string type
{
get { return string.Format(“老師”);}
}
public Student(string name, string type)
: base(name)
{
this.name=name;
}
public string Work()
{
return string.Format(“Person{0}:早上8:30開始上課”, name);
}
}
public class Teacher :Person, IPerson
{
public string type
{
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
get { return string.Format(“學(xué)生”);}
}
public Teacher(string name, string type)
: base(name)
{
this.name = name;
}
public string Work()
{
return string.Format(“Person{0}:早上8:30開始講課”, name);
}
}
} }
2、聲明一個(gè)接口Iplayer,包含5個(gè)接口方法:播放,停止,暫停,上一首和下一首。在該程序中定義一個(gè)MP3播放器類和一個(gè)AVI播放器類,以實(shí)現(xiàn)該接口。
MP3類(包含Iplayer接口,AVI類): using System;using System.Collections.Generic;using System.Text;namespace Test4_2 {
interface IPlayer
{
string Play();
string Stop();
string Pause();
string Pre();
string Next();
}
public class MP3:IPlayer
{
public string Play()
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
{
return “正在播放MP3歌曲!”;
}
public string Stop()
{
return “停止播放MP3歌曲!”;
}
public string Pause()
{
return “暫停播放MP3歌曲!”;
}
public string Pre()
{
return “播放上一首MP3歌曲!”;
}
public string Next()
{
return “播放下一首MP3歌曲!”;
}
}
public class AVI : IPlayer
{
public string Play()
{
return “正在播放AVI歌曲!”;
}
public string Stop()
{
return “停止播放AVI歌曲!”;
}
public string Pause()
{
return “暫停播放AVI歌曲!”;
}
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
public string Pre()
{
return “播放上一首AVI歌曲!”;
}
public string Next()
{
return “播放下一首AVI歌曲!”;
}
} } Form窗體里代碼: using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace Test4_2 {
public partial class Form1 : Form
{
IPlayer iplayer;
MP3 mp3;
AVI avi;
public Form1()
{
InitializeComponent();
}
private void btnMp3_Click(object sender, EventArgs e)
{
mp3 = new MP3();
iplayer =(IPlayer)mp3;
}
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
private void btnPlay_Click(object sender, EventArgs e)
{
label1.Text = iplayer.Play();
}
private void btnUp_Click(object sender, EventArgs e)
{
label1.Text = iplayer.Pre();
}
private void btnStop_Click(object sender, EventArgs e)
{
label1.Text = iplayer.Stop();
}
private void btnPause_Click(object sender, EventArgs e)
{
label1.Text = iplayer.Pause();
}
private void btnNext_Click(object sender, EventArgs e)
{
label1.Text = iplayer.Next();
}
private void btnAvi_Click(object sender, EventArgs e)
{
avi = new AVI();
iplayer =(IPlayer)avi;
}
} }
3、實(shí)現(xiàn)對(duì)文本文件的讀寫操作,用文件操作控件打開和保存文件。
using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.IO;namespace Test4_3
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnSave_Click(object sender, EventArgs e)
{
saveFileDialog1.ShowDialog();
StreamWriter
sw = StreamWriter(saveFileDialog1.FileName,true);
sw.WriteLine(DateTime.Now.ToString());
sw.WriteLine(txtSource.Text);
sw.Close();
}
private void btnShow_Click(object sender, EventArgs e)
{
StreamReader sr = StreamReader(saveFileDialog1.FileName);
txtShow.Text = sr.ReadToEnd();
sr.Close();
}
} }
4、實(shí)現(xiàn)對(duì)二進(jìn)制文件的讀寫操作。
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.IO;
new
new
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
namespace Test4_4 {
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnSave_Click(object sender, EventArgs e)
{
FileStream
fs
= FileStream(@“d:Datastudent.dat”,FileMode.Append,FileAccess.Write);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(Int32.Parse(txtStuNo.Text));
bw.Write(TxtName.Text);
bool isMale;
if(rdoMan.Checked)
isMale = true;
else
isMale = false;
bw.Write(isMale);
fs.Close();
bw.Close();
}
private void btnShow_Click(object sender, EventArgs e)
{
lstShow.Items.Clear();
lstShow.Items.Add(“學(xué)號(hào)t姓名t性別”);
FileStream
fs
= FileStream(@“d:Datastudent.dat”,FileMode.Open,FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
fs.Position = 0;
while(fs.Position!= fs.Length)
{
new
new
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
int s_no = br.ReadInt32();
string name = br.ReadString();
string sex = “";
if(br.ReadBoolean())
sex = ”男“;
else
sex = ”女“;
string
result String.Format(”{0}t{1}t{2}“,s_no,name,sex);
lstShow.Items.Add(result);
}
br.Close();
fs.Close();
}
} }
5、實(shí)現(xiàn)對(duì)象序列化和反序化。
Student類: using System;using System.Collections.Generic;using System.Text;namespace Test4_5 {
[Serializable]
public class Student
{
public int sno;
public string name;
public bool sex;
public Student(int s_no, string name, bool isMale)
{
this.sno = s_no;
this.name = name;
this.sex = isMale;
=
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
}
} } StudentList類: using System;using System.Collections.Generic;using System.Text;namespace Test4_5 {
[Serializable]
public class StudentList
{
private Student[] list = new Student[100];
public Student this[int index]
{
get
{
if(index < 0 || index >= 100)
return list[0];
else
return list[index];
}
set
{
if(!(index < 0 || index >=100))
list[index] = value;
}
}
} } Form下的代碼: using System;using System.Collections.Generic;using System.ComponentModel;
金陵科技學(xué)院實(shí)驗(yàn)報(bào)告
using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.IO;using System.Runtime.Serialization.Formatters.Binary;namespace Test4_5 {
public partial class Test9_32 : Form
{
private StudentList list = new StudentList();
private int i = 0;
public Test9_32()
{
InitializeComponent();
}
private void Test9_32_Load(object sender, EventArgs e)
{
}
private void btnSave_Click(object sender, EventArgs e)
{
string file = @”d:datastudent.dat";
Stream
stream
= FileStream(file,FileMode.OpenOrCreate,FileAccess.Write);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(stream,list);
stream.Close();
}
private void btnAdd_Click(object sender, EventArgs e)
{
int sno = Int32.Parse(txtStuNo.Text);
bool isMale;
if(rdoMan.Checked)
isMale = true;
new
第二篇:C#程序設(shè)計(jì)案例評(píng)語
C#程序設(shè)計(jì)案例評(píng)語:
優(yōu)秀:該生在課程實(shí)習(xí)過程中,能夠按照實(shí)習(xí)任務(wù)書的要求,完整的開發(fā)記事本及計(jì)算器程序,設(shè)計(jì)過程中能主動(dòng)查閱資料,獨(dú)立完成程序開發(fā),軟件設(shè)計(jì)界面良好,功能完整,實(shí)習(xí)報(bào)告內(nèi)容詳細(xì)。實(shí)習(xí)過程中表現(xiàn)突出。
良好:該生在課程實(shí)習(xí)過程中,能夠按照實(shí)習(xí)任務(wù)書的要求,完整的開發(fā)記事本及計(jì)算器程序,設(shè)計(jì)過程中能獨(dú)立完成程序開發(fā),軟件設(shè)計(jì)界面良好,功能完整,實(shí)習(xí)報(bào)告內(nèi)容詳細(xì)。實(shí)習(xí)過程中表現(xiàn)良好。
中等:該生在課程實(shí)習(xí)過程中,能夠按照實(shí)習(xí)任務(wù)書的要求,比較完整的開發(fā)記事本及計(jì)算器程序,設(shè)計(jì)過程中能在老師的指導(dǎo)下完成程序開發(fā),功能完整,實(shí)習(xí)報(bào)告內(nèi)容完整。實(shí)習(xí)過程中表現(xiàn)一般。
及格:該生在課程實(shí)習(xí)過程中,基本能夠按照實(shí)習(xí)任務(wù)書的要求,比較完整的開發(fā)記事本及計(jì)算器程序,設(shè)計(jì)過程中能在老師和同學(xué)的指導(dǎo)下完成程序開發(fā),功能基本完整,實(shí)習(xí)報(bào)告內(nèi)容完整。實(shí)習(xí)過程中表現(xiàn)一般。
第三篇:《計(jì)算機(jī)程序設(shè)計(jì)》實(shí)驗(yàn)報(bào)告
《計(jì)算機(jī) 程序設(shè)計(jì)》 實(shí)驗(yàn)報(bào)告
姓名:
學(xué)號(hào) :
實(shí)驗(yàn)日期:
****年**月**日
實(shí)驗(yàn)名稱
控制結(jié)構(gòu)與基本算法 一、實(shí)驗(yàn)?zāi)康囊?1.熟練掌握 if 語句和 switch 語句 2.循環(huán)控制結(jié)構(gòu)的使用 二、實(shí)驗(yàn)內(nèi)容 1.實(shí)驗(yàn)教材 P86 第四題。
2.實(shí)驗(yàn)教材 P87 第八題。
3.實(shí)驗(yàn)教材 P108 第一題。
4.實(shí)驗(yàn)教材 108 頁(yè)的第四題。
5.選做題:參考實(shí)驗(yàn)教材 P104 第六題,做課件上題目:
科大有 4 位同學(xué)中的一位做了好事不留名,表?yè)P(yáng)信來了之后,校長(zhǎng)問這四位是誰做的好事.A 說:不是我.B 說:是 C.C 說:是 D.D 說:他(C)胡說
? 文件名格式:學(xué)號(hào)-姓名-實(shí)驗(yàn) 5.doc
? 序號(hào) 1-23:tmf77@mail.ustc.edu.cn ? 序號(hào) 24-45:yunmeng@mail.ustc.edu.cn ? 序號(hào) 46-67:cys1024@mail.ustc.edu.cn
三、上機(jī)程序(算法設(shè)計(jì)思想)
四、運(yùn)行結(jié)果
五、調(diào)試中的問題及解決方法
第四篇:分支程序設(shè)計(jì)實(shí)驗(yàn)報(bào)告[范文模版]
實(shí)驗(yàn)二 二 分支程序設(shè)計(jì) 一、實(shí)驗(yàn)?zāi)康? 1、學(xué)習(xí)分支程序得設(shè)計(jì)方法 2、熟悉在 PC 機(jī)上建立、匯編、連接、調(diào)試與運(yùn)行匯編語言程序得過程 二、實(shí)驗(yàn)環(huán)境:
硬件環(huán)境
IBM/ PC 及其兼容機(jī) 軟件環(huán)境
統(tǒng) 操作系統(tǒng) DO S
編輯程序 EDIT 或其她編輯程序
序程編匯? 匯編程序 M ASM、E XE
連接程序LIN K、EXE 序 調(diào)試程序 DEB UG、EXE 三、實(shí)驗(yàn)內(nèi)容:
:、在屏幕上顯示如下信息:—-— —- ------—-—---— — ------—-Panda
2— —- --— — ---—-—-———-----— —-—--Cat
?
3-——--------------———- -——-Ra bbit
4— — -— —-— — -— —--— — --- —- --——------Pig—— ------—--—--—-—---— —- --—EXI T
(Pl(wèi)ea se
ch oo se 1, 2, 3,4or 5)—- ----入 若輸入 1, 顯示“I like e
p panda ”后程序結(jié)束;若輸入 2, 顯示“I
lik e cat” ”后程序結(jié)束;若輸入 3,顯示“I
lik e rab bit t入 ”后程序結(jié)束;若輸入 4, 顯示“I do n’t l like pig ”后程序結(jié)束;若輸入 5,程序直接結(jié)束;若輸入其它字符,顯示“You
pr ess an error key!“ 后程序結(jié)束.1)流程圖
2)源程序 DATA SEGMENT
INFOR1 DB 0AH,0DH,”1-—-—----—-—Panda:$"
INFOR2 DB 0AH,0DH,”2—-—-——--———Cat:$”
INFOR3 DB 0AH,0DH,"3---—---——-—Rabbit;$”
INFOR4 DB 0AH,0DH,"4---—------—pig:$“
INFOR5 DB 0AH,0DH,”5--—--——--—-EXIT:$"
INFOR6 DB 0AH,0DH,”(please choose 1,2,3,4 or 5——-):$“
INFOR7 DB 0AH,0DH,”I like Panda:$“
INFOR8 DB 0AH,0DH,"I like Cat:$”
INFOR9 DB 0AH,0DH,"I like Rabbit;$"
INFOR10 DB 0AH,0DH,”I like pig:$"
INFOR11 DB 0AH,0DH,”you press an error key?。骸纭?DATA ENDS
;數(shù)據(jù)段結(jié)束 CODE SEGMENT
;代碼段開始 Y Y Y Y N N N N N 開始 選項(xiàng) 用戶輸入 Al=1 Al=2 Al=3 Al=4 Al=5 You press an error key 結(jié)束 I like panda I like cat I like rabbit I like do not
ASSUME
CS:CODE,DS:DATA
;段尋址 START: MOV AX,DATA
;將 dat(yī)a 得數(shù)據(jù)存入ax 中
MOV DS,AX
;為 ds 賦值
MOV DX,OFFSET
INFOR1
;返回變量 INFOR1 段內(nèi)偏移地址【運(yùn)行后在屏幕上顯示字符 1--——--—--—-Panda:】
MOV AH,09H
INT 21H
;執(zhí)行九號(hào)功能調(diào)用
MOV DX,OFFSET
INFOR2
MOV AH,09H
INT 21H
MOV DX,OFFSET
INFOR3
MOV AH,09H
INT 21H
MOV DX,OFFSET
INFOR4
MOV AH,09H
INT 21H
MOV DX,OFFSET
INFOR5
;返回變量 INFOR5 段內(nèi)偏移地址【運(yùn)行后在屏幕上顯示字符 5—-—--——----EXIT:】
MOV AH,09H
INT 21H
MOV DX,OFFSET
INFOR6
MOV AH,09H
INT 21H
MOV AH,01H
INT 21H
CMP AL,“1’
JE
Panda
CMP AL,'2’
JE
Cat
CMP AL,”3’
JE
Rabbit
CMP AL,’4'
JE Pig
CMP AL,’5’
JE PEND
JMP Other Panda:
MOV DX,OFFSET INFOR7
MOV AH,09H
INT 21H
JMP PEND Cat:
8ROFNI TESFFO,XD VOM? H90,HA VOM? H12 TNI? JMP PEND Rabbit:
MOV DX,OFFSET INFOR9
MOV AH,09H
H12 TNI?
JMP PEND Pig:
MOV DX,OFFSET INFOR10
H90,HA VOM? INT 21H
JMP PEND Other:
MOV DX,OFFSET INFOR11
MOV AH,09H
H12 TNI?
JMP PEND PEND:
MOV AH,4CH
INT 21H CODE
ENDS
END START
2、、從鍵盤輸入一字符,判斷該字符就是小寫字母、大寫字母、數(shù)字或其它字符.若輸入為小寫字母, 顯示“Y You
I nput a Lo wer case Letter!”;若輸入為大寫字母, 顯示“You Inp ut a Uppercase L et ter!”;若輸入為數(shù)字,顯示“Yo ou Input a Digit!“;
若輸入為其它字符,顯示“You Inpu t
Ot her Let tt er!”。、編程指導(dǎo) 字 數(shù)字 0? ? 9得ASC II 碼為30H? ?39H;大寫字母得 ASCII 碼為 4 1H? ? 5AH,小寫字母得AS CI I碼為61H? ?7AH。本題目將字符分為小寫字母、大寫字母、數(shù)字及其它字符,得 根據(jù)鍵入字符得 AS CII 碼值判斷其所屬類型, 并顯示相應(yīng)得信息 息.字符串顯示使用功能號(hào)為 09H 得 得 DOS 功能調(diào)用, 接收鍵盤輸入得單個(gè)字符使為 用功能號(hào)為 01H 得 得 DOS 功能調(diào)用。
2、流程圖及程序框圖 1)流程圖 2)源程序 DATA SEGMENT
INFOR1 DB 0AH,0DH,”Please Press Any Key to input a letter:$"
INFOR2 DB 0AH,0DH,”You input a lowercase letter!$”
INFOR3 DB 0AH,0DH,“You input a Uppercase letter!
$”
INFOR4 DB 0AH,0DH,"You input a Digit!
$”
INFOR5 DB 0AH,0DH,“You input Other letter!$” DATA ENDS CODE SEGMENT
ASSUME
CS:CODE,DS:DATA START:
MOV AX,DATA
; 顯示信息“Please Press Any Key to input a letter”得指令序列以及接收從鍵盤輸入一個(gè)字符得指令序列
MOV DS,AX
MOV
DX,OFFSET
INFOR1
H90,HA
VOM?
INT
21H
MOV AH,01H
INT 21H Y Y Y Y Y Y 顯示提示信息“Please Press Any Key to input a letter” 及功能號(hào)為 1 得接收鍵盤輸入單個(gè)字符得指令序列 開始 結(jié)束(AL)<’0’(AL)<=’9’(AL)<’A’(AL)<=’Z’(AL)<’a’(AL)<=’z’ 輸入得就是小寫字母,顯示信息 輸入得就是大寫字母,顯示信息 輸入得就是數(shù)字,顯示有關(guān)信息 輸入得就是其它字符,顯示信息
CMP
AL,’0’
JB
OTHER
CMP
AL,’9’
JBE
DIGIT
CMP
AL,’A“
REHTO(shè)
BJ? ”Z',LA
PMC? REPPU
EBJ? CMP
AL,’a’
JB
OTHER
“z',LA
PMC? JBE
LOWER
JMP
PEND LOWER:
;顯示“You Input a Lowercase Letter!”得指令序列
MOV DX,OFFSET INFOR2
H90,HA VOM? INT 21H
出跳序程使應(yīng)后支分個(gè)一完行執(zhí)意注;
DNEP PMJ?UPPER:
; 顯示“You Input a Uppercase Letter”得指令序列 MOV DX,OFFSET INFOR3
H90,HA VOM? H12 TNI? DNEP PMJ?DIGIT:
; 顯示“You Input a Digit!”得指令序列 MOV DX,OFFSET INFOR4
H90,HA VOM? INT 21H
JMP PEND OTHER:
; 顯示“You Input Other Letter!”得指令序列
5ROFNI TESFFO,XD VOM? MOV AH,09H
H12 TNI?PEND:
MOV AH,4CH
H12 TNI?CODE
ENDS
END START
四、心得 通過這次上機(jī)實(shí)驗(yàn), 我掌握了分支程序額設(shè)計(jì)方法, 宏定義及宏調(diào)用得基本方法,了解了小寫字母與大寫字母得ASCII 碼表示及其轉(zhuǎn)換方法,了解了數(shù)字及其她得 字符得 AS CII 碼表示方法, 進(jìn)一步掌握了調(diào)試工具得 使用方法。
第五篇:C程序設(shè)計(jì)實(shí)驗(yàn)報(bào)告
浙江理工大學(xué)信息學(xué)院
C程序設(shè)計(jì)實(shí)驗(yàn)報(bào)告
實(shí)驗(yàn)名稱: 學(xué)時(shí)安排:
實(shí)驗(yàn)類別:
實(shí)驗(yàn)要求:1人1組
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
一、實(shí)驗(yàn)?zāi)康?/p>
二、實(shí)驗(yàn)設(shè)備介紹
軟件需求: Visual C++ 6.0或CFree3.5以上版本
硬件需求: 對(duì)于硬件方面的要求,建議配置是Pentium III 450以上的CPU處理器,64MB以上的內(nèi)存,200MB的自由硬盤空間、CD-ROM驅(qū)動(dòng)器、能支持24位真彩色的顯示卡、彩色顯示器、打印機(jī)。
三、實(shí)驗(yàn)內(nèi)容
四、程序清單
五、運(yùn)行結(jié)果
六、實(shí)驗(yàn)心得