Sunteți pe pagina 1din 34

Colegiul Național “Spiru Haret” Gorj

ARBORI C++
LUCRARE PENTRU ATESTAREA COMPETENŢELOR
PROFESIONALE

Elevi: Sburlea Maria Roxana și Mitroi Robert Daniel


Profesor îndrumător: Dabelea Delia
Sesiunea: mai 2020
Clasa: a XII-a F
Profil: matematică-informatică intensiv informatică
Cuprins

Argument......................................................................1
Noțiuni teoretice...........................................................2
Grafuri neorientate...............................................2
Arbori....................................................................3
Prezentarea proiectului................................................7
Sursa............................................................................14
Bibliografie...................................................................34
Argument

Tema aleasă pentru această lucrare de atestat este cazul


particular al grafurilor neorientate, acela de arbori. Am ales această
temă deoarece arborii facilitează transpunerea datelor ce au aplicații
în diverse domenii: proiectarea circuitelor electrice, determinarea
celui mai scurt drum dintre doua localități, rețelele sociale, etc.

Am creat acest soft educațional pentru a veni în sprijinul


persoanelor ce doresc să învețe cum funcționează aceștia și cum pot
sa-i pună în practică. Acest soft este adecvat pentru toate categoriile
de vârstă, punând la dispoziție atât teorie cat și exercitii, un joc și un
test.

Softul dispune de modalități interactive de învățare,


simplificând întregul proces, fiind mereu stimulat de metodele
distractive pe care noi le-am ales. Astfel, după parcurgerea teoriei,
utilizatorul poate să aprofundeze ceea ce a învățat prin exerciții atât
rezolvate cât și nerezolvate, printr-un joc recreativ, în final având
posibilitatea de a-și teste cunoștințele printr-un test cu 10 întrebări.

1
Noțiuni teoretice

 Grafuri neorientate

Definiție: Se numește graf neorientat o pereche ordonată de mulțimi


G=(X,U), unde:

o X este o mulțime finită și nevidă de elemente numite vârfuri sau


noduri;
o U este o mulțime finită de submulțimi cu două elemente din X,
numite muchii.

Două vârfuri între care există muchie se numesc adiacente.

Mulțimea muchiilor are proprietatea de simetrie: dacă [x,y] este muchie,


atunci și [y,x] este muchie.

Conform definiției:

 într-un graf neorientat nu există muchie de la un vârf la el însuși;


 intre două vârfuri distincte există cel mult o muchie.

Definiție: Într-un graf neorientat se numește grad al unui vârf numărul de


vârful adiacente cu acesta (sau numărul de muchii incidente cu acesta). Gradul
unui vărf x se notează d(x) (degree).

Teoremă: Într-un graf neorientat, suma gradelor tuturor vârfurilor este dublul
numărului de muchii.

2
Observații:

 un vârf cu gradul 0 se numește izolat.


 un vârf cu gradul 1 se numește terminal;
 gradul maxim al unui vârf într-un graf cu n vârfuri este n-1.

Consecințe:

 Suma gradelor tuturor vârfurilor este număr par.


 Într-un graf neorientat, numărul de vârfuri de grad impar este
întotdeauna par.

Definiție: Un graf neorientat se numește graf conex dacă pentru oricare două
vârfuri x și y diferite ale sale, există cel puțin un lanț care le leagă, adică x este
extremitatea inițială și y este extremitatea finală.

Un graf cu un singur nod este, prin definiție, conex.

3
 Arbori

Arborii sunt structuri de date dinamice şi omogene. Cele mai comune


utilizări ale arborilor sunt căutarea în volume mari de date şi reprezentarea
de structuri organizate ierarhic.

Definiție: Se numește arbore un graf conex și aciclic.

Exemplu:

Observații:

 Un arbore cu n vârfuri are n-1 muchii.


 Un arbore este un graf conex și minimal cu această proprietate;
dacă s-ar mai elimina o muchie, graful nu ar mai fi conex.
 Un arbore este un graf aciclic și maximal cu această proprietate;
dacă s-ar mai adăuga o muchie, s-ar obține un ciclu.

Un graf parțial care este arbore se numește arbore parțial.

Un graf care nu conține cicluri se mai numește pădure. Într-o pădure


fiecare componentă conexă este arbore.

