CS202 бие даалт 3

Тодорхойлох зүйлс:

  • 1ш интерфэйс
  • 1ш хийсвэр класс
  • Тухайн хийсвэр классаас удамшиж үүссэн 1 ш класс

for/while/if/switch, override, overload заавал байна.

Tic tic toe C#

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;
using System.Configuration;

namespace tic_tac_game
{
public partial class Form1 : Form
{
Graphics g1;
Rectangle[] rt;
Bitmap b1, b2, b3;

int t = 0, k = 0, tt = 0, count = 0;
string st1=”o”, st2=”x”, st3;
string[,] str = new string[3, 3];
public Form1()
{

InitializeComponent();
label1.Text = t.ToString();
ConfigurationSettings.AppSettings.Set(“people”, “3”);
this.Text = ConfigurationSettings.AppSettings[“people”];
}

private void NewMatt() {

str[0, 0] = str[0, 1] = str[0, 2] = str[1, 0] = str[1, 1] = str[1, 2] = str[2, 0] = str[2, 1] = str[2, 2] = “k”;
}
private string hojil(){

int i, j;
string st=”k”;
i = 0; j = 0;
if (str[i, j] + str[i + 1, j + 1] + str[i + 2, j + 2] == “ooo” || str[i, j] + str[i + 1, j + 1] + str[i + 2, j + 2] == “xxx”) st = str[i, j];

return st;
}
private void Form1_Load(object sender, EventArgs e)
{
st1 = “o”;
st2 = “x”;
b1 = new Bitmap(“pic02.jpg”);
b2 = new Bitmap(“pic01.jpg”);
b3 = new Bitmap(“pic03.jpg”);
NewMatt();
panel1.Size = b1.Size;
g1 = panel1.CreateGraphics();

rt = new Rectangle[9];
rt[0] = new Rectangle(79, 60, 85, 85);
rt[1] = new Rectangle(170, 60, 85, 85);
rt[2] = new Rectangle(261, 60, 85, 85);

rt[3] = new Rectangle(79, 151, 85, 85);
rt[4] = new Rectangle(170, 151, 85, 85);
rt[5] = new Rectangle(261, 151, 85, 85);
rt[6] = new Rectangle(79, 242, 85, 85);
rt[7] = new Rectangle(170, 242, 85, 85);
rt[8] = new Rectangle(261, 242, 85, 85);

button1_Click(null,null);
}

private void button1_Click(object sender, EventArgs e)
{
NewMatt();
st1 = “o”;
st2 = “x”;
b2 = new Bitmap(“pic01.jpg”);
b3 = new Bitmap(“pic03.jpg”);
g1.DrawImage(b1, 0, 0, b1.Width, b1.Height);
count = 0;
}

private void panel1_MouseClick(object sender, MouseEventArgs e)
{
Bitmap bpp;

if (rt[0].Contains(e.X, e.Y)) { g1.DrawImage(b2, rt[0]); str[0,0]=st1;}
if (rt[1].Contains(e.X, e.Y)) { g1.DrawImage(b2, rt[1]); str[0, 1] = st1; }
if (rt[2].Contains(e.X, e.Y)) { g1.DrawImage(b2, rt[2]); str[0, 2] = st1; }
if (rt[3].Contains(e.X, e.Y)) { g1.DrawImage(b2, rt[3]); str[1, 0] = st1; }
if (rt[4].Contains(e.X, e.Y)) { g1.DrawImage(b2, rt[4]); str[1, 1] = st1; }
if (rt[5].Contains(e.X, e.Y)) { g1.DrawImage(b2, rt[5]); str[1, 2] = st1; }
if (rt[6].Contains(e.X, e.Y)) { g1.DrawImage(b2, rt[6]); str[2, 0] = st1; }
if (rt[7].Contains(e.X, e.Y)) { g1.DrawImage(b2, rt[7]); str[2, 1] = st1; }
if (rt[8].Contains(e.X, e.Y)) { g1.DrawImage(b2, rt[8]); str[2, 2] = st1; }
st3=st1; st1=st2; st2=st3;
bpp = b2; b2 = b3; b3 = bpp;

if (hoj() != “k”)
if (hoj() == “x” || hoj() == “o”)
MessageBox.Show(“Hojloo”);
}

 

private string hoj()
{
string st = “k”;
if (str[0, 0] + str[0, 1] + str[0, 2] == “xxx” ||
str[0, 0] + str[0, 1] + str[0, 2] == “ooo”)
st = str[0, 0];

return st;
}
}
}

