-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
111 lines (87 loc) · 2.68 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
class Question
{
public Question(string text, string[] choices, string answer)
{
this.Text = text;
this.Choices = choices;
this.Answer = answer;
}
public string Text { get; set; }
public string[] Choices { get; set; }
public string Answer { get; set; }
public bool checkAnswer (string answer)
{
return this.Answer.ToLower() == answer.ToLower();
}
}
class Quiz
{
public Quiz(Question[] questions)
{
this.Questions = questions;
this.QuestionIndex = 0;
this.Score = 0;
}
private Question[] Questions { get; set; }
private int QuestionIndex { get; set; }
private int Score { get; set; }
private Question GetQuestion()
{
return this.Questions[this.QuestionIndex];
}
public void DisplayQuestion()
{
var question = this.GetQuestion();
this.DisplayProgress();
Console.WriteLine($"Soru {this.QuestionIndex+1}: {question.Text}");
foreach (var c in question.Choices)
{
Console.WriteLine($"-{c}");
}
Console.Write("cevap:");
var result = Console.ReadLine();
this.Guess(result);
}
private void Guess(string answer)
{
var question = this.GetQuestion();
if (question.checkAnswer(answer))
{
Score++;
}
this.QuestionIndex++;
if (this.Questions.Length == this.QuestionIndex)
{
this.DisplayScore();
}
else
{
this.DisplayQuestion();
}
}
private void DisplayScore()
{
Console.WriteLine($"Skor: {this.Score}");
}
private void DisplayProgress()
{
int totalQuestion = this.Questions.Length;
int questionNumber = this.QuestionIndex + 1;
if(totalQuestion>=questionNumber) {
Console.WriteLine($"Question {questionNumber} of {totalQuestion}");
}
}
}
internal class Program
{
private static void Main(string[] args)
{
var q1 = new Question("Mod alma işlemini aşağıdaki karakterlerden hangisi gerçekleştirir?", new string[] { "A) >", "B) !", "C) %", "D) &" }, "C");
var q2 = new Question("Program boyunca sabit kalacak veriyi hangi kelime ile tanımlarız?", new string[] { "A) FLOAT", "B) DOUBLE", "C) BOOL", "D) CONST" }, "D");
var q3 = new Question("Aşağıdakilerden hangisi veri tiplerinden değildir?", new string[] { "A) STRİNG", "B) SLONG", "C) İNT", "D) BYTE" }, "B");
var questions = new Question[] { q1, q2, q3 };
var quiz = new Quiz(questions);
quiz.DisplayQuestion();
}
}