Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[REQUEST] c++ Countdown timer for quiz program

Status
Not open for further replies.

themaestro

Newbie level 1
Joined
Oct 6, 2010
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,286
Hi there everyone. i'm doing a c++ program using DEV. i'm making a quiz program but i wish to add a countdown timer on the cmd at the same time, the user can do the quiz. The timer is shown on the screen and when the time reaches 30mins, the quiz is automatically finish and end. Can anyone help me out here? Here's my code
Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <conio.h>
#include <iomanip>
#include <ctype.h>
#include <cstring>
using namespace std;

int quiz1();
int quiz2();
void diagram1();
void diagram2();
void diagram3();
int main()
{
    quiz1();
    quiz2();
   
    getch();
    
    
}

int quiz1()
{   
    cout<<"Quiz 1 Basic Concepts of Circuit Theory"<<endl<<endl;
    cout<<"Please Key In Your Answers In Simplified SI Units shown as the table on the next page."<<endl<<endl;
    cout<<"Press Any Key To Start The Quiz"<<endl;
    getch();
    system("CLS");
    ifstream inputquiz1("quiz1.txt",ios::in);
    ifstream inputrealans1("ans1.txt",ios::in);
    char q1[10][999],ans1[10][999],realans1[10][999];
    int a;
    for(int i=0;i<10;i++)
    {       
            inputquiz1.getline(q1[i],999);
            inputrealans1.getline(realans1[i],999);
    }
    
    for(int i=0;i<10;i++)
    {       
             cout<<"s = second(s)\t"<<"v = volt(s)"<<endl;
             cout<<"a = ampere(s)\t"<<"ohm = ohm(s)"<<endl;
             cout<<"w = watt(s)\t"<<"j = joule(s)"<<endl<<endl;
            int correct,wrong;
            cout<<"Question "<<i+1<<endl<<endl;
            cout<<q1[i]<<endl; 
            cin.getline(ans1[i],999);
            for(int j=0;j<999;j++)
            { char a=tolower(ans1[i][j]);
            ans1[i][j]=a;}
            a=strcmp(ans1[i],realans1[i]);
 
            if (a==0)
            {        cout<<" Correct Answer! "<<endl;
                     correct++;
            }
            else
            {        cout<<" Incorrect Answer! "<<endl;
                     wrong++; 
            }
            getch();
            system("CLS");           
    }
}

int quiz2()
{
    cout<<"Quiz 2 The Basic Laws Of Circuit"<<endl;
    cout<<"Please Key In All Your Answers In LOWERCASE"<<endl<<endl;
    cout<<"Press Any Key To Start The Quiz"<<endl;
    getch();
    system("CLS");
    ifstream inputquiz2("quiz2.txt",ios::in);
    ifstream inputrealans2("ans2.txt",ios::in);
    ifstream inputquiz2choice("quiz2choice.txt",ios::in);
    char q2[10][999],q2choice[40][999],ans2[10][2],realans2[10][2];
    int a,h=0;
    for(int i=0;i<10;i++)
    {      
            inputquiz2.getline(q2[i],999);
            inputrealans2>>realans2[i];
            
    }
    for(int i=0;i<40;i++)
    {        
            inputquiz2choice.getline(q2choice[i],999);
    }
   
    for(int i=0;i<10;i++)
    {       
            int correct,wrong;
            cout<<"Question "<<i+1<<endl<<endl;
            if((i>=3)&&(i<=6))
            {diagram1();
            }
            else if(i==7)
            {diagram2();
            }
            else if(i==8)
            {diagram3();
            }
            
            cout<<q2[i]<<endl; 
            for(int j=h;j<h+4;j++)
            {
            cout<<endl<<q2choice[j]<<endl;
            }
            cin>>ans2[i];
              for(int j=0;j<2;j++)
            { char c=tolower(ans2[i][j]);
            ans2[i][j]=c;}
          a=strcmp(ans2[i],realans2[i]);
            
    
           
 
            if (a==0)
            {        cout<<" Correct Answer! "<<endl;
                     correct++;
            }
            else
            {        cout<<" Incorrect Answer! "<<endl;
                     wrong++; 
            }
            h+=4;           
            getch();
            system("CLS");
            
    }
}
    
    
    
void diagram1()
{
 cout<<"          DELTA CONNECTION                       WYE CONNECTION"<<endl;                                                                      
 cout<<"            ______                           _____          _____      "<<endl;
 cout<<" __________|______|_____________       _____|_____|________|_____|____ "<<endl;
 cout<<"   |             R(c)      |                  R1      |     R2         "<<endl;
 cout<<"   |                       |                          |                "<<endl;
 cout<<"   |                       |                          |                "<<endl;
 cout<<" __|                       |__                      __|                "<<endl;
 cout<<"|  |                       |  |                    |  |                "<<endl;
 cout<<"|  | R(b)              R(a)|  |                 R3 |  |                "<<endl;
 cout<<"|  |                       |  |                    |__|                "<<endl;
 cout<<"|__|                       |__|                       |                "<<endl;
 cout<<"   |                       |                          |                "<<endl;
 cout<<"   |                       |                          |                "<<endl;
 cout<<"___|_______________________|____       _______________|______________  "<<endl<<endl;
 cout<<"                               Diagram 1                               "<<endl<<endl<<endl;

}

void diagram2()
{
                                                                    
 cout<<"                 ______                           _____           _____      "<<endl;
 cout<<"  ______________|______|_________________________|_____|_________|_____|_____ "<<endl;
 cout<<"  |          |    12ohm              |             8ohm         | 2ohm      |     "<<endl;
 cout<<"  |          |                       |                          |           |     "<<endl;
 cout<<" _|        __|                       |__                      __|           |     "<<endl;
 cout<<"| |       |  |                       |  |                    |  |           |     "<<endl;
 cout<<"| |6ohm   |  | 3ohm                  |  | 9ohm               |  | 4ohm      |     "<<endl;
 cout<<"| |       |  |                       |  |                    |  |           |     "<<endl;
 cout<<"|_|       |__|                       |__|                    |__|           |     "<<endl;
 cout<<"  |          |                       |                          |           |     "<<endl;
 cout<<"  |__________|_______________________|__________________________|___________|     "<<endl<<endl;
 cout<<"                               Diagram 2                               "<<endl<<endl<<endl;

}
void diagram3()
{
                                                                    
 cout<<"                 ______                                           _____          "<<endl;
 cout<<"  ______________|______|_________________________________________|_____|____     "<<endl;
 cout<<"  |              12ohm                           _____            2ohm      |    "<<endl;
 cout<<"  |_____________________________________________|_____|_____________________|    "<<endl;
 cout<<" _|        __|                       |__         10ohm                    __|    "<<endl;
 cout<<"| |       |  |                       |  |                                |  |    "<<endl;
 cout<<"| |6ohm   |  | 3ohm                  |  | 9ohm                           |  |4ohm"<<endl;
 cout<<"| |       |  |                       |  |                                |  |    "<<endl;
 cout<<"|_|       |__|                       |__|                                |__|    "<<endl;
 cout<<"  |          |                       |                                      |     "<<endl;
 cout<<"  |__________|_______________________|______________________________________|     "<<endl<<endl;
 cout<<"                               Diagram 3                               "<<endl<<endl<<endl;

}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top