第一篇:C#程序設計案例評語
C#程序設計案例評語:
優秀:該生在課程實習過程中,能夠按照實習任務書的要求,完整的開發記事本及計算器程序,設計過程中能主動查閱資料,獨立完成程序開發,軟件設計界面良好,功能完整,實習報告內容詳細。實習過程中表現突出。
良好:該生在課程實習過程中,能夠按照實習任務書的要求,完整的開發記事本及計算器程序,設計過程中能獨立完成程序開發,軟件設計界面良好,功能完整,實習報告內容詳細。實習過程中表現良好。
中等:該生在課程實習過程中,能夠按照實習任務書的要求,比較完整的開發記事本及計算器程序,設計過程中能在老師的指導下完成程序開發,功能完整,實習報告內容完整。實習過程中表現一般。
及格:該生在課程實習過程中,基本能夠按照實習任務書的要求,比較完整的開發記事本及計算器程序,設計過程中能在老師和同學的指導下完成程序開發,功能基本完整,實習報告內容完整。實習過程中表現一般。
第二篇:C#程序設計實驗報告
實驗報告書寫要求
實驗報告原則上要求學生手寫,要求書寫工整。若因課程特點需打印的,標題采用四號黑體,正文采用小四號宋體,單倍行距。紙張一律采用A4的紙張。
實驗報告書寫說明
實驗報告中實驗目的和要求、實驗儀器和設備、實驗內容與過程、實驗結果與分析這四項內容為必需項。教師可根據學科特點和實驗具體要求增加項目。
填寫注意事項
(1)細致觀察,及時、準確、如實記錄。(2)準確說明,層次清晰。
(3)盡量采用專用術語來說明事物。
(4)外文、符號、公式要準確,應使用統一規定的名詞和符號。(5)應獨立完成實驗報告的書寫,嚴禁抄襲、復印,一經發現,以零分論處。
實驗報告批改說明
實驗報告的批改要及時、認真、仔細,一律用紅色筆批改。實驗報告的批改成績采用五級記分制或百分制,按《金陵科技學院課堂教學實施細則》中作業批閱成績評定要求執行。
實驗報告裝訂要求
實驗批改完畢后,任課老師將每門課程的每個實驗項目的實驗報告以自然班為單位、按學號升序排列,裝訂成冊,并附上一份該門課程的實驗大綱。
金陵科技學院實驗報告
實驗項目名稱: C#基礎編程 實驗學時: 6 同組學生姓名: 實驗地點: 1318 實驗日期: 10月5日-10月19日 實驗成績: 批改教師: 批改時間:
金陵科技學院實驗報告
實驗1 C#基礎編程
一、實驗目的
1、熟悉Visual Studio.NET開發環境。
2、掌握C#應用程序的基本操作過程。
3、掌握C#的數據類型,運算符以及表達式的使用。
4、掌握分支和循環語句的使用方法。
5、掌握一維數組,二維數組及數組型數組的使用。
二、實驗要求
(1)編寫程序要規范、正確,上機調試過程和結果要有記錄(2)做完實驗后給出本實驗的實驗報告。
三、實驗設備、環境
安裝有Visual Studio.NET軟件。
四、實驗步驟
1、分析題意。
2、根據題目要求,新建項目。
3、編寫并輸入相關的程序代碼。
5、運行與調試項目。
6、保存項目。
五、實驗內容
1、編寫一個簡單的控制臺應用程序,打印一行文字(如你的姓名)。
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、編寫一個簡單的Windows應用程序,在窗體Load事件中書寫代碼,標簽中顯示你的姓名。
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 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、編寫一個一個程序,用來判斷輸入的是大寫字母,小寫字母,數字還是其他的字符。
using System;using System.Collections.Generic;using System.Text;
namespace one.third {
class Program
{
static void Main(string[] args)
{
Console.WriteLine(“請輸入一個字符:”);
char c = Convert.ToChar(Console.ReadLine());
if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
Console.WriteLine(“這是一個字母”);
if(char.IsDigit(c))
Console.WriteLine(“這是一個數字”);
金陵科技學院實驗報告
}
} }
4、分別用while,do-while,for循環求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的自然數之和為:” + 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的自然數的和為:” + sum);
}
}
金陵科技學院實驗報告
} 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的自然數的和為:” + sum);
}
} }
5、定義一個一維數組,用隨機數為此賦值,用foreach循環輸出其中的內容。
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、實現二維數組的輸入和輸出。
using System;using System.Collections.Generic;using System.Linq;
金陵科技學院實驗報告
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、實現數組型數組的輸入和輸出。
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]);
}
}
}
} }
六、實驗體會(遇到問題及解決辦法,編程后的心得體會)
剛開始編程的時候覺得無從下手,盡管我們已經學了好幾種高級編程語言,但每個都
金陵科技學院實驗報告
有其獨特的地方,稍不留神就會混淆。
通過這次實驗,我體會到課后復習鞏固的重要性。在編程的時候,很多內容都不記得,需要去翻書。不得不說,實驗是鞏固課程的好方法!本次實驗,我熟悉Visual Studio.NET開發環境;掌握了C#應用程序的基本操作過程;掌握了C#的數據類型,運算符以及表達式的使用;掌握了分支和循環語句的使用方法以及一維數組,二維數組及數組型數組的使用。
金陵科技學院實驗報告
實驗項目名稱: 類與對象 實驗學時: 6 同組學生姓名: 實驗地點: 1318 實驗日期: 10月26日-11月9日 實驗成績: 批改教師: 批改時間:
金陵科技學院實驗報告
實驗2 類與對象
一、實驗目的、要求
(1)掌握類的定義和使用;
(2)掌握類的數據成員,屬性的定義和使用;
(3)掌握方法的定義,調用和重載以及方法參數的傳遞;(4)掌握構造函數的定義和使用。
二、實驗要求
(1)編寫程序要規范、正確,上機調試過程和結果要有記錄;(2)做完實驗后給出本實驗的實驗報告。
三、實驗設備、環境
安裝有Visual Studio.NET軟件。
四、實驗步驟
1、分析題意;
2、根據題目要求,新建項目;
3、編寫并輸入相關的程序代碼;
5、運行與調試項目;
6、保存項目。
五、實驗內容
1、定義一個方法,實現兩個數的交換(分別把參數按值傳遞和按引用傳遞)。
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());
金陵科技學院實驗報告
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、定義一個方法,實現數組的排序。using System;using System.Collections.Generic;using System.Text;
namespace second.two {
class Program
{
string.Format(”
按
值
傳
參
交
換
之
金陵科技學院實驗報告
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 = 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);
金陵科技學院實驗報告
}
} }
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;
金陵科技學院實驗報告
square s = new square(a,b);
Console.WriteLine(“求矩形面積,長為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、設計一個windows應用程序,在該程序中定義一個學生類和班級類,以處理每個學生的學號,姓名,語文,數學和英語成績,要求:
1)能查詢每個學生的總成績。2)能顯示全班前三名的名單。
3)能顯示單科成績最高分和不及格的學生名單。4)能統計全班學生的平均成績。
5)能顯示各科成績不同分數段的學生人數的百分比。
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
{
金陵科技學院實驗報告
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;
}
//給所有成績排序,用后面實現前三名的排名
金陵科技學院實驗報告
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;
}
}
}
//顯示單科成績的最高分
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;
金陵科技學院實驗報告
}
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 += “單科數學最高:” + stu[HighScore(0)].name + “n”;
Maxer += “ 單科語文最高:” + stu[HighScore(1)].name + “n”;
Maxer += “ 單科英語最高:” + stu[HighScore(2)].name + “n”;
Loser += “單科數學掛科名單:” +BuhgName(0)+ “n”;
Loser += “單科語文掛科名單:” + BuhgName(1)+ “n”;
Loser += “單科英語掛科名單:” + BuhgName(2)+ “n”;
金陵科技學院實驗報告
return Maxer + “n” + Loser;
}
//全班的平均成績
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 “班級總分平均分:”+avg;
}
//各科成績不同分數段的學生百分比
//英語成績各分數段百分比
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++;
}
金陵科技學院實驗報告
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 “語文成績百分比:”+“n”+“90~100:”+per1+“ 80~90:”+per2+“ 80~70:”+per3+“ 70~60:”+per4+“ 60以下的:”+per5;
}
//數學成績各分數段百分比
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))
{
金陵科技學院實驗報告
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(“數學成績百分比:” + “n” + “90~100:” + per1 + “ 80~90:” + per2 + “ 80~70:” + per3 + “ 70~60:” + per4 + “ 60以下的:” + per5);
}
//英語成績各分數段百分比
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++;
金陵科技學院實驗報告
}
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(“數學成績百分比:” + “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;
金陵科技學院實驗報告
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 + “的總成績:sl.stu[pos].sumScore;
}
else { MessageBox.Show(”不存在這個人!“);}
}
private void btnFinish_Click(object sender, EventArgs e)
{
label7.Text = ”前3名:“+”n“;
” + 金陵科技學院實驗報告
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”;
}
} }
六、實驗體會(遇到問題及解決辦法,編程后的心得體會)
通過本次實驗,我掌握了類的定義與使用;掌握了類的數據成員,屬性的定義和使用;掌握了方法的定義,調用和重載以及方法參數的傳遞以及構造函數的定義和使用。值得注意的是:本次實驗中return的使用以及所在的位置,類型轉換時也經常用到
金陵科技學院實驗報告
實驗項目名稱: 繼承與多態 實驗學時: 6 同組學生姓名: 實驗地點: 1318 實驗日期: 11月16日-11月30日 實驗成績: 批改教師: 批改時間:
金陵科技學院實驗報告
實驗3 繼承與多態
一、實驗目的、要求
(1)掌握類的繼承性與多態性;
(2)掌握虛方法的定義以及如何使用虛方法實現多態;(3)掌握抽象類的定義以及如何使用抽象方法實現多態;
二、實驗要求
(1)編寫程序要規范、正確,上機調試過程和結果要有記錄;(2)做完實驗后給出本實驗的實驗報告。
三、實驗設備、環境
安裝有Visual Studio.NET軟件。
四、實驗步驟
1、分析題意;
2、根據題目要求,新建項目;
3、編寫并輸入相關的程序代碼;
5、運行與調試項目;
6、保存項目。
五、實驗內容
1、設計一個Windows應用程序,在該程序中首先構造一個學生基本類,再分別構造小學生、中學生、大學生派生類,當輸入相關數據,單擊不用的按鈕時,將分別創建不同的學生類對象,并輸出當前學生的總人數,該學生的姓名,學生類型,平均成績。
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;
金陵科技學院實驗報告
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;
金陵科技學院實驗報告
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窗體內的代碼:
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
{
金陵科技學院實驗報告
public Form1()
{
InitializeComponent();
}
private void btnSmall_Click(object sender, EventArgs e)
{
Pupil),Convert.ToDouble(txtMath.Text));
lblShow.Text += “總人數:” +Convert.ToString(Student.number)+ “,” + “姓名:” + p.Name + “,” + “小學生” + “,” + “平均成績為:” + 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 += “總人數:” + Convert.ToString(Student.number)+ “,” + “姓名:” + m.Name + “,” + “中學生” + “,” + “平均成績為:” + m.Average()+ “n”;
}
private void btnBig_Click(object sender, EventArgs e)
{
College Convert.ToInt32(txtAge.Text), Convert.ToDouble(txtMath.Text));
lblShow.Text += “總人數:” + Convert.ToString(Student.number)+ “,” + “姓名:” + c.Name + “,” + “大學生” + “,” + “平均成績為:” + c.Average()+ “n”;
}
}
c
=
new
College(txtName.Text,Convert.ToDouble(txtChinese.Text),金陵科技學院實驗報告
}
2、設計一個Windows應用程序,在該程序中定義平面圖形抽象類和派生類圓,矩形和三角形。
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;
}
金陵科技學院實驗報告
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()
{
金陵科技學院實驗報告
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、定義一個Person類,包含姓名字段和一個方法,早上8:30學生開始上課,教師開始講課。分別用new關鍵字,虛方法,抽象類實現多態性。
New關鍵字: using System;using System.Collections.Generic;using System.Text;
namespace third.three {
class Program
{
static void Main(string[] args)
金陵科技學院實驗報告
{
Student s=new Student(“學生”);
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;
金陵科技學院實驗報告
namespace third.three.two {
class Program
{
static void Main(string[] args)
{
Student s = new Student(“張三”,“學生”);
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
金陵科技學院實驗報告
{
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(“張三”, “學生”);
PersonWork(s);
Teacher t = new Teacher(“李斯”, “教師”);
PersonWork(t);
}
private static void PersonWork(Person person)
{
Console.WriteLine(person.Work());
}
}
public abstract class Person
金陵科技學院實驗報告
{
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);
}
} }
金陵科技學院實驗報告
六、實驗體會(遇到問題及解決辦法,編程后的心得體會)
通過本次實驗,我理解了類的繼承性與多態性;掌握了虛方法的定義以及如何用虛方法來實現多態;掌握了抽象類的定義以及如何用抽象方法來實現多態。這次實驗與前兩次不同,采用Windows應用程序,既涉及到代碼段也涉及到界面的設計。所以,勉強通過實驗。
金陵科技學院實驗報告
實驗項目名稱: 接口、文件和流 實驗學時: 6 同組學生姓名: 實驗地點: A205 實驗日期: 12月7日-12月21日 實驗成績: 批改教師: 批改時間:
金陵科技學院實驗報告
實驗4 接口、文件和流
一、實驗目的
(1)掌握接口的定義及使用方法;
(2)掌握流,序列化和反序列化的概念和使用方法;(3)掌握流文件的讀寫操作類及其使用方法;
(4)掌握OpenFileDialog,SaveFileDialog等控件的使用。
二、實驗要求
(1)編寫程序要規范、正確,上機調試過程和結果要有記錄;(2)做完實驗后給出本實驗的實驗報告。
三、實驗設備、環境
安裝有Visual Studio.NET軟件。
四、實驗步驟
1、分析題意;
2、根據題目要求,新建項目;
3、編寫并輸入相關的程序代碼;
5、運行與調試項目;
6、保存項目。
五、實驗內容
1、定義一個Person類,包含姓名字段和一個方法,早上8:30學生開始上課,教師開始講課。用接口來實現。
using System;using System.Collections.Generic;using System.Text;namespace Test4_1 {
class Program
{
static void Main(string[] args)
{
Student s = new Student(“張三”,“學生”);
Console.WriteLine(s.Work());
Teacher t = new Teacher(“李四”,“老師”);
Console.WriteLine(t.Work());
}
金陵科技學院實驗報告
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
{
金陵科技學院實驗報告
get { return string.Format(“學生”);}
}
public Teacher(string name, string type)
: base(name)
{
this.name = name;
}
public string Work()
{
return string.Format(“Person{0}:早上8:30開始講課”, name);
}
}
} }
2、聲明一個接口Iplayer,包含5個接口方法:播放,停止,暫停,上一首和下一首。在該程序中定義一個MP3播放器類和一個AVI播放器類,以實現該接口。
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()
金陵科技學院實驗報告
{
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歌曲!”;
}
金陵科技學院實驗報告
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;
}
金陵科技學院實驗報告
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、實現對文本文件的讀寫操作,用文件操作控件打開和保存文件。
using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.IO;namespace Test4_3
金陵科技學院實驗報告
{
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、實現對二進制文件的讀寫操作。
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
金陵科技學院實驗報告
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(“學號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
金陵科技學院實驗報告
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、實現對象序列化和反序化。
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;
=
金陵科技學院實驗報告
}
} } 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;
金陵科技學院實驗報告
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#程序設計教程期末復習題及答案
習題 1
一、選擇題
1.在C#中 B 都是對象。
A 任何類型 B 任何事物 C 任何代碼 D 任何技術 2.對象包含數據和 A 的方法。
A 在該數據上工作 B 調用 C 函數調用 D 傳遞參數 3.一個類是 D 的藍本。
A 數據集合 B 函數集合 C 方法集合 D 給定功能集合 4..NET構架包含公用語言運行時期和 B。5..NET的核心是 A。
A CLR B Windows2000 C DNA D 分解平臺 6.C#程序以 B 擴展名保存編寫的程序。A.CS B.PS C.CSS D.SC 7.System是 B 的命名空間。
A 存儲系統類 B 控制臺類 C I/O操作 D 新項目 8.namespace用于聲明 B。
A 新項目 B 一個命名空間 C 類與方法 D 指令 9.每個C#程序必須有一個 D 方法。A 類方法 B 構造方法 C Main D 重載方法
二、問答題
1.面向對象編程的三大原則是什么? 答:封裝、繼承和多態性。2.封裝是什么?
答:封裝是用于隱藏對象實際的制作細節。3.繼承是什么?
答:繼承是在建立新的特定對象時,可以使用現有對象的功能性。4.多態性是什么?
答:多態性是程序代碼能夠依據實際對象所需而進行不同的行為。5..NET的核心構件包括哪些? 答:(1).NET構造塊服務或有計劃的訪問某些服務。
(2)將在新的Internet設備上運行的.NET設備軟件。(3).NET用戶經驗。6.CLR的作用是什么?
答:CLR是.NET的核心,它是一個運行時期環境,在該環境中,以不同語言編寫的應用程序均能始終運行。
三、編程題
使用.NET代碼編輯器編寫一個C#應用程序,以在屏幕打印出:
C# is the Component-oriented language in C and C++ family of language.要求:
(1)使用using System命名空間,即定位System命名空間的Console類。(2)不使用using System命名空間,即System命名空間的Console類。(3)使用using指令的別名,即使用using創建using的別名。答案:(1)
//Example1.cs Using System;Class Example1 { Public static void Main(){ Console.Write(“C# is the Component-oriented language ”);Console.WriteLine(“in C and C++ family of language.”);} }(2)
//Example2.cs Class Example1 { Public static void Main(){ System.Console.Write(“C# is component-oriented language”);System.Console.WriteLine(“in C and C++ family language.”);
} }(3)Example3.cs Using output=System.Console;Class Example1
Public static void Main(){ Output.Write(“C# is component-oriented language”);}
習題2
一、選擇題
1.C#的數據類型有 A 和 C 兩種。
A 值類型 B 調用類型 C 引用類型 D 關系類型 2.C#的值類型包括 A、B 和 D 三種。A 枚舉 B 基本類型 C 整形 D 結構 E浮點型 F 字符型
3.C#的引用類型包括 A、B、C、F、G 和 H 六種。
A string B object C 類 D float E char F 數組G 代表 H 4.裝箱是把值類型轉換到 B 類型。
A 數組 B 引用 C char D string 5.拆箱是引用類型返回到 C 類型。
A string B char C 值 D 數組 6. A 類型是所有類型的根。
接口 A System.Object B object C string D System.Int32 7.從派生類到基類對象的轉換是 B 類型轉換。A 顯示 B 隱式 C 自動 D 專向 8.從基類到派生類對象的轉換是 D 類型轉換。A 隱式 B 自動 C專向 D 顯示 9.強制轉換對象可以使用 B 關鍵字實現。A is B as C this D object 10.命名空間用于定義 A 的作用域。
A 應用程序 B 有關類型 C 多重源代碼 D 層次結構 11.using關鍵字用于 B 命名空間中的Console對象。A Console B System C Object D Int32
二、填空題
1.下列程序的運行結果是 99.44。//Exam1.cs using System;class Using { public static void Main(){ int i=918;float f=10.25f;short sh=10;double d=11.19;Console.WriteLine(i+f+sh+d);} } 2.下列程序的運行結果是 25.5。//Exam2.cs using System;class Using { public static void Main(){ int i=5;float f=5.1f;Console.WriteLine(i*f);} }
二、編程題
1. 已知a=1,b=2,c=3,x=2,計算y=ax+bx+c之值。2. 已知圓的半徑Radius=2.5,計算圓的面積。(PI=3.14159)要求:
(1)使用基本方法;(2)使用裝箱與拆箱;
(3)輸出以double,float,int,decimal,short表示;(4)使用object類與類型轉換;(5)使用派生類與as。答案: 1. 方案一: //YValue.cs using System;class Using { public static void Main(){ int a=1,b=2,c=3,x=2,y;y=(a*x+b)*x+c;Console.WriteLine(“y={0}”,y);} } 方案二:
//YValue1.cs using System;class Using { public static void Main(){ int a=1,b=2,c=3,x=2;Console.WriteLine(“y={0}”,(a*x+b)*x+c);} } 2.
(1)使用基本方法 方案一:
//CircleAreaApp.cs using System;class CircleAreaApp { public static void Main(){ double Radius=2.5,Area;Area=3.14159*Radius*Radius;Console.WriteLine(“Area={0}”,Area);} } 方案二:
//CircleAreaApp1.cs using System;class CircleAreaApp { public static void Main(){ double Radius=2.5;Console.WriteLine(“Area={0}”,3.14159*Radius*Radius);} }(2)使用裝箱與拆箱 //CircleAreaApp2.cs using System;class CircleAreaApp { public static void Main(){ double Radius=2.5;double Area=3.14159*Radius*Radius;Console.WriteLine(“Area={0}”,Area);object obj=Area;Console.WriteLine(“Area={0}”,(double)obj);} }(3)輸出以double,float,int,decimal,short表示 //CircleAreaApp3.cs using System;class CircleAreaApp { public static void Main(){ double Radius=2.5;double Area=3.14159*Radius*Radius;Console.WriteLine(“Area={0}”,Area);Console.WriteLine(“Area={0}”,(float)Area);Console.WriteLine(“Area={0}”,(int)Area);Console.WriteLine(“Area={0}”,(decimal)Area);Console.WriteLine(“Area={0}”,(short)Area);} }(4)使用object類與類型轉換 //CircleAreaApp4.cs using System;class Circle { public double Radius=2.5;} class CircleAreaAPP { public static void Main(){ Circle cir=new Circle();double Area=3.14159*cir.Radius*cir.Radius;Console.WriteLine(“Area={0}”,Area);Console.WriteLine(“Area={0}”,(float)Area);object obj=(float)Area;Console.WriteLine(“Area={0}”,(float)obj);} }(5)使用派生類與as //CircleAreaApp5.cs using System;class Circle {} class CircleAreaAPP:Circle { public static void Main(){ double Radius=2.5;double Area=3.14159*Radius*Radius;Console.WriteLine(“Area={0}”,Area);Console.WriteLine(“Area={0}”,(float)Area);object obj=(float)Area;Console.WriteLine(“Area={0}”,(float)obj);Circle cir=new Circle();Console.WriteLine(“cir={0}”,cir==null?“null”:cir.ToString());CircleAreaAPP cirA=new CircleAreaAPP();cirA=cir as CircleAreaAPP;Console.WriteLine(“cirA={0}”,cirA==null?“null”:cirA.ToString());} }
習題3
一、選擇題
1.字符串的輸入使用 B 方法。
A)Cosole.Read()B)Cosole.ReadLine()C)Cosole.Write()D)Cosole.In.read()2.用于格式化輸出十進制數的符號是 C。
A)C B)E C)D D)G E)N F)X 3.用于格式化輸出浮點數的符號是 D。A)C B)D C)G D)F E)N F)X 4.用于格式完整日期/時間模式(長時間)的符號是 A。A)D B)F C)G D)M E)R F)S 5.用于格式完整日期/時間模式(短時間)的符號是 C。A)D B)f C)g D)d E)F F)G
二、編程題
1.從鍵盤輸入一個小寫字母,然后輸出所輸入的小寫字母后其對應單代碼值。2.從鍵盤輸入兩個浮點數,然后輸出這兩個數相加的結果(要求小數后取4位)。3.從鍵盤輸入年、月、日的數值,然后用完整的日期事件格式化輸出。答案: 1.
//CharValue.cs using System;public class CharValue { public static void Main(){ Console.Write(“Enter an char:”);char ch = char.Parse(Console.ReadLine());//or char ch=(char)Console.Readline();Console.WriteLine(ch);Console.WriteLine((int)ch);} }
2.//TwoFloatAddition.cs using System;public class TwoFloatAddition { public static void Main(){ Console.Write(“Enter a float:”);float f1= float.Parse(Console.ReadLine());Console.Write(“Enter a float:”);float f2 = float.Parse(Console.ReadLine());Console.WriteLine(“Result of addition for two float is: {0:F4}”,f1+f2);} }
3.//DateTimeFormat.cs using System;using System.Globalization;public class DateTimeFormat { public static void Main(String[] args){ Console.Write(“Enter year month day: ”);string s = Console.ReadLine();DateTime s1 = DateTime.Parse(s);Console.WriteLine(“d {0:d}”,s1);Console.WriteLine(“D {0:D}”, s1);Console.WriteLine(“f {0:f}”, s1);Console.WriteLine(“F {0:F}”, s1);Console.WriteLine(“g {0:g}”, s1);Console.WriteLine(“G {0:G}”, s1);Console.WriteLine(“m {0:m}”, s1);Console.WriteLine(“M {0:M}”, s1);Console.WriteLine(“r {0:r}”, s1);Console.WriteLine(“R {0:R}”, s1);Console.WriteLine(“s {0:s}”, s1);} }
習題4 1.以下運算符的運算符優先級,D 最高,E 最低。A)+ B)<< C)| D)()E)|| F)++ 2.以下運算符中,A 是三目運算符。
A)?: B)--C)= D)<= 3.在堆棧上創建對象和調用構造函數時,通常使用 B 關鍵字。A)typeof B)new C)as D)is 4. A 用于獲取系統的System.Type類型。
A)typeof B)new C)sizeof D)is
二、寫出下列程序執行結果。1.運行結果。//Increment1.cs using System;public class Increment1 { public static void Main(){ int i1=1993,i2=11,i3=19;Console.WriteLine(“i1={0},i2={1},i2={2}”,i1,i2,i3);i1=i3;Console.WriteLine(“i1={0},i2={1},i2={2}”,i1,i2,i3);i3+=i2;Console.WriteLine(“i1={0},i2={1},i2={2}”,i1,i2,i3);i1=i2+i3;Console.WriteLine(“i1={0},i2={1},i2={2}”,i1,i2,i3);i1++;++i2;i3=i1++ + ++i2;Console.WriteLine(“i1={0},i2={1},i2={2}”,i1,i2,i3);} }
2.運行結果:。//Increment2.cs using System;public class Increment2 { public static void Main(){ int a,b;a = b = 1;b = a / ++b;Console.WriteLine(“a={0} b={1}”,a,b);b = a++-i1);Console.WriteLine(---i1);Console.WriteLine(i2---i3);Console.WriteLine(i4---i5);Console.WriteLine(-i6---i7);Console.WriteLine(i8++/ ++i9*--i10);Console.WriteLine(++i11/i12++ *--i13);Console.Read();} }
三、編程題
1.輸入兩個整數,輸出它們(實數除)的商,并輸出商的第2位小數位(例如:5/18.0=1.875, 1.875的第二位小數是7)。
2.輸入圓球的半徑,計算圓球的表面積(4πr)和體積(4πr/3),其中π=3.14159。3.輸入秒數,把它轉換為用小時、分、秒表示。例如,輸入7278秒,則輸出2小時1分18秒。4.計算x=ab+5ln(1+c)要求:
(1)輸出結果以科學表示法、定點表示法(小數點后保留兩位)和普通表示法表示。(2)輸出結果以整數表示并指明當前工作的日期和時間。
5.計算答案: 1.
//RealDivide.cs using System;public class RealDivide
3223 { public static void Main(){ Console.WriteLine(“Enter two integers:”);string[] s = Console.ReadLine().Split();;int a = int.Parse(s[0]);int b = int.Parse(s[1]);float f = 1.0f * a / b;int c=(int)(f*100)%10;Console.WriteLine(“Result of real divide is : {0}”,f);Console.WriteLine(“Second place of decimals is : {0}”,c);} }
2.//SphereA.cs using System;public class Sphere { public static void Main(){ Console.Write(“Enter the radius of sphere: ”);string s = Console.ReadLine();double radius = double.Parse(s);double surfaceArea = 4 * Math.PI * radius * radius;double Volume = 4 * Math.PI * radius * radius * radius / 3;Console.WriteLine(“SurfaceArea={0}”,surfaceArea);Console.WriteLine(“Volume={0}”,Volume);} }
3.//HourMinuteSecond.cs using System;public class HourMinuteSecond { public static void Main(){ int hour, minute, second;Console.Write(“Enter numbers of second:”);string s = Console.ReadLine();second = int.Parse(s);hour = second / 3600;second %= 3600;minute = second / 60;second = second % 60;Console.WriteLine(“{0} hour {1} minute {2} second”,hour,minute,second);} }
4. //ValueX.cs using System;using System.Globalization;public class ValueX { public static void Main(){ double a, b, c, x;Console.Write(“Enter three numbers: ”);string[] s = Console.ReadLine().Split();a = double.Parse(s[0]);b = double.Parse(s[1]);c = double.Parse(s[2]);x = a * Math.Pow(b, 3)+ 5 * Math.Log(1 + c * c);Console.WriteLine(“x={0:E}ttx={1:F2}ttx={2:G}”, x, x, x);Console.WriteLine(“x={0:D}”,(int)x);DateTime NowTime = DateTime.Now;Console.WriteLine(“{0:D}”, NowTime);} }
5.//MathTestA.cs using System;public class MathTestA { public static void Main(){ double alpha, beta, y;Console.Write(“Enter value of alpha: ”);string s = Console.ReadLine();alpha = double.Parse(s);Console.Write(“Enter value of beta: ”);s = Console.ReadLine();beta = double.Parse(s);y = Math.Pow(Math.Abs(Math.Log(Math.Sqrt(1 + alpha * alpha))a)*(sc)));Console.WriteLine(“Area of triangle is :{0:F2}n”, Area);} else { Console.WriteLine(“can't construct triangle!n”);} Console.ReadLine();}
} 運行結果:
2.//Prime.cs
class Prime { public static void Main(){ int a, n, m = 0, i, j;bool flag;for(i = 2;i <= 50;i++){ flag = true;j = 2;a =(int)Math.Sqrt((double)i);while(flag && j <= a){ if(i % j == 0)flag = false;j++;} if(flag){ Console.Write(“{0:D2} ”, i);m++;if(m % 4 == 0)Console.WriteLine();} } Console.WriteLine();Console.ReadKey();} } 運行結果:
3.//CountDigit.cs class CountDigit { public static void Main(){ int num = 0;char ch;Console.Write(“Enter chars:”);while(true){ if((ch =(char)Console.Read())== 'b')if((ch =(char)Console.Read())== 'y')if((ch =(char)Console.Read())== 'e')break;if(ch >= '0' && ch <= '9')num++;} Console.WriteLine(“Numbers of digit is:{0}n”, num);Console.Read();Console.ReadKey();} } 運行結果:
4.//ForSinCosTan.cs class ForSinCosTan { public static void Main(){ float sinx, cosx, tanx;double x;Console.WriteLine(“xtsinxtcosxttanx”);for(int i = 2;i <= 10;i += 2){ x = i * Math.PI / 180;sinx =(float)Math.Sin(x);cosx =(float)Math.Cos(x);tanx =(float)Math.Tan(x);Console.WriteLine(“{0}tt{1:F6}tt{2:F6}tt{3:F6}”, i, sinx, cosx, tanx);} Console.Read();Console.ReadKey();} } 運行結果:
5.//Factorial.cs
class Factorial { static int n, Fact;public static void Main(){ n = 0;Fact = 1;Console.WriteLine(“Use while loop:”);while(++n <= 5){ Fact *= n;Console.WriteLine(“ {0}!= {1}”, n, Fact);} Console.WriteLine(“Use do-while loop:”);n = 1;Fact = 1;do { Fact *= n;Console.WriteLine(“ {0}!= {1}”, n, Fact);} while(++n <= 5);Console.WriteLine(“Use for loop: ”);Fact = 1;for(n = 1;n <= 5;n++){ Fact *= n;Console.WriteLine(“ {0}!= {1}”, n, Fact);} Console.ReadKey();} } 運行界面:
習題6
一、填空題
1.C#類的成員包括 域、方法、屬性、常量、索引、事件與運算符
2.用于指定類的成員是否可訪問的修飾符有public、protected、private及internal。3.類最常用的方法是Main 4.構造方法實例化對象的形式是 類名 對象=new 類名(構造方法參數)5.從另一個類,繼承一個類的語法是 class 派生類:基類 6.sealed類用于 確保一個類永不作為基類
二、編程題
1輸入一個數值作為正方形的邊長,計算正方形的面積,并輸出到屏幕上。要求:
(1)定義一個類,在類中定義無參的構造方法和主方法。(2)定義一個類,在類中定義帶參的構造方法和主方法。
2、重復輸入數據,計算分段函數
?|x|?r?0y=?
22|x|?r??r?x要求:
(1)定義兩個類,在一個類中定義無參的構造方法,在另一個類中定義主方法。(1)定義兩個類,在一個類中定義帶參的構造方法,在另一個類中定義主方法。
3.從鍵盤讀入邊數(side),然后按輸入的邊數畫出一組由排列緊湊的星號組成的正方形。例如,side為4則畫出: * * * * * * * * * * * * 要求:
(1)定義一個類,在類中定義無參的構造方法。
(2)定義有兩個類,在一個類中定義帶參的構造方法,在另一個類中定義主方法。4.打印一個ASCⅡ碼表。
要求定義兩個類,在一個類中定義無參的構造方法,在另一個類中定義主方法。5.重復輸入數據計算正方形、長方形與任意三角形面積(要求使用單一繼承)。
答案 1.(1)答案
namespace ConsoleApplication1 { class Square { Square(){ Console.Write(“Enter length of side for square:”);double len = double.Parse(Console.ReadLine());Console.WriteLine(“Area={0}”, len * len);} public static void Main(){ for(;;){ Square obj = new Square();Console.Write(“Do you want to continue?(y/n)”);string s = Console.ReadLine();if(s.Equals(“n”))break;}
} } }
運行結果:
(2)答案 namespace ConsoleApplication1 { class Square { public static readonly int N = 3;public Square(double len){ Console.WriteLine(“Area={0}”, len * len);} public static void Main(){ for(int i=1;i<=N;i++){ Console.Write(“Enter length of side for square: ”);string s=Console.ReadLine();double length=double.Parse(s);Square obj=new Square(length);} Console.ReadKey();} } } 運行結果:
2.題(1)答案
namespace ConsoleApplication3 { class Function { public Function(){ Console.Write(“Enter value of x and r;”);string[] s = Console.ReadLine().Split();double x = double.Parse(s[0]);double r = double.Parse(s[1]);double y = Math.Abs(x)>= r ? 0 : Math.Sqrt(r * ry;} } static void Main(string[] args){ int x = 30, y = 50, a, b;fun(x, y out a ,out b)Console.WriteLine(“a=”+a +“b=”+b);} } A)50,30 B)30,50 C)80,—20 D)80,20
二、填空題
下面程序的執行結果是()//FunApp2.cs Using System;class FunApp2 { int x = 888, y = 777, z = 666;public FunApp2(){ x++;y++;z++;} public FunApp2(int a, int b, int c){ x = a;y = b;z = c;} } public class FunApp { static void Main();FunApp2 obj1=new FunApp2();Console.Write Line(obj1.x);Console.Write Line(obj1.y);Console.Write Line(obj1.z);FunApp2 obj2=new FunApp2();Console.Write Line(obj2.x);Console.Write Line(obj2.y);Console.Write Line(obj2.z);} }
二、編程題
1,重復輸入任意數據,計算y=
??0
???
r2?x2
|x|??r
|x|?r要求:
(1)使用值參數方法:(2)使用ref參數方法;(3)使用out參數方法;(4)使用ref與out參數方法;(5)使用重載方法;(6)使用重載構造方法;(7)使用可變參數方法;(8)使用靜態方法。
(1)答案: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApplication1 { //YestA
class YTest { public void yMethod(double x, double r){ Console.WriteLine(“y={0}”, Math.Abs(x)> r ? 0 : Math.Sqrt(r * rx * x);} } class YTest {
第四篇:淺談C#程序設計課程的創新教學方法
淺談C#程序設計課程的創新教學方法
【摘要】本文主要討論高職軟件技術專業C#程序設計課程的教學方法,擬將創新學習的理論和實踐應用于課程教學中,分析了接受性學習和創新學習各自的特點和適用知識的范圍。并對課堂教學模式、課后作業布置模式等教學環節提出了一些創新性的看法。
【關鍵詞】教學方法主動學習創新學習課件開發教師學習
【中圖分類號】G71 【文獻標識碼】A 【文章編號】2095-3089(2014)06-0249-01
1.序言
現在很多高職院校的軟件技術專業一般都開設了微軟公司開發的C#程序設計這門課程。學生對C#程序設計課程的學習都存在一定的問題。這門課程和那些傳統的知識型課程對比,有很多不一樣的創新思維過程在里面。因此這門課程的教學肯定不能像其它知識型課程那樣教學,我們必須另想辦法來解決。筆者先后多次擔任《C#程序設計》課程的教學,在教學過程中積累了一些實際的教學心得體會。
2.創新教學的理論
對于C#程序設計課程而言,其語法格式、變量、方法、屬性、封裝、繼承、多態等基本的程序設計技巧和方法都屬于可以采用接受性學習方式的概念性知識。而程序設計實例則是一項典型的創新活動,其主要的知識內涵是如何在現有的知識和方法論的基礎上設計出不存在的知識作品(程序)。這就需要創新教學方法來使學生跟隨你的教學方式。
所謂創新教學并不是與把學生接受性學習絕對對立的,它必須以接受性學習為基礎和前提。創新教學的主要特征就是讓學生以掌握知識的全部內涵為目的,運用邏輯思維,通過再創新教學內容的方式進行,將知識的學習過程變為知識的創新過程。
3.創新教學的實際應用
筆者在實際教學過程中,對于那些理論性的知識,如語法結構、程序結構、觸發事件服務等,筆者采用大量真實有趣的生活實例進行案例教學方法。最后用一個綜合性的簡單程序實例來聯系整門課程的大部分理論和實踐知識,并且將這個實例程序的編寫過程錄制成屏幕錄像形式的動畫文件,在動畫中用注解的方式將教師的講解融入其中,程序設計中的注意事項,要掌握的組件屬性、方法和事件以及其中蘊含的編程技巧、程序的擴展思路和思考問題都在動畫中得以體現。教師上課時可以播放動畫并作針對性講解,這樣就完全避免了這類課程在教學時教師邊操作、邊講解的手足無措的現象。更重要的是,有些學生在上課時經常開小差或請假,下課又搞不懂,他就可以通過下載動畫課件文件在課后反復觀看,就把老師在課堂上的講解重現出來方便學習。這樣就可以將課堂教學直接延伸到了課堂之外,使得教師的知識教學和學生的自主學習可以達到高效而持續的教學目的。筆者的演示課件一般是課堂主要實例的編制全過程錄像加上文字解說,采用的屏幕錄像軟件是由天狼星軟件工作室開發的《屏幕錄像專家》。《屏幕錄像專家》和一般屏幕錄像軟件的最大區別是給制作者更大的靈活性,可以全過程錄制也可以手動選擇重點知識需要的畫面進行錄制,錄制完后還可以很方便地任意剪輯、添加幀以及加入有趣的注解形式,并且在后期還可以適當加入部分配音。更難得的是《屏幕錄像專家》可以生成Flash格式的動畫文件,使得課件文件存儲空間大大減小,一般一個45分鐘的屏幕錄像課件不到5MB。而其他AVI格式的屏幕錄像軟件制作出來的動畫文件則動輒幾十MB甚至一百多BM。
對于軟件技術專業的當代大學生來說,自學是獲取知識的另一次要途徑,它的重要性有時甚至超過課堂學習。筆者指導學生自學主要采用的是專業學習網站和圖書館資料。很多專業教學網站上都包括教材全部的知識點和實例的講解、源代碼甚至習題,學生可以通過這個網站完成初步自學的過程,這就大大減輕了教師課堂教學的壓力。另外通過興趣教學和擴展性很強的課后作業可以督促學生充分地利用互聯網和圖書館等多種途徑去學習課程中所沒有的知識點、方法和技巧,使學生的創新學習能力得到很大的培養。
在最后兩周的實訓教學中,筆者采用的是一種模塊化的教學方式,將最后的那個程序項目分為若干個有序而獨立的子模塊讓學生自己思考,解決了一個子模塊的同學可以上講臺演示和講解,然后在此基礎上進入下一個子模塊,直至問題全部解決,完整的可執行的軟件應用程序項目也就呈現出來。最后,教師對整個過程進行點評。在此過程中,每一個解決模塊的學生必須根據上一個學生的思路來進行,也可以修正上一個同學的不合理的編碼,臺下的同學可以自由參與討論或借鑒別人的經驗,最終目的是讓每個學生完成一個完整的程序作品并上交教師,讓學生覺得心理有很大的滿足感和成就感。
再探索過程是通過課后作業環節來實現的。作業的選題主要包含課程的知識點且有時要高于知識點,其中作業要求也是分層次的,學生能夠做什么就做什么層次的作業。這些層次都是循序漸進、環環相扣的,既體現了程序設計的趣味性又將面向對象的編程思想融入到作業中,更重要的是學生從這些作業的創新編程過程中體會到編程的樂趣和成就感,加深了他們對于程序設計的熱愛,提高了他們的創新思維能力。在筆者的教學實施過程中,課后作業這一環節是非常重要的,它是培養學生學習能力和解決問題能力最主要的教學環節。
4.教師的創新學習
教師的智能結構包括知識結構和能力結構兩方面。創造型教師的知識結構是一種三維立體結構模式,它由知識的廣度、深度和獲取知識的方法三個維度變量組成。知識的廣度意味著創造型教師要具備廣博的科學基礎知識,特別是新興的或邊緣學科知識,能從多角度對自己的專業知識進行審視分析、類比演繹,并且能在多學科交叉的“無人區”發現新問題,開拓新領域。知識的深度意味著創造型教師要具備精深的專業知識,對本專業的新動向和新成果有清晰的了解,并對本專業的課題有一定深度的見解,引導學生進行科學研究與發明創造。獲取知識的方法意味著教師不僅教給學生固定的知識,而且主要的是要教會學生獲得知識的方法。創新型教師就應當具備科學的方法論知識,讓學生更快更有效地學習好科學文化知識。
筆者在任課程教學的之余,經常加強學習,從軟件工程、UML、軟件測試等到各種程序設計語言的各個領域,除此之外,還多次利用暑假的時間深入軟件公司進行真實項目開發,有效拓寬了自己的知識面和研究創新能力,形成扎實的技術功底,在課堂面對學生時才能自信而游刃有余,也才有能力帶領學生進入深入的創新學習的思維中。同時在自己的學習過程中嘗試運用創新方法,使創新方法在課堂的實踐可以循著一條可行的思路,做到有據可依。
5.結論
知識是教師教學和學生學習的共同載體,將知識劃分為理論性知識和程序性知識而采取不同的學習和教學方法,是創新教學法在高職教育中的重要應用原則。接受性學習和創新教學各自適用于不同的知識內涵,而創新教學和教師的創造能力是教學中培養學生創新能力的重要因素。
第五篇:《C#程序設計基礎教程與實訓》習題答案
附錄Ⅰ 各章習題答案
第1章 C#語言概述
一、判斷題
1、√
2、×
3、√
4、×
5、√
6、√
7、×
8、×
二、選擇題
1、C
2、B
3、C
4、A
5、A
6、B
7、B
8、B
三、填空題
1、最新的;面向對象
2、C和C++;JAVA
3、先進設計思想;安全性能
4、靈活性
5、集成開發環境(IDE)——Visual Studio.NET
6、Microsoft.NET Framework(微軟.NET框架體系)
7、最基本的通用語言運行時庫CLR(Common Language Runtime);一些提供了具體功能的類庫
8、需要開發和設計的項目文件;應用程序或組件
四、簡答題
1、① 簡潔易用的語法。② 自動的資源回收機制。③ 與Web的緊密結合。④ 完整的安全性與錯誤處理。⑤ 版本處理技術。⑥ 靈活性和兼容性。
2、C#程序必須包含一個Main方法,Main方法是程序的入口點,程序控制在該方法中開始和結束。該方法用來執行任務,并在任務完成后返回信息。
第2章 常用標準控件
一、判斷題
1、×
2、×
3、√
4、×
5、√
6、×
7、√
8、√
二、選擇題
1、A
2、C
3、B
4、D
5、A
6、B
7、B
8、D
三、填空題
1、輸入/輸出信息
2、屬性
3、事件
4、TextAlign
5、Click
6、文本框(TextBox)
7、保證數據標準化
8、Show
四、簡答題
1、簡述生成控件的操作過程。
(1)單擊工具箱中相應的工具按鈕,這一按鈕呈現被按下狀態,表明被選定。
(2)移動鼠標到窗體上,這時鼠標的指針變成十字形,在需要放置控件的左上角位置按下鼠標左鍵。
(3)在窗體范圍內向下向右拖動鼠標,這時窗體上會顯示一個矩形框,當其大小合適時,松開鼠標左鍵,窗體上就會顯示一個相應大小的這種控件。
另外一種快捷的方法是在工具箱中相應的工具按鈕上雙擊此按鈕,窗體上就會出現一個系統默認大小的所選按鈕。
2、消息框有多少種Button參數設置? OK:只顯示“確定”按鈕
OKCancel:顯示“確定”和“取消”按鈕
AbortRetryIgnore:顯示“終止”、“重試”和“忽略”按鈕 YesNoCancel:顯示“是”、“否”和“取消” YesNo:顯示“是”和“否”
RetryCancel:顯示“重試”和“取消”
第3章 數據類型
一、填空題
1、-2,147,483,648 到 2,147,483,647
2、單精度;雙精度 3、16 4、1 5、99 6、2.2
7、false
8、隱式轉換;顯式轉換
二、判斷題
1、√
2、×
3、×
4、√
5、×
6、×
7、×
8、×
三、選擇題
1、A
2、C
3、D
4、A
5、B
6、B
7、D
8、C
四、簡答題
1.請說明C#標識符命名規則。
(1)不能跟系統關鍵字重名。(2)標識符由字母、下劃線“_”、數字或中文組成。(3)標識符應以字母、中文或下劃線開頭。(4)標識符中間不能包含空格。(5)C#標識符大小寫敏感。
2.請簡單說明銀行家舍入法。
銀行家的舍法與四舍五入只有一點不同,對.5的舍入上,采用取偶數的方式。例:1.25最近的兩個只有1位小數的數字為1.2和1.3,舍入的結果將選擇最后一位為偶數的數字1.2。同理,也可以推斷出1.35舍入后為1.4。
如果在求和計算中使用四舍五入,一直算下去,誤差有可能會越來越大。機會均等才公平,也就是向上和向下各占一半才合理。在大量計算中,從統計角度來看,高一位分別是偶數和奇數的概率正好是50% : 50%。
第4章 運算符和表達式
一、填空題
1、?:
2、0 3、1.1 4、2 5、2 6、2 7、18
8、true
9、false 10、2970
二、判斷題
1、×
2、√
3、×
4、√
5、√
6、×
7、×
8、×
三、選擇題
1、B
2、D
3、B
4、A
5、C
6、C
7、D
8、B
四、簡答題
1.試闡述邏輯運算符 & 和條件運算符 &&之間的區別。
&& 運算符與 & 運算符的區別在于,&& 運算符不能對整型進行計算。另外,對于表達式 x && y 如果 x 為 false,則不計算 y(因為不論 y 為何值,“與”操作的結果都為 false)。這被稱作為“短路”計算。也就是說使用 && 運算符進行條件計算,比使用 & 運算符速度更快些。
2.請從高到低排列【&& 和 ||】、【算術運算符】、【賦值運算符】、【!(非)】、【關系運算符】的優先級順序。答:由高到低的順序為:【!(非)】?【算術運算符】?【關系運算符】?【&& 和 ||】?【賦值運算符】 第5章 條件判斷語句
一、判斷題
1、×
2、√
3、×
4、√
5、√
6、×
7、×
8、√
二、選擇題
1、A
2、C
3、A
4、C
5、B
6、D
7、A
8、C
三、填空題
1、條件判斷語句、循環語句
2、關系表達式、邏輯表達式
3、bool
4、執行大括號里的語句塊;跳過語句塊,執行大括號后面的語句
5、都將會執行
6、只要找到為真的表達式就執行相應的語句塊并跳出整個判斷語句
7、if;switch
8、break
四、簡答題
1、簡單描述if語句的幾種形式。(1)if語句的一般表示形式為: if(表達式){ 語句塊 }(2)當一個判斷語句只存在兩種可能的結果時,可以使用if…else語句來表達。它的表現形式為:
if(表達式){ 語句塊1 }else { 語句塊2 }(3)當一個判斷語句存在多種可能的結果時,可以使用if...else if...語句來表達。它的表現形式為:
if(表達式1){ 語句塊1 } else if(表達式2){ 語句塊2 }...else if(表達式n){ 語句塊n }
2、在switch語句時需要注意什么?
(1)switch關鍵字后面的表達式,其值的類型必須是字符串或整數(char、int、long)都屬于整數類型。
(2)case標簽后面的值必須是常量表達式,不允許使用變量。(3)case和default標簽以冒號而非分號結束。
(4)case標簽后面的語句塊,無論是單條語句還是多條語句,都無需用括號包圍。
(5)default標簽可以有,也可以沒有。case子句的排放順序是無關緊要的,甚至可以把default子句放在最前面。
第6章 循環控制語句
一、填空題
1、順序結構;選擇結構;循環結構
2、false
3、執行循環體;判斷條件是否為真
4、循環的嵌套
5、-5 6、18 7、16 8、1
二、判斷題
1、√
2、×
3、√
4、√
5、√
6、√
7、√
8、×
三、選擇題
1、C
2、B
3、C
4、D
5、B
6、C
7、D
8、B
四、簡答題
1、請說明do...while語句的表現形式。do { 語句塊 } while(表達式);
當流程到達do后,立即執行語句塊,然后再對表達式進行測試。若表達式的值為真,則返回do重復循環,否則退出執行后面的語句。這里特別需要注意的是跟while語句不同,do...while語句的表達式后面要加上分號。
2、for語句的一般表現形式為: for(表達式1;表達式2;表達式3){ 語句塊 } for語句的執行順序如圖所示,其中,當表達式2的值為假時,則直接跳出循環。表達式1:一般情況下用于給循環變量賦初值。
表達式2:返回值必須是一個bool值,作為循環是否繼續執行的條件。表達式3:一般情況下用于給循環變量增值。
第7章 數組
一、選擇題
1、D
2、B
3、A
4、C
5、B
6、A
7、D
8、C
二、填空題
1、類型
2、零
3、new
4、大括號“{}”
5、動態數組
6、引用
7、地址
8、行,列
三、判斷題
1、√
2、×
3、√
4、√
5、√
6、×
7、√
8、×
四、簡答題
1.請簡述什么是數組?
答:數組是具有相同類型的一組數據。數組按照數組名、數據元素的類型和維數來進行描述。當訪問數組中的數據時,可以通過下標來指明。
2.請簡述Array和ArrayList主要的區別?
(1)Array 的容量是固定的,而 ArrayList的容量可根據需要自動擴充。
(2)ArrayList提供添加、插入或移除某一范圍元素的方法。在 Array 中,您只能一次獲取或設置一個元素的值。
(3)Array 可以具有多個維度,而 ArrayList始終只是一維的。
第8章 GDI+圖形
一、填空題
1、GDI+
2、Graphics
3、Pen,Brush
4、Rectangle,RectangleF
5、Point
6、DrawPolygon,FillPolygon
7、橢圓
8、Paint
二、判斷題
1、√
2、×
3、×
4、×
5、√
6、√
7、×
8、×
三、選擇題
1、B
2、B
3、A
4、D
5、C
6、A
7、A
8、D
四、簡答題
1.試闡述Graphics圖形對象的幾種創建方法。
(1)用某控件或窗體的CreateGraphics方法來創建Graphic對象,該對象表示該控件或窗體的繪圖表面。如果想在已存在的窗體或控件上繪圖,則可以使用此方法。
(2)接收對圖形對象的引用,該對象為窗體或控件的Paint事件中PaintEventArgs的一部份。在為控件創建繪制代碼時,通常使用此方法來獲取對圖形對象的引用。
2.請簡述使用虛擬畫布繪圖的步驟。(1)在內存中建立一塊“虛擬畫布”如:(2)獲取這塊內存畫布的Graphics引用:(3)在這塊內存畫布上繪圖:(4)將內存畫布畫到窗口中:
第9章 方法
一、選擇題
1、B
2、D
3、A
4、C
5、C
6、A
7、B
8、D
二、填空題
1、return
2、void
3、值參數
4、數組型
5、重載
6、形參,實參
7、成員變量
8、遞歸
三、判斷題
1、√
2、√
3、√
4、√
5、×
6、√
7、×
8、×
四、簡答題
1.請簡述用方法構造代碼的好處?
(1)方法允許將程序分為不連續的邏輯單元。調試單獨的單元與調試不包含方法的整個程序相比要容易的多。
(2)可以在其他程序中使用為某個程序開發的方法,而通常只需要進行少量修改,甚至不需修改。
2.請簡述什么是遞歸?
答:在方法中直接或間接地調用自己叫方法的遞歸調用。樹型關系問題的求解往往需要使用到遞歸算法。
3.請簡述什么是方法的重載?
答:當定義兩種或多種具有相同名稱的方法時,就稱作重載。在調用時,編譯器會根據不同的方法簽名調用相應的方法。
第10章 窗體與控件
一、選擇題
1、B
2、C
3、C
4、D
5、B
6、A
7、D
8、C
二、填空題
1、窗體
2、Maximized
3、Load
4、true
5、CheckedChanged
6、ListBox
7、Image
8、Interval
三、判斷題
1、√
2、×
3、√
4、√
5、×
6、×
7、√
8、×
四、簡答題
1.請簡述組合框的使用特點?
答:當需要用戶在多個選項中選擇一項時,除可以使用單選按鈕外,還可以使用組合框(ComboBox)。組合框是TextBox與ListBox的組合,具有列表框和文本框的大部份屬性。組合框在列表框中列出可供用戶選擇的項,另外還有一個文本框。當列表框中沒有所需選項時,允許在文本框中用鍵盤輸入用戶自定義的內容。
2.請列出圖片框(PictureBox)支持哪幾種類型的圖像?并進行簡單的說明。a)位圖(bitmap):是將圖像定義為像素的圖案,這種圖像格式體積很大,未經壓縮。位圖文件的擴展名是.bmp或.dib。b)圖標(icon):是特殊類型的位圖。圖標的最大尺寸為32×32像素。圖標文件的擴展名是.ico。
c)Windows文件(metafile):將圖形定義為編碼的線段和圖形。普通圖元文件擴展名為.wmf,增強圖元文件擴展名為.emf。
d)GIF:由CompuServe開發的一種壓縮位圖格式,是Internet上流行的一種文件格式。e)JPEG:是一種支持8位和24位顏色的壓縮位圖格式。也是Internet上流行的一種文件格式。
第11章 界面設計
一、選擇題
1、C
2、B
3、C
4、D
5、C
6、D
7、A
8、B
二、填空題
1、單文檔(SDI)應用程序,多文檔(MDI)應用程序
2、ShowIcon,ShowInTaskbar,FormBorderStyle3、DialogResult4、非模式
5、菜單欄,菜單標題,菜單項
6、MenuItem,ComboBox,Separator,TextBox
7、MDI 子窗口
8、Cascade,TileHorizontal
三、判斷題
1、×
2、√
3、√
4、×
5、√
6、×
7、×
8、√
四、簡答題
1.請簡述非模式窗體和模式窗體的區別。
(1)打開一個非模式窗體后,用戶可以跟應用程序的其他部分交流,而模式窗體不行。這意味著,程序在執行到創建模式窗體的代碼時,會停下來等待模式窗體關閉后再繼續往下執行。而程序在打開非模式窗體的同時會繼續往下執行后面的代碼。(2)非模式窗體沒有返回值,模式窗體有返回值。
(3)關閉非模式窗體會直接在內存中釋放窗體,而模式窗體則不會。
(4)非模式窗體使用Show方法創建,模式窗體使用ShowDialog方法創建。
2.簡述創建一個MDI應用程序的方法。
(1)把作為MDI父窗體的窗體的IsMDIContainer 屬性設置為True。(2)新建一個窗體(假設窗體名為Form2)作為MDI子窗體。(3)在MDI父窗體中調用如下代碼即可顯示一個MDI子窗體。
Form2 f2 = new Form2();f2.MdiParent = this;f2.Show();第12章 異常處理
一、選擇題
1、B
2、B
3、D
4、A
5、C
6、A
7、D
8、C
二、填空題
1、try,catch,finally
2、try-catch3、一個,一個或多
4、Exception
5、改變編譯器的設置,使用校驗(checked)語句
6、The operation overflows at complie time in checked mode
7、異常處理程序,清理代碼
8、顯式地標明了它所作用的語句塊或表達式不需要進行溢出檢查
三、判斷題
1、×
2、×
3、√
4、×
5、√
6、√
7、√
8、√
四、簡答題
1.導致代碼失敗的具體原因有哪些?
答:算術溢出、堆棧溢出、內存不足、參數越界、數組索引越界、試圖訪問已經釋放的資源(例如訪問一個已經關閉的文件)等。
2.在catch語句里可以使用哪幾種方法處理異常來獲得不同的執行路徑? a)不寫任何跳轉代碼:這種方法使得系統忽略異常,程序會繼續往下執行。b)使用return語句:它使得程序直接跳出方法體,回到調用方法的地方。c)使用throw 語句:它使得異常再次被拋出,表示當前異常處理代碼無法處理此類異常,將異常轉給更上一級的異常處理程序進行處理
d)使用System.Environment.Exit(1)語句:它將直接關閉應用程序,一般情況下不使用這樣的方法