Employee class

public class Employee {
String lastName;
String firstName;
String socialNumber;
int birthYear;
int birthMonth;
int birthDay;
private double salary;
Employee() {

}
Employee( String firstName ) {
this.firstName = firstName;
}
String getLastName() {
return lastName;
}
String getFirstName() {
return firstName;
}
String getSocialNumber() {
return socialNumber;
}
int getBirthYear() {
return birthYear;
}
int getBirthMonth() {
return birthMonth;
}
int getBirthDay() {
return birthDay;
}
void setLastName( String lastName ) {
this.lastName = lastName;
}
void setFirstName( String firstName ) {
this.firstName = firstName;
}
void setSocialNumber( String socialNumber ) {
this.socialNumber = socialNumber;
}
void setBirthYear(int birthYear ) {
this.birthYear = birthYear;
}
void setBirthMonth( int birthMonth ) {
this.birthMonth = birthMonth;
}
void setBirthDay( int birthDay ) {
this.birthDay = birthDay;
}
double getSalary() {
return salary;
}
void setSalary( double salary ) {
this.salary = salary;
}
}

IT213 тооны машин

Эндээс тооны машины код татаж авна уу.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Calculator tooniiMashin = new Calculator();
Application.Run(tooniiMashin);
}
}
class Calculator : Form
{
double cdblCurrTotal = 0.0;
bool cblnReplace = false;
string cstrLastOperation = “”;

private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Button button8;
private System.Windows.Forms.Button button9;
private System.Windows.Forms.Button button10;
private System.Windows.Forms.Button button11;
private System.Windows.Forms.Button button12;
private System.Windows.Forms.Button button13;
private System.Windows.Forms.Button button14;
private System.Windows.Forms.Button button15;
private System.Windows.Forms.Button button16;
private System.Windows.Forms.Button button17;
private System.Windows.Forms.Button button18;
private System.Windows.Forms.Button button19;
private System.Windows.Forms.Button button20;
private System.Windows.Forms.Button button21;
private System.Windows.Forms.Button button22;
private System.Windows.Forms.Button button23;
private System.Windows.Forms.Button button24;
private System.Windows.Forms.Button button25;
private System.Windows.Forms.Button button26;
private System.Windows.Forms.Button button27;

public Calculator()
{
Ehleh();
}

private void Ehleh()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.button8 = new System.Windows.Forms.Button();
this.button9 = new System.Windows.Forms.Button();
this.button10 = new System.Windows.Forms.Button();
this.button11 = new System.Windows.Forms.Button();
this.button12 = new System.Windows.Forms.Button();
this.button13 = new System.Windows.Forms.Button();
this.button14 = new System.Windows.Forms.Button();
this.button15 = new System.Windows.Forms.Button();
this.button16 = new System.Windows.Forms.Button();
this.button17 = new System.Windows.Forms.Button();
this.button18 = new System.Windows.Forms.Button();
this.button19 = new System.Windows.Forms.Button();
this.button20 = new System.Windows.Forms.Button();
this.button21 = new System.Windows.Forms.Button();
this.button22 = new System.Windows.Forms.Button();
this.button23 = new System.Windows.Forms.Button();
this.button24 = new System.Windows.Forms.Button();
this.button25 = new System.Windows.Forms.Button();
this.button26 = new System.Windows.Forms.Button();
this.button27 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(25, 21);
this.textBox1.Name = “textBox1”;
this.textBox1.Size = new System.Drawing.Size(240, 20);
this.textBox1.TabIndex = 0;
//
// button1
//
this.button1.ForeColor = System.Drawing.Color.Red;
this.button1.Location = new System.Drawing.Point(25, 56);
this.button1.Name = “button1”;
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = “Backspace”;
this.button1.UseVisualStyleBackColor = true;
//
// button2
//
this.button2.ForeColor = System.Drawing.Color.Red;
this.button2.Location = new System.Drawing.Point(106, 56);
this.button2.Name = “button2”;
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 2;
this.button2.Text = “CE”;
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.ForeColor = System.Drawing.Color.Red;
this.button3.Location = new System.Drawing.Point(187, 56);
this.button3.Name = “button3”;
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 3;
this.button3.Text = “C”;
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.ForeColor = System.Drawing.Color.Red;
this.button4.Location = new System.Drawing.Point(23, 85);
this.button4.Name = “button4”;
this.button4.Size = new System.Drawing.Size(35, 28);
this.button4.TabIndex = 4;
this.button4.Text = “MC”;
this.button4.UseVisualStyleBackColor = true;
//
// button5
//
this.button5.Location = new System.Drawing.Point(64, 85);
this.button5.Name = “button5”;
this.button5.Size = new System.Drawing.Size(35, 28);
this.button5.TabIndex = 5;
this.button5.Text = “7”;
this.button5.UseVisualStyleBackColor = true;
//
// button6
//
this.button6.Location = new System.Drawing.Point(105, 85);
this.button6.Name = “button6”;
this.button6.Size = new System.Drawing.Size(35, 28);
this.button6.TabIndex = 6;
this.button6.Text = “8”;
this.button6.UseVisualStyleBackColor = true;
//
// button7
//
this.button7.Location = new System.Drawing.Point(146, 85);
this.button7.Name = “button7”;
this.button7.Size = new System.Drawing.Size(35, 28);
this.button7.TabIndex = 7;
this.button7.Text = “9”;
this.button7.UseVisualStyleBackColor = true;
//
// button8
//
this.button8.Location = new System.Drawing.Point(187, 85);
this.button8.Name = “button8”;
this.button8.Size = new System.Drawing.Size(35, 28);
this.button8.TabIndex = 8;
this.button8.Text = “/”;
this.button8.UseVisualStyleBackColor = true;
//
// button9
//
this.button9.ForeColor = System.Drawing.Color.Red;
this.button9.Location = new System.Drawing.Point(228, 85);
this.button9.Name = “button9”;
this.button9.Size = new System.Drawing.Size(35, 28);
this.button9.TabIndex = 9;
this.button9.Text = “sqrt”;
this.button9.UseVisualStyleBackColor = true;
//
// button10
//
this.button10.ForeColor = System.Drawing.Color.Red;
this.button10.Location = new System.Drawing.Point(228, 119);
this.button10.Name = “button10”;
this.button10.Size = new System.Drawing.Size(35, 28);
this.button10.TabIndex = 15;
this.button10.Text = “%”;
this.button10.UseVisualStyleBackColor = true;
//
// button11
//
this.button11.Location = new System.Drawing.Point(187, 119);
this.button11.Name = “button11”;
this.button11.Size = new System.Drawing.Size(35, 28);
this.button11.TabIndex = 14;
this.button11.Text = “*”;
this.button11.UseVisualStyleBackColor = true;
//
// button12
//
this.button12.Location = new System.Drawing.Point(146, 119);
this.button12.Name = “button12”;
this.button12.Size = new System.Drawing.Size(35, 28);
this.button12.TabIndex = 13;
this.button12.Text = “6”;
this.button12.UseVisualStyleBackColor = true;
//
// button13
//
this.button13.Location = new System.Drawing.Point(105, 119);
this.button13.Name = “button13”;
this.button13.Size = new System.Drawing.Size(35, 28);
this.button13.TabIndex = 12;
this.button13.Text = “5”;
this.button13.UseVisualStyleBackColor = true;
//
// button14
//
this.button14.Location = new System.Drawing.Point(64, 119);
this.button14.Name = “button14”;
this.button14.Size = new System.Drawing.Size(35, 28);
this.button14.TabIndex = 11;
this.button14.Text = “4”;
this.button14.UseVisualStyleBackColor = true;
//
// button15
//
this.button15.ForeColor = System.Drawing.Color.Red;
this.button15.Location = new System.Drawing.Point(23, 119);
this.button15.Name = “button15”;
this.button15.Size = new System.Drawing.Size(35, 28);
this.button15.TabIndex = 10;
this.button15.Text = “MR”;
this.button15.UseVisualStyleBackColor = true;
//
// button16
//
this.button16.ForeColor = System.Drawing.Color.Red;
this.button16.Location = new System.Drawing.Point(228, 153);
this.button16.Name = “button16”;
this.button16.Size = new System.Drawing.Size(35, 28);
this.button16.TabIndex = 21;
this.button16.Text = “1/x”;
this.button16.UseVisualStyleBackColor = true;
//
// button17
//
this.button17.Location = new System.Drawing.Point(187, 153);
this.button17.Name = “button17”;
this.button17.Size = new System.Drawing.Size(35, 28);
this.button17.TabIndex = 20;
this.button17.Text = “-“;
this.button17.UseVisualStyleBackColor = true;
//
// button18
//
this.button18.Location = new System.Drawing.Point(146, 153);
this.button18.Name = “button18”;
this.button18.Size = new System.Drawing.Size(35, 28);
this.button18.TabIndex = 19;
this.button18.Text = “3”;
this.button18.UseVisualStyleBackColor = true;
this.button18.Click += new System.EventHandler(this.button18_Click);
//
// button19
//
this.button19.Location = new System.Drawing.Point(105, 153);
this.button19.Name = “button19”;
this.button19.Size = new System.Drawing.Size(35, 28);
this.button19.TabIndex = 18;
this.button19.Text = “2”;
this.button19.UseVisualStyleBackColor = true;
this.button19.Click += new System.EventHandler(this.button19_Click);
//
// button20
//
this.button20.Location = new System.Drawing.Point(64, 153);
this.button20.Name = “button20”;
this.button20.Size = new System.Drawing.Size(35, 28);
this.button20.TabIndex = 17;
this.button20.Text = “1”;
this.button20.UseVisualStyleBackColor = true;
this.button20.Click += new System.EventHandler(this.button20_Click);
//
// button21
//
this.button21.ForeColor = System.Drawing.Color.Red;
this.button21.Location = new System.Drawing.Point(23, 153);
this.button21.Name = “button21”;
this.button21.Size = new System.Drawing.Size(35, 28);
this.button21.TabIndex = 16;
this.button21.Text = “MS”;
this.button21.UseVisualStyleBackColor = true;
//
// button22
//
this.button22.ForeColor = System.Drawing.Color.Red;
this.button22.Location = new System.Drawing.Point(228, 187);
this.button22.Name = “button22”;
this.button22.Size = new System.Drawing.Size(35, 28);
this.button22.TabIndex = 27;
this.button22.Text = “=”;
this.button22.UseVisualStyleBackColor = true;
this.button22.Click += new System.EventHandler(this.button22_Click);
//
// button23
//
this.button23.Location = new System.Drawing.Point(187, 187);
this.button23.Name = “button23”;
this.button23.Size = new System.Drawing.Size(35, 28);
this.button23.TabIndex = 26;
this.button23.Text = “+”;
this.button23.UseVisualStyleBackColor = true;
this.button23.Click += new System.EventHandler(this.button23_Click);
//
// button24
//
this.button24.Location = new System.Drawing.Point(146, 187);
this.button24.Name = “button24”;
this.button24.Size = new System.Drawing.Size(35, 28);
this.button24.TabIndex = 25;
this.button24.Text = “.”;
this.button24.UseVisualStyleBackColor = true;
//
// button25
//
this.button25.Location = new System.Drawing.Point(105, 187);
this.button25.Name = “button25”;
this.button25.Size = new System.Drawing.Size(35, 28);
this.button25.TabIndex = 24;
this.button25.Text = “+/-“;
this.button25.UseVisualStyleBackColor = true;
//
// button26
//
this.button26.Location = new System.Drawing.Point(64, 187);
this.button26.Name = “button26”;
this.button26.Size = new System.Drawing.Size(35, 28);
this.button26.TabIndex = 23;
this.button26.Text = “0”;
this.button26.UseVisualStyleBackColor = true;
//
// button27
//
this.button27.ForeColor = System.Drawing.Color.Red;
this.button27.Location = new System.Drawing.Point(23, 187);
this.button27.Name = “button27”;
this.button27.Size = new System.Drawing.Size(35, 28);
this.button27.TabIndex = 22;
this.button27.Text = “M+”;
this.button27.UseVisualStyleBackColor = true;
//
// Form1
//
this.ClientSize = new System.Drawing.Size(285, 235);
this.Controls.Add(this.button22);
this.Controls.Add(this.button23);
this.Controls.Add(this.button24);
this.Controls.Add(this.button25);
this.Controls.Add(this.button26);
this.Controls.Add(this.button27);
this.Controls.Add(this.button16);
this.Controls.Add(this.button17);
this.Controls.Add(this.button18);
this.Controls.Add(this.button19);
this.Controls.Add(this.button20);
this.Controls.Add(this.button21);
this.Controls.Add(this.button10);
this.Controls.Add(this.button11);
this.Controls.Add(this.button12);
this.Controls.Add(this.button13);
this.Controls.Add(this.button14);
this.Controls.Add(this.button15);
this.Controls.Add(this.button9);
this.Controls.Add(this.button8);
this.Controls.Add(this.button7);
this.Controls.Add(this.button6);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Name = “Calculator”;
this.Text = “Calculator”;
}
private void button2_Click(object sender, EventArgs e)
{
cdblCurrTotal = 0.0;
textBox1.Text = “0.”;
}