4
Prezentarea proiectului

 Mediu de învățare

5
6
7
o Joc

8
o Răspuns corect

o Răspuns greșit

9
 Test

10
11
Sursa
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DoubleBuffered = true;
}

private void Form1_Load(object sender, EventArgs e)


{
DoubleBuffered = true;
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
Form2 test = new Form2();
test.Show();
}

private void button2_Click(object sender, EventArgs e)


{

private void inv_Click(object sender, EventArgs e)


{
DoubleBuffered = true;
teorie1.BringToFront();
teorie1.Visible = true;
}

}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class Form2 : Form

12
{
public Form2()
{
InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)


{

private void Form2_FormClosing(object sender, FormClosingEventArgs e)


{
Form1 meniu = new Form1();
meniu.Show();
}

private void userControl11_Load(object sender, EventArgs e)


{

}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}

private void Form3_Load(object sender, EventArgs e)


{

}
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class exnerez : Form

13
{
public exnerez()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)


{
this.Close();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class exrez : UserControl
{
public exrez()
{
InitializeComponent();
}

private void next_Click(object sender, EventArgs e)


{
pictureBox1.Visible=false;
next.Visible = false;
button5.Visible = true;
pictureBox3.Visible = true;

private void button5_Click_1(object sender, EventArgs e)


{
pictureBox3.Visible = false;
pictureBox1.Visible = true;
next.Visible = true;
button5.Visible = false;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class exrezo : Form

14
{
public exrezo()
{
InitializeComponent();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class final : Form
{
public final()
{
InitializeComponent();
}

private void final_Load(object sender, EventArgs e)


{

private void final_FormClosed(object sender, FormClosedEventArgs e)


{
joc j = new joc();
j.Close();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class intr1 : Form
{
public intr1()
{
InitializeComponent();
}

private void textBox1_TextChanged(object sender, EventArgs e)


{

15
private void button1_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class intr2 : Form
{
public intr2()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
this.DialogResult = DialogResult.OK;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class intr3 : Form
{
public intr3()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
this.DialogResult = DialogResult.OK;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;

16
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class intr4 : Form
{
public intr4()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
this.DialogResult = DialogResult.OK;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class intr5 : Form
{
public intr5()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
this.DialogResult = DialogResult.OK;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class joc : Form
{
public int scor = 0;
int nr=0;
int sus, sus2,sus3,sus4,sus5;

17
int st, st2, st3, st4, st5;
public joc()
{
InitializeComponent();
DoubleBuffered = true;
sus = button1.Top;
st = button1.Left-45;
sus2 = button2.Top;
st2 = button2.Left-45;
sus3 = button3.Top;
st3 = button3.Left-45;
sus4 = button4.Top;
st4 = button4.Left-45;
sus5 = button5.Top;
st5 = button5.Left - 45;
}
string rezultat;
private void button4_Click(object sender, EventArgs e)
{
button4.Enabled = false;
nr++;
intr4 in4 = new intr4();
if (in4.ShowDialog(this) == DialogResult.OK)
{
this.rezultat = in4.textBox1.Text;
if (rezultat.Equals("1"))
{
MessageBox.Show("Raspuns corect!");
scor++;
timer4.Start();
}
else
{
MessageBox.Show("Raspuns gresit!");
Image poza = new Bitmap(@"C:\Users\roxi\Pictures\stricat.png");
button4.BackgroundImage = poza;
}
}
in4.Dispose();
if (nr==5)
{
final fin = new final();
if(scor==1)
fin.label1.Text = "Felicitari! Ai obtinut: " + scor + " punct!";
else
fin.label1.Text = "Felicitari! Ai obtinut: " + scor + " puncte!";
fin.Show();
}
}
private void timer4_Tick(object sender, EventArgs e)
{
cos.Visible = true;
cos.Left = st4;
cos.Top = 400;
if (sus4 < 300) { sus4 += 6; button4.Top = sus4; }
else
if (sus4 < 425)
{
sus4 += 8;
button4.Top = sus4;
}
if (sus4 >= 435)

18
{
timer4.Stop();
cos.Visible = false;
button4.Visible = false;
}
else if (sus4 >= 425) sus4 += 5;
}

private void timer5_Tick(object sender, EventArgs e)


{
cos.Visible = true;
cos.Left = st5;
cos.Top = 400;
if (sus5 < 300) { sus5 += 6; button5.Top = sus5; }
else
if (sus5 < 425)
{
sus5 += 8;
button5.Top = sus5;
}
if (sus5 >= 435)
{
timer5.Stop();
cos.Visible = false;
button5.Visible = false;
}
else if (sus5 >= 425) sus5 += 5;
}

private void button5_Click(object sender, EventArgs e)


{
button5.Enabled = false;
nr++;
intr5 in5 = new intr5();
if (in5.ShowDialog(this) == DialogResult.OK)
{
this.rezultat = in5.textBox1.Text;
if (rezultat.Equals("3"))
{
MessageBox.Show("Raspuns corect!");
scor++;
timer5.Start();
}
else
{
MessageBox.Show("Raspuns gresit!");
Image poza = new Bitmap(@"C:\Users\roxi\Pictures\stricat.png");
button5.BackgroundImage = poza;
}
}
in5.Dispose();
if (nr == 5)
{
final fin = new final();
if (scor == 1)
fin.label1.Text = "Felicitari! Ai obtinut: " + scor + " punct!";
else
fin.label1.Text = "Felicitari! Ai obtinut: " + scor + " puncte!";
fin.Show();
}
}

19
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
nr++;
intr1 in1 = new intr1();
if(in1.ShowDialog(this)==DialogResult.OK)
{
this.rezultat = in1.textBox1.Text;
if (rezultat.Equals("2"))
{
MessageBox.Show("Raspuns corect!");
scor++;
timer1.Start();
}
else
{
MessageBox.Show("Raspuns gresit!");
Image poza = new Bitmap(@"C:\Users\roxi\Pictures\stricat.png");
button1.BackgroundImage = poza;
}
}
in1.Dispose();
if (nr == 5)
{
final fin = new final();
if (scor == 1)
fin.label1.Text = "Felicitari! Ai obtinut: " + scor + " punct!";
else
fin.label1.Text = "Felicitari! Ai obtinut: " + scor + " puncte!";
fin.Show();
}
}

void timer1_Tick(object sender, EventArgs e)


{
cos.Visible = true;
cos.Left = st;
cos.Top = 400;
if (sus < 300) { sus += 4; button1.Top = sus; }
else
if (sus < 425)
{
sus += 6;
button1.Top = sus;
}
if (sus >= 435)
{
timer1.Stop();
cos.Visible = false;
button1.Visible = false;
}
else if(sus>=425) sus += 5;
}
string rezultat2;
private void button2_Click(object sender, EventArgs e)
{
button2.Enabled = false;
nr++;
intr2 in2 = new intr2();
if (in2.ShowDialog(this) == DialogResult.OK)
{

20
this.rezultat2 = in2.textBox1.Text;
if (rezultat2.Equals("19"))
{
MessageBox.Show("Raspuns corect!");
scor++;
timer2.Start();
}
else
{
MessageBox.Show("Raspuns gresit!");
Image poza = new Bitmap(@"C:\Users\roxi\Pictures\stricat.png");
button2.BackgroundImage = poza;
}
}
in2.Dispose();
if (nr == 5)
{
final fin = new final();
if (scor == 1)
fin.label1.Text = "Felicitari! Ai obtinut: " + scor + " punct!";
else
fin.label1.Text = "Felicitari! Ai obtinut: " + scor + " puncte!";
fin.Show();
}
}
string rezultat3;
private void button3_Click(object sender, EventArgs e)
{
button3.Enabled = false;
nr++;
intr3 in3 = new intr3();
if (in3.ShowDialog(this) == DialogResult.OK)
{
this.rezultat3 = in3.textBox1.Text;
if (rezultat3.Equals("171"))
{
MessageBox.Show("Raspuns corect!");
scor++;
timer3.Start();
}
else
{
MessageBox.Show("Raspuns gresit!");
Image poza = new Bitmap(@"C:\Users\roxi\Pictures\stricat.png");
button3.BackgroundImage = poza;
}
}
in3.Dispose();
if (nr == 5)
{
final fin = new final();
if (scor == 1)
fin.label1.Text = "Felicitari! Ai obtinut: " + scor + " punct!";
else
fin.label1.Text = "Felicitari! Ai obtinut: " + scor + " puncte!";
fin.Show();
}
}

private void timer3_Tick(object sender, EventArgs e)


{
cos.Visible = true;

21
cos.Left = st3;
cos.Top = 400;
if (sus3 < 300) { sus3 += 5; button3.Top = sus3; }
else
if (sus3 < 380)
{
sus3 += 8;
button3.Top = sus3;
}
else if (sus3 < 425)
{
sus3 += 11;
button3.Top = sus3;
}
if (sus3 >= 435)
{
timer3.Stop();
cos.Visible = false;
button3.Visible = false;
}
else if (sus3 >= 425) sus3 += 5;
}

private void timer2_Tick(object sender, EventArgs e)


{
cos.Visible = true;
cos.Left = st2;
cos.Top = 400;
if (sus2 < 300) { sus2 += 5; button2.Top = sus2; }
else
if (sus2 < 380)
{
sus2 += 8;
button2.Top = sus2;
}
else if(sus2<425)
{
sus2 +=11;
button2.Top = sus2;
}
if (sus2 >= 435)
{
timer2.Stop();
cos.Visible = false;
button2.Visible = false;
}
else if (sus2 >= 425) sus2 += 5;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{

22
public partial class teorie : UserControl
{
public teorie()
{
InitializeComponent();
DoubleBuffered = true;
}

private void teorie_Load(object sender, EventArgs e)


{
DoubleBuffered = true;
}

private void exercitiiB_Click(object sender, EventArgs e)


{

private void teorieB_Click(object sender, EventArgs e)


{
DoubleBuffered = true;
panel1.SendToBack();
teorie11.Visible = true;
teorie11.BringToFront();
}

private void jocB_Click(object sender, EventArgs e)


{
joc x = new joc();
x.Show();
}
private void exnerB_Click(object sender, EventArgs e)
{

exnerez a = new exnerez();


a.Show();
}

private void exrezB_Click(object sender, EventArgs e)


{

exrezo ex = new exrezo();


ex.Show();
}

private void button2_Click(object sender, EventArgs e)


{
DoubleBuffered = true;
this.Hide();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

23
namespace WindowsFormsApp1
{
public partial class teorie1 : UserControl
{
public teorie1()
{
InitializeComponent();
DoubleBuffered = true;
}

private void button2_Click(object sender, EventArgs e)


{
this.Hide();
}

private void button3_Click(object sender, EventArgs e)


{
teorie21.Show();
teorie21.BringToFront();
}
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class teorie2 : UserControl
{
public teorie2()
{
InitializeComponent();
DoubleBuffered = true;
}
private void teorie2_Load(object sender, EventArgs e)
{
DoubleBuffered = true;
}
private void n1_Click(object sender, EventArgs e)
{
pictureBox2.Visible = true;
DoubleBuffered = true;
}

private void n3_Click(object sender, EventArgs e)


{
pictureBox3.Visible = true;
DoubleBuffered = true;
}

private void n5_Click(object sender, EventArgs e)


{
pictureBox3.Visible = true;

24
DoubleBuffered = true;
}

private void n5_Click_1(object sender, EventArgs e)


{

private void n7_Click(object sender, EventArgs e)


{
pictureBox4.Visible = true;
DoubleBuffered = true;
}

private void n8_Click(object sender, EventArgs e)


{
pictureBox5.Visible = true;
DoubleBuffered = true;

private void n9_Click(object sender, EventArgs e)


{
pictureBox5.Visible = true;
}

private void n10_Click(object sender, EventArgs e)


{
pictureBox5.Visible = true;
}

private void button2_Click(object sender, EventArgs e)


{
this.Hide();
}

private void n4_Click(object sender, EventArgs e)


{

private void n2_Click(object sender, EventArgs e)


{

private void n6_Click(object sender, EventArgs e)


{

private void n5_Click_2(object sender, EventArgs e)


{

}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;

25
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApp1
{
public partial class test2 : UserControl
{
public test2()
{
InitializeComponent();
}

private void test2_Load(object sender, EventArgs e)


{

string[] intr = new string[]


{
"Ce este un arbore?", "Din ce este compus un arbore?", "Câte frunze are
arborele cu rădăcină descris prin " +
"următorul vector ”de taţi”:(6,5,5,2,0,3,3,3,8, 7, 7)",
"Se consideră un graf neorientat cu 80 de noduri şi 3560 muchii. " +
"Care este numărul de muchii ce pot fi eliminate" +
" astfel încât graful parţial obţinut să fie arbore?","Ce reprezita
radacina unui arbore?",
"Care este gradul maxim posibil şi care este" +
" gradul minim posibil pentru un nod dintr-un" +
" arbore cu n noduri?", "Într-un graf orientat cu 7 noduri suma gradelor"
+
" interioare ale tuturor nodurilor este " +
"egală cu 10. Care este valoarea sumei " +
"gradelor exterioare ale tuturor nodurilor? ",
"Un nod este frunza daca:","Care sunt nodurile care au exact 2 descendenţi " +
"pentru un arbore cu rădăcină, cu 7 noduri, " +
"numerotate de la 1 la 7, dat de vectorul de ”taţi”: " +
"(3,3,0,1,2,2,4)?","Se consideră un arbore cu 11 muchii." +
"Care este numărul de noduri ale arborelui?"
};

string[] rasp = new string[]


{
"un caz particular al grafurilor " +
"neorientate","un copac","un caz particular al grafurilor" +
" orientate","o variabila",
"dintr-o serie de noduri " +
"interconectate in care se " +
"gasesc informatii","dintr-o serie de muchii " +
"interconectate " +
"intre ele","din doua " +
"sau mai multe grafuri","din mai multe caractere",
"4","2","5","6",
"3488","3481","2560","3555",
"un nod special care " +
"are un singur fiu","nodul de pe nivelul " +
"cel mai de jos al arborelui","un nod special care " +
"ajuta la delimitarea " +
"arborelui pe nivele","nodul cu numarul 1",

26
"gradul maxim este 4, " +
"iar gradul minim este 1","gradul maxim este 3, " +
"iar gradul minim este 1","gradul maxim este 3, " +
"iar gradul minim este 2","gradul maxim este 4 iar " +
"gradul minim este 2",
"5","10","20","6",
"nu are niciun fiu","este legat direct de radacina","se afla pe nivelul
2"," are doar un fiu",
"2,4,1","2,5","2,3","2,4",
"10","11","12","9"
};
string ans;
int i = -1;
int a = 0;
int scor = 0;
private void start_Click(object sender, EventArgs e)
{
pictureBox1.Visible = false;
label1.Visible = true;
ok.Visible = true;
ok2.Visible = true;
ok3.Visible = true;
ok4.Visible = true;
raspunde.Visible = true;
label3.Visible = true;
if (i < intr.Length-1)
i++;
label1.Text = intr[i];
label3.Text = Convert.ToString(i+1)+"/10";
ok.Text = rasp[a];
a++;
ok2.Text = rasp[a];
a++;
ok3.Text = rasp[a];
a++;
ok4.Text = rasp[a];
a++;
start.Visible = false;
if (i == 9)
{ button1.Visible = true; }
}
string getSelectedAnswer()
{
if (ok.Checked)
return ok.Text.ToString();
if (ok2.Checked)
return ok2.Text.ToString();
if (ok3.Checked)
return ok3.Text.ToString();
if (ok4.Checked)
return ok4.Text.ToString();
return "";
}

private void raspunde_Click(object sender, EventArgs e)


{
ans = getSelectedAnswer();
SqlConnection con = new SqlConnection(@"Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\WindowsFormsApp1\WindowsFormsApp1\qu
iz.mdf;Integrated Security=True");
SqlCommand cmd = new SqlCommand(@"insert into [raspunsuri] values('" + ans
+ "')", con);

27
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Raspuns inregistrat!");
SqlCommand cmd1 = new SqlCommand("SELECT [raspunsuri].[raspuns],
[rcorecte].[rcorect] FROM [rcorecte] INNER JOIN ( SELECT TOP 1 [raspuns] FROM
[raspunsuri] order by ID DESC) AS [raspunsuri] ON [raspunsuri].[raspuns]=[rcorecte].
[rcorect]", con);
SqlDataAdapter sda1 = new SqlDataAdapter(cmd1);
DataTable dt = new DataTable();
sda1.Fill(dt);
if (dt.Rows.Count > 0)
{
SqlCommand cmd2 = new SqlCommand(@"INSERT INTO [intrebari]
([intrebare]) values('corect') ", con);
con.Open();
cmd2.ExecuteNonQuery();
con.Close();
scor++;
}
else
{
SqlCommand cmd2 = new SqlCommand(@"INSERT INTO [intrebari]
([intrebare]) values('incorect') ", con);
con.Open();
cmd2.ExecuteNonQuery();
con.Close();

}
if (i == 9) start.Visible = false;
else
{
start.Visible = true;
start.Text = "Next";
}

private void button1_Click(object sender, EventArgs e)


{
SqlConnection con = new SqlConnection(@"Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\WindowsFormsApp1\WindowsFormsApp1\qu
iz.mdf;Integrated Security=True");
SqlCommand cmd4 = new SqlCommand(@"SELECT TOP 1 intrebare FROM intrebari
ORDER BY ID DESC",con);
SqlDataAdapter sda = new SqlDataAdapter(cmd4);
DataTable dt = new DataTable();
sda.Fill(dt);
MessageBox.Show("Raspunsul este " +dt.Rows[0][0] + "!");
}

private void button1_Click_1(object sender, EventArgs e)


{
MessageBox.Show("Ai obtinut "+Convert.ToString(scor)+" puncte!");
SqlConnection con2 = new SqlConnection(@"Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\WindowsFormsApp1\WindowsFormsApp1\Da
tabase1.mdf;Integrated Security=True");
con2.Open();
SqlCommand cmd = new SqlCommand(@"INSERT INTO [punctaje](Punctaj)
values('" + scor + "')", con2);
cmd.ExecuteNonQuery();
con2.Close();

28
}
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApp1
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}

private void UserControl1_Load(object sender, EventArgs e)


{
disp_data();
}

SqlConnection con = new SqlConnection(@"Data


Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\WindowsFormsApp1\WindowsFormsApp1\Da
tabase1.mdf;Integrated Security=True");
private void button1_Click_1(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
if (String.IsNullOrEmpty(nume_txt.Text) ||
String.IsNullOrEmpty(prenume_txt.Text))
MessageBox.Show("INTRODU DATELE!");
else
{
cmd.CommandText = "insert into [Table] (Nume, Prenume) values('" +
nume_txt.Text + "','" + prenume_txt.Text + "')";
cmd.ExecuteNonQuery();
MessageBox.Show("INREGISTRARE EFECTUATA!");
Form3 a = new Form3();
a.Show();
}
con.Close();
}
public void disp_data()
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT [Table].Nume,[Table].Prenume,punctaje.Punctaj
FROM [Table] INNER JOIN punctaje ON [Table].ID=[punctaje].Id";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);

29
da.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
}

private void dataGridView1_CellContentClick(object sender,


DataGridViewCellEventArgs e)
{

private void button2_Click(object sender, EventArgs e)


{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT [Table].Nume,[Table].Prenume,punctaje.Punctaj
FROM [Table] INNER JOIN punctaje ON [Table].ID=[punctaje].Id";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
}
}
}

30
Resurse de hard şi soft necesare

Soft-ul a fost realizat cu ajutorul programului Microsoft Visual Studio.


Acest soft este optimizat să funcţioneze pe orice tip de computer care dispune
de sistemul de operare Windows cu platforma .NET preinstalată. .NET este o
platformă softare, realizată la Microsoft, destinată dezvolatării de aplicații. Cele
mai importante caracteristici ale acestei platforme sunt următoarele:

 Programatorii au la dispoziţie o serie de limbaje de programare de


nivel înalt din care pot alege. Printre limbajele puse la dispoziţie de Microsoft
se numără şi C#, fiind dezvoltat o dată cu platforma .NET.

 Pot fi dezvoltate o varietate largă de aplicaţii, de la programe pentru


desktop până la aplicaţii pentru dispozitive mobile, aplicaţii şi servicii web sau
servicii Windows, de la programe izolate şi până la sisteme distribuite de
dimensiuni mari.

 Mediul de execuţie este strict controlat de un motor de execuţie, care


oferă o serie de facilităţi ce ridică mult nivelul de calitate a aplicaţiilor
(managementul automat al memoriei şi securitatea fiind primele două care ies
în evidenţă).

31
Bibliografia

 https://www.pbinfo.ro/
 http://ase.softmentor.ro/StructuriDeDate/06_Arbori.htm
 https://invata.info/2017/04/02/arbori-c/

32

S-ar putea să vă placă și