-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampletest.cpp
More file actions
165 lines (151 loc) · 4.4 KB
/
Copy pathExampletest.cpp
File metadata and controls
165 lines (151 loc) · 4.4 KB
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
163
164
165
#include <iostream>
#include <conio.h>
using namespace std;
class TButton{
public:
char name[50];
int fg,bg;
TButton(int f=96,int b=40){
fg=f;
bg=b;
}
void Name(char *n,int i){
for(int I=0;I<i;I++){
name[I]=n[I];
}
name[i]='\0';
}
};
int function(int no,int opsize,char *p,int x , int y,int line){
TButton A[no];
for(int i=0;i<no;i++){
char a[opsize];
for(int j=0;j<opsize;j++){
a[j]=*(p+50*i+j);
}
A[i].Name(a,opsize);
}
static int count=1;
char M;
while(1){
for(int i=0;i<no;i++){
if(i+1!=count){
printf("\033[0m\033[%d;%dm\033[%d;%dH %s \n",A[i].fg,A[i].bg,i+1+y,x,A[i].name);
}
else{
printf("\033[0m\033[%d;%dm\033[%d;%dH %s \n",106,97,i+1+y,x,A[i].name);
}
}
M=getch();
if(M=='w'||M=='W'){count--;}
else if(M=='s'||M=='S'){count++;}
else if(M=='e'||M=='E'){
if(line==1){
for(int i=0;i<no;i++){
if(i+1!=count){
printf("\033[0m\033[%d;%dm\033[%d;%dH %s \033[%d;%dm \n",A[i].fg,A[i].bg,i+1+y,x,A[i].name,106,97);
}
else{
printf("\033[0m\033[%d;%dm\033[%d;%dH %s \n",106,97,i+1+y,x,A[i].name);
}
}
}
break;
}
if(count<1){
count=no;
}
else if(count>no){
count=1;
}
}
return count;
}
int Option1(){
int options=5;
int optionsize=9;
char *p=new char[50*options];
char a[options][optionsize]={{"Calcium "},{"Carbon "},{"Nitrogen"},{"Oxygen "},{"Hydrogen"}};
for(int i=0;i<options;i++){
int j=0;
for(j=0;j<optionsize;j++){
*(p+i*50+j)=a[i][j];
}
*(p+i*50+j+1)='\0';
}
return function(options,optionsize,p,0,2,0);
}
int Option2(){
int options=5;
int optionsize=3;
char *p=new char[50*options];
char a[options][optionsize]={{"Ca"},{"C "},{"N "},{"O "},{"He"}};
for(int i=0;i<options;i++){
int j=0;
for(j=0;j<optionsize;j++){
*(p+i*50+j)=a[i][j];
}
*(p+i*50+j+1)='\0';
}
return function(options,optionsize,p,0,9,0);
}
int Option3(){
int options=5;
int optionsize=7;
char *p=new char[50*options];
char a[options][optionsize]={{"Yellow"},{"White "},{"Red "},{"Green "},{"Brown "}};
for(int i=0;i<options;i++){
int j=0;
for(j=0;j<optionsize;j++){
*(p+i*50+j)=a[i][j];
}
*(p+i*50+j+1)='\0';
}
return function(options,optionsize,p,0,16,0);
}
int Option4(){
int options=5;
int optionsize=2;
char *p=new char[50*options];
char a[options][optionsize]={{"3"},{"5"},{"4"},{"2"},{"6"}};
for(int i=0;i<options;i++){
int j=0;
for(j=0;j<optionsize;j++){
*(p+i*50+j)=a[i][j];
}
*(p+i*50+j+1)='\0';
}
return function(options,optionsize,p,0,23,0);
}
int Option5(){
int options=5;
int optionsize=7;
char *p=new char[50*options];
char a[options][optionsize]={{"Honey "},{"Cerial"},{"Jelly "},{"Chips "},{"Cake "}};
for(int i=0;i<options;i++){
int j=0;
for(j=0;j<optionsize;j++){
*(p+i*50+j)=a[i][j];
}
*(p+i*50+j+1)='\0';
}
return function(options,optionsize,p,0,30,0);
}
int main(){
int marks=0;
cout<<"\033[96;40m QUIZ TEST "<<endl;
cout<<"\033[96;40m1. Which element is said to keep bones strong?";
if(Option1()==1){marks++;}
cout<<endl<<"\033[96;40m2. What is the atomic sign for Helium on the periodic table?";
if(Option2()==5){marks++;}
cout<<endl<<"\033[96;40m3. What is the color of blood when it's inside your body?";
if(Option3()==3){marks++;}
cout<<endl<<"\033[96;40m4. How many rings appear on the Olympic flag?";
if(Option4()==2){marks++;}
cout<<endl<<"\033[96;40m5. Which food item never spoils?";
if(Option5()==1){marks++;}
cout<<endl<<endl<<"Your Marks is "<<marks<<"/5"<<endl;
cout<<"Accuracy="<<marks*20<<"%";
marks=getch();
return 0;
}