private void button3_Click(object sender, EventArgs e)
{
textBox1.Text = “0.”;
}

private void button20_Click(object sender, EventArgs e)
{
CreateValue(“1”);
}

private void button19_Click(object sender, EventArgs e)
{
CreateValue(“2”);
}

private void button18_Click(object sender, EventArgs e)
{
CreateValue(“3”);
}

private void button23_Click(object sender, EventArgs e)
{
cdblCurrTotal += Convert.ToDouble(textBox1.Text);
cblnReplace = true;
cstrLastOperation = “+”;
}

private void button22_Click(object sender, EventArgs e)
{
switch (cstrLastOperation)
{
case “+”:
cdblCurrTotal += Convert.ToDouble(textBox1.Text);
textBox1.Text = cdblCurrTotal.ToString();
break;
}

}
private void CreateValue(string strCurrNum)
{
if ((textBox1.Text == “0.”) || (textBox1.Text == “”) || cblnReplace)
textBox1.Text = strCurrNum + “.”;
else
textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length – 1) + strCurrNum + “.”;
cblnReplace = false;
}

}
}

CS202 Хичээлийн оюутнуудад

Moodle дээр шинээр эрх үүсгүүлсэн оюутнууд өөрсдийн оюутны кодоор нэвтэрнэ үү. Нууц үг: Test12345; 

Нууц үгээ мартаад сэргээлгэсэн оюутнууд Test111; нууц үгээр нэвтэрнэ үү.