1
HO CHI MINH UNIVERSITY OF INDUSTRY
Computer Science & Engineering Department
LAB REPORT
Windows 1 Programming
Student:NGUYỄN QUỐC TÚ
ID:09194131
Class:NCTH3A
2
Contents
I) Chapter 1: Module 1 4
1) Exercise 1: 4
2) Exercise 2: 6
3) Exercise 3: 7
4) Exercise 4: 8
5) Exercise 5: 10
6) Exercise 6: 12
7) Exercise 7: 14
8) Exercise 8: 15
9) Exercise 9: 17
10) Exercise 10: 19
II) Chapter 2: Module 2 20
1) Exercise 1: 21
2) Exercise 2: 23
3) Exercise 3: 25
4) Exercise 4: 28
5) Exercise 5: 28
6) Exercise 6: 31
7) Exercise 7: 35
8) Exercise 8: 38
9) Exercise 9: 38
10) Exercise 10: 41
11) Exercise 11: 43
12) Exercise 12: 45
13) Exercise 13: 48
14) Exercise 14: 54
15) Exercise 15: 64
3
16) Exercise 16: 64
17) Exercise 17: 69
18) Exercise 18: 69
19) Exercise 19: 70
20) Exercise 20: 70
21) Exercise 21: 70
22) Exercise 22: 70
III) Chapter 3: Module 3 70
1) Exercise 1: 70
2) Exercise 2: 73
3) Exercise 3: 76
4) Exercise 4: 76
5) Exercise 5: 82
6) Exercise 6: 85
7) Exercise 7: 89
8) Exercise 8: 92
9) Exercise 9: 92
10) Exercise 10: 92
11) Exercise 11: 92
12) Exercise 12: 92
IV) Chapter 4: Module 4 92
1) Exercise 1: 92
2) Exercise 2: 92
3) Exercise 3: 92
4) Exercise 4: 92
5) Exercise 5: 92
6) Exercise 6: 92
7) Exercise 7: 92
4
V) Chapter V: Module 5 96
1) Exercise 1: 96
2) Exercise 2: 100
3) Exercise 3: 100
4) Exercise 4: 100
5) Exercise 5: 100
VI) Chapter VI: Module 6 101
1) Exercise 1: 101
2) Exercise 2: 106
VII) Chapter VII: Module 7 107
1) Exercise 1: 107
2) Exercise 2: 114
3) Exercise 3: 114
4) Exercise 4: 114
I) Chapter 1: Module 1
Exercise 1:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace bai1
{
5
class Program
{
/// <summary>
/// sử dụng (console.writeline để xuất ra và console.readline để kết thúc)
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
Console.WriteLine("Welcome to");
Console.WriteLine("C# 2010 Programming!");
Console.WriteLine("Programming by nguyen quoc tu");
Console.ReadLine();
}
}
}
KQ:
6
Exercise 2:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace bai2
{
class Program
{
/// <summary>
/// sử dụng (console.writeline để xuất ra và console.readline để kết thúc)
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
Console.WriteLine("{0}\n{1}","Welcome to ", "C# 2010 Programming!");
Console.WriteLine("Programming by nguyen quoc tu");
Console.ReadLine();
}
}
}
7
KQ:
Exercise 3:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace bai3_
{
class hieu
{
static void Main(string[] args)
{
int so1, so2, hieu = 0;
Console.Clear();
Console.Write("nhap so thu 1:");
//chuyển đổi kiểu dl từ chuỗi sang số kiểu int
so1 = Convert.ToInt32(Console.ReadLine());
8
Console.Write("nhap so thu 2:");
so2 = Convert.ToInt32(Console.ReadLine());
//tính hiệu 2 số
hieu = so1 - so2;
//kết quả trả về
Console.Write("hieu cua" + so1 + "va" + so2 + "la:" + hieu);
Console.ReadLine();
}
}
}
KQ:
Exercise 4:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace bai4
{
9
class Program
{
static void Main(string[] args)
{
//khai báo biến
int dai, rong, cv = 0, dt = 0;
Console.Clear();
Console.WriteLine("***************tinh cv va dien tich**************");
Console.Write("nhap chieu dai:");
//chuyển dl từ chuổi sang số
dai = Convert.ToInt32(Console.ReadLine());
Console.Write("nhap chieu rong:");
rong = Convert.ToInt32(Console.ReadLine());
//hàm tíh chu vi
cv = (dai + rong) * 2;
//xuất ra chu vi
Console.WriteLine("chu vi="+cv);
//hàm tính diện tích
dt = dai * rong;
//xuất ra diện tích
Console.Write("dien tich=" + dt);
Console.ReadLine();
}
10
}
}
KQ:
Exercise 5:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace bai5
{
class ptb1
{
static void Main(string[] args)
{
//khai báo biến
int a, b;
float x;
11
Console.Clear();
Console.WriteLine("******GIAI VA BIEN LUAN PTBAC 1******");
Console.Write("nhap vao a:");
//chuyển đổi dl từ chuổi sang số
a = Convert.ToInt32(Console.ReadLine());
Console.Write("nhap vao b:");
b = Convert.ToInt32(Console.ReadLine());
//hàm kt nghiệm pt bậc nhất
if (a == 0)
if (b == 0)
Console.Write("phuong trinh vo so nghiem");
else
Console.Write("phuong trinh vo nghiem");
else
{
x = (float)-b / a;
Console.Write("phuong trinh co nghiem la:" + x);
}
Console.ReadLine();
}
}
}
KQ:
12
Exercise 6:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace bai6
{
class ptb2
{
static void Main(string[] args)
{
//khai báo biến kiểu double
double a, b, c;
double x1,x2,dt=0;
Console.Clear();
Console.WriteLine("********GIAI PHUONG TRINH BAC 2*********");
Console.Write("nhap vao a:");
//chuyển dl từ chuỗi sang số
13
a = Convert.ToDouble(Console.ReadLine());
Console.Write("nhap vao b:");
b = Convert.ToDouble(Console.ReadLine());
Console.Write("nhao vao c:");
c = Convert.ToDouble(Console.ReadLine());
//hàm tính detal
dt=Math.Pow(b,2)-(4*a*c);
//hàm kiểm tra nghiệm ptb2
if (dt < 0)
Console.Write("phuong trinh vo nghiem.");
else if (dt == 0)
Console.Write("phuong trinh co nghiem kep x1=x2=:" + (-b) / (2 * a));
else
{
x1 = ((-b) + Math.Sqrt(dt)) / 2 * a;
x2 = ((-b) - Math.Sqrt(dt)) / 2 * a;
Console.WriteLine("phuong trinh co 2 nghiem
phanbiet:\n"+"x1="+Math.Round(x1,2)+"\n"+"x2="+Math.Round(x2,2));
}
Console.ReadLine();
}
}
}
14
KQ
:
Exercise 7:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace bai7
{
class cachanluonggiac
{
static void Main(string[] args)
{
//khai báo biến
double fx;
Console.Clear();
Console.WriteLine("*******cac ham luong giac********");
Console.Write("nhap vao 1 goc :");
15
//chuyển dl từ chuổi sang double
fx = Convert.ToDouble(Console.ReadLine());
double rad = fx * Math.PI / 180;
//hàm tính sin
Console.WriteLine("sin({0}={1})", fx, Math.Sin(rad));
//hàm tính cos
Console.WriteLine("cos({0}={1})", fx, Math.Cos(rad));
//tính rad
Console.WriteLine("tan({0}={1})", fx, Math.Tan(rad));
//tính cos rad
Console.WriteLine("cogtan({0}={1})", fx, Math.Cos(rad)/Math.Sin(rad));
Console.ReadLine();
}
}
}
KQ:
Exercise 8:
using System;
using System.Collections.Generic;
16
using System.Linq;
using System.Text;
namespace bai8
{
class cvdttamgiac
{
static void Main(string[] args)
{
//khai báo biến
double a, b, c,cv=0,dt=0,p=0;
Console.Clear();
Console.Write("nhap vao a:");
//chuyển dl từ chuổi sang số kiểu double
a = Convert.ToDouble(Console.ReadLine());
Console.Write("nhap vao b:");
b = Convert.ToDouble(Console.ReadLine());
Console.Write("nhap vao c:");
c = Convert.ToDouble(Console.ReadLine());
//kiểm tra các cạnh tam giác có tạo thàng tam giác ko
if (a > 0 && b > 0 && c > 0 && (a + b > 0) && (b + c > 0) && (a + c > b))
{
cv = a + b + c;
Console.WriteLine("chu vi cua tam giac la:" + cv);
17
p = cv / 2;
dt = Math.Sqrt(p * (p - a) * (p - b) * (p - c));
Console.Write("dien tich cua tam giac la:" + dt);
}
else
Console.Write("khong tao thanh tam giac");
Console.ReadLine();
}
}
}
KQ:
Exercise 9:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace bai9
18
{
class TinhTongChuoiSo
{
static void Main(string[] args)
{
//khai báo biến
double x, n, mu=1, gt=1,tong=0;
Console.Write("nhap vao x:");
//chuyển dl từ chuổi sang số
x = Convert.ToDouble(Console.ReadLine());
Console.Write("nhap vao n:");
n = Convert.ToDouble(Console.ReadLine());
for (int i = 1; i <= n; i++)
{
//hàm tính
mu = Math.Pow(x, i);
gt = gt * i;
tong = tong + (mu / gt);
}
Console.WriteLine("tong S(x,n)="+Math.Round(tong,3));
Console.ReadLine();
}
19
}
}
KQ:
Exercise 10:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace bai10
{
class Program
{
static void Main(string[] args)
{
Console.Clear();
Console.WriteLine("***********chó và gà*************");
Console.WriteLine("vua ga vua cho ");
Console.WriteLine("bo lai cho tron");
Console.WriteLine("ba muoi sau con");
20
Console.WriteLine("mot tram chan chang");
for(int i=1;i<=25;i++)
if ((i * 4 + (36 - i) * 2) == 100)
{
int tong=(i+(36-i));
Console.WriteLine("\nso gà=" + (36 - i) + "\nso chó=" + i+"\ntong ga
vacho:"+(36-i)+"+"+i+"="+tong);
tong = (2 * (36 - i) + 4 * i);
Console.WriteLine("\nso gà=" + 2*(36 - i) + "\nso chó=" + 4*i +
"\ntongga va cho:" + 2*(36 - i) + "+" + 4*i + "=" + tong);
}
Console.ReadLine();
}
}
}
KQ:
II) Chapter 2: Module 2
21
1)Exercise 1:
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 bai1
{
public partial class Frm : Form
{
public Frm()
{
InitializeComponent();
}
/// <summary>
/// khi click vao button hiển thị thì nội dung của textbox
/// password se hiển thị dưới textbox hiển thị
/// </summary>
/// <param name="sender"></param>
22
/// <param name="e"></param>
private void btnhienthi_Click(object sender, EventArgs e)
{
txthienthi.Text = txtpassword.Text;
}
/// <summary>
/// button tiếp thực hiện chức năng xóa dữ liệu trong 2 textbox
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btntiep_Click(object sender, EventArgs e)
{
txthienthi.Text = "";
txtpassword.Clear();
txtpassword.Focus();
}
/// <summary>
/// thoát chương trình
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btndong_Click(object sender, EventArgs e)
{
this.Close();
23
}
}
}
KQ:
2)Exercise 2:
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 bai2
{
public partial class Frm_simpleevenclick : Form
24
{
public Frm_simpleevenclick()
{
InitializeComponent();
}
/// <summary>
/// hiển thị thông báo khi click vào button
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnclickme_Click(object sender, EventArgs e)
{
MessageBox.Show("Button was clicked. ");
}
/// <summary>
/// xuất hiện thông báo khi form được load lên
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show("Hi , Welcome to C# 2010 programming!");
}
/// <summary>
25
/// xuất hiện thông báo khi click vào form
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Frm_simpleevenclick_Click_1(object sender, EventArgs e)
{
MessageBox.Show("Form was clicked.");
}
}
}
KQ:
3)Exercise 3:
using System;