-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCplusplus.dart
162 lines (146 loc) · 5.96 KB
/
Cplusplus.dart
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import 'package:quizzapp/FailPage.dart';
import 'package:quizzapp/QuestionsC.dart';
import 'package:quizzapp/PassPage.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class Cplusplus extends StatefulWidget {
@override
State<Cplusplus> createState() => _CplusplusState();
}
class _CplusplusState extends State<Cplusplus> {
List<IconData> scoreKeeper =[];
List<Questions> questionsBank=[
Questions(q: ' In C++, the "cin" object is used for output', a: false),
Questions(q: ' The "break" statement is used to terminate the loop and skip the remaining iterations', a: true),
Questions(q: ' C++ supports both single-line (//) and multi-line (/* */) comments', a: true),
Questions(q: ' The "malloc" function is used in C++ to allocate memory for variables', a: false),
Questions(q: ' In C++, the "class" and "struct" keywords are used interchangeably to define user-defined data types', a: true),
Questions(q: ' A reference variable in C++ is a pointer to another variable', a: true),
Questions(q: ' The "cin" object is used for formatted output in C++', a: false),
Questions(q: ' The "++" operator increments the value of a variable by 2', a: false),
Questions(q: ' In C++, a function can only return a single value', a: true),
Questions(q: ' A pointer in C++ is a variable that stores the memory address of another variable', a: true),
];
int questionnumber=0;
int totalnumber=0;
int t=0;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
flex:5,
child: Padding(
padding:EdgeInsets.all(10) ,
child: Center(
child: Text(
questionsBank[questionnumber].questiontext,
textAlign: TextAlign.center,
style:GoogleFonts.rajdhani(fontSize: 30,color: Colors.white,
),
),
),
),
),
Card(
color:Colors.green,
child: FloatingActionButton(
backgroundColor:Colors.green,
elevation: 0,
child:Text(
'True',
textAlign: TextAlign.center,
style:GoogleFonts.rajdhani(fontSize: 25,color: Colors.white,fontWeight: FontWeight.bold
),
),
onPressed: (){
bool correctans =questionsBank[questionnumber].questionanswer;
if (correctans==true){
t=t+1;
scoreKeeper.add(Icons.check);
}
else {
t=t;
scoreKeeper.add(Icons.close);
}
setState(() {
questionnumber++;
print('questionnumber: $questionnumber');
print('t: $t');
if (questionnumber == questionsBank.length-1 )
{
if( t >7 || t<10) {
Navigator.push(context,
MaterialPageRoute(
builder: (context) => PassPage()));
} else if( t<7 ) {
Navigator.push(context,
MaterialPageRoute(
builder: (context) => FailPage()));
}else{}
}});
},
),
),
Card(
color:Colors.red,
child: FloatingActionButton(
backgroundColor:Colors.red,
child:Text(
'False',
textAlign: TextAlign.center,
style:GoogleFonts.rajdhani(fontSize: 25,color: Colors.white,fontWeight: FontWeight.bold
),
),
elevation: 0,
onPressed: (){
bool correctans =questionsBank[questionnumber].questionanswer;
if (correctans==false){
t=t+1;
scoreKeeper.add(Icons.check);}
else {
t=t;
scoreKeeper.add(Icons.close);
}
setState(() {
questionnumber++;
print('questionnumber: $questionnumber');
print('t: $t');
if (questionnumber == questionsBank.length-1 ){
if( t<7 ) {
Navigator.push(context,
MaterialPageRoute(
builder: (context) => FailPage()));
} else if( t >7 || t<10) {
Navigator.push(context,
MaterialPageRoute(
builder: (context) => PassPage()));
} else{} }
});},
),
),
Row(
children: scoreKeeper.map((iconData) {
if (iconData == Icons.check) {
return Icon(
iconData,
color: Colors.green, // Change this to the desired color for correct answers
);
} else if (iconData == Icons.close) {
return Icon(
iconData,
color: Colors.red, // Change this to the desired color for incorrect answers
);
}
return Container(); // Return an empty container if the iconData is invalid
}).toList(),
)
],
),
);
}
}