Just paste this into your editor..

This is a discussion on Just paste this into your editor.. within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, I've written some code for a quiz program, but I don't have a proper compiler right now to ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    71

    Just paste this into your editor..

    Hi everyone,
    I've written some code for a quiz program, but I don't have a proper compiler right now to test it on (the one I downloaded earlier today is useless). So if anyone could please paste the following code into their compiler editor, run it, and tell me if there are any problems, I'd really appreciate it.
    The file quiz.txt contains this (with the exact format and no blank lines):
    1. What is the best way to describe a network?
    A. A series of individual components that communicate
    B. A single unit that represents all components
    C. A single client and multiple servers
    D. All communication components and the Internet
    B
    2. Which protocol was PPP created to replace?
    A. SLIP
    B. CHAP
    C. IPX
    D. SPX
    A
    3. What is the purpose of LMI?
    A. Informs the hub which PVCs are available
    B. Determines the operational status of PVCs
    C. Ensures the PVC shutdown during inactivity
    D. Eliminates the need for DLCIs
    B
    4. What does Frame Relay use to prevent routing loops?
    A. Holddown timers
    B. Lower convergence times
    C. Increased router updates
    D. Split horizon
    D
    5. How does PPP handle individual station addresses?
    A. PPP does not assign individual station addresses.
    B. The user assigns addresses for PPP.
    C. PPP gets addresses from a DHCP server.
    D. Routers assign PPP addresses.
    A
    6. What does remote monitoring use to gather data?
    A. SNMP agent
    B. RMON probe
    C. SNTP server
    D. MIB
    B
    7. Using Cisco IOS release 11.2 or later, how is the LMI type set?
    A. Autosensing
    B. Requires a default setting
    C. Set to ANSI
    D. Set to Cisco
    A
    8. What would cause the PPP link establishment to terminate repeatedly?
    A. Incorrect URL
    B. Browser misconfiguration
    C. Incorrect DNS entry
    D. Loss of carrier
    D
    9. What IP protocol does Frame Relay use for error correction?
    A. ICMP
    B. UDP
    C. TCP
    D. SPX
    C
    10. Which of the following is a mandatory byte in the LMI frame?
    A. FCS
    B. Global addressing
    C. Information element
    D. Protocol discriminator
    D
    11. What command is used to display protocol statistics?
    A. Tracert
    B. Telnet
    C. Ping
    D. Netstat
    D
    12. Which of the following is a common LMI extension?
    A. Multicasting
    B. Global addressing
    C. Simple flow control
    D. Virtual circuit status messages
    D


    Thanks a lot.
    Linette

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    71

    oops..

    I forgot to paste the actual code here!..
    PHP Code:
    #include <iostream.h>
    #include <fstream.h>
    #include <string.h>

    struct qtype {
       
    char question [80];
       
    char answers [4][80];
       
    char rightanswer;
    };

    void getquestion (qtype item[12]);
       
    ifstream sourcefile ("quiz.txt");
       
    char line [80];
       
    int c;
       
    int count 0;
       
       if (
    sourcefile.fail())
          
    cerr << "Error opening quiz.txt...";
       else
          (while ! 
    sourcefile.eof()) {
             
    sourcefile.getline (linesizeof(line));
         
    strcpy (item[count].questionline);
             for (
    c=0c<4c++) {
            
    sourcefile.getline (linesizeof(line));
            
    strcpy (item[count].answers[c], line);
         }
         
    sourcefile.getline (linesizeof(line));
         
    strcpy (item[count].rightanswerline);
         
    count ++;
          }    
       
    sourcefile.close();
       return;
    }
     
    void doquiz (qtype item[12], char ans[12]) {
       
    int count;
       
    int c;
       for (
    count=0count<12count++) {
          
    cout << item[count].question << endl;
          for (
    c=0c<4c++) 
             
    cout <<item[count].answers[c] << endl;
          
    cout << "Your Answer: ";
          
    cin >> ans[count];
       }
       return;    
    }

    void evaluate (qtype item[12], char ans[12], int right) {
       
    int c;
       for (
    c=0c<12c++) 
          if ( 
    ans[c] == item[c].rightanswer)
             
    right++;
       return;
    }

    void comment (int right) {
       if (
    right == 12)
          
    cout << "\nPerfect score, good job!";
       else if (
    right 8)
          
    cout << "\nNot bad, you do know some networking.";
       else if (
    right 4)
          
    cout << "\nYou need some review..";
       else
          
    cout << "\nNot good at all! You should forget about networking.";
       return;
    }

    void main () {
       
    qtype item [12];
       
    char ans [12];
       
    int rightones 0;  //the number of answers user got right
       
    getquestion (item);
       
    doquiz (itemans);
       
    evaluate (itemansrightones);
       
    comment (rightones);
       return;


  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    71
    um, in function doquiz, add in another statement please:

    after
    cin >> ans[count];
    add:
    cout << "\n";

  4. #4
    Unregistered
    Guest
    Hi, i'm trying to work on the same sort of thing as you are and I think your code is great. Could you please explain each line of this part of it for me? Thanks.

    Code:
    void getquestion (qtype item[12]);
       ifstream sourcefile ("quiz.txt");
       char line [80];
       int c;
       int count = 0;
       
       if (sourcefile.fail())
          cerr << "Error opening quiz.txt...";
       else
          (while ! sourcefile.eof()) {
             sourcefile.getline (line, sizeof(line));
         strcpy (item[count].question, line);
             for (c=0; c<4; c++) {
            sourcefile.getline (line, sizeof(line));
            strcpy (item[count].answers[c], line);
         }
         sourcefile.getline (line, sizeof(line));
         strcpy (item[count].rightanswer, line);
         count ++;
          }    
       sourcefile.close();
       return;
    }

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    71
    umm can i ask where you're located if you don't mind?

    to explain that function.. what it does is it reads the file line by line and stores every question's first line in the 'question' field of the struct, the next four lines as the four 'answers', and the final line as the 'rightanswer'.
    Did you try running it on your compiler? Did it work fine?

    That's all I need to know...

  6. #6
    Registered User
    Join Date
    Jan 2002
    Posts
    71
    Please somebody just test that in your compiler!..


  7. #7
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    I would if I knew how to put that .txt in the right place.......sorry I haven't gotten to that yet.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  8. #8
    Registered User
    Join Date
    Jan 2002
    Posts
    71
    Oh that just involves pasting the questions and everything I wrote into a .txt (notepad) file, saving it as quiz.txt, and making sure it's in the same folder as the program.

    I'd really really appreciate it if you tried running that.

  9. #9
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Info :Compiling C:\Documents and Settings\Incognito\Desktop\NONAME00.CPP
    Error: NONAME00.CPP(17,6):Declaration terminated incorrectly
    Error: NONAME00.CPP(19,8):Declaration terminated incorrectly
    Error: NONAME00.CPP(32,10):Declaration terminated incorrectly
    Error: NONAME00.CPP(33,2):Unexpected }
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  10. #10
    Registered User
    Join Date
    Jan 2002
    Posts
    71
    Oh, I just noticed why.
    At the end of function getquestion's header, please change that semi-colon to a {.
    Does it work well now? the output..?

    Thanks a lot.

  11. #11
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    I don't follow you........just update it to the code you posted above and then tell me you did so and I'll copy and run everything again.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  12. #12
    Registered User
    Join Date
    Jan 2002
    Posts
    71
    PHP Code:
    #include <iostream.h>
    #include <fstream.h>
    #include <string.h>

    struct qtype {
       
    char question [80];
       
    char answers [4][80];
       
    char rightanswer;
    };

    void getquestion (qtype item[12]) { //here was a syntax error
       
    ifstream sourcefile ("quiz.txt");
       
    char line [80];
       
    int c;
       
    int count 0;
       
       if (
    sourcefile.fail())
          
    cerr << "Error opening quiz.txt...";
       else
          while (! 
    sourcefile.eof()) { //here was another
             
    sourcefile.getline (linesizeof(line));
             
    strcpy (item[count].questionline);
             for (
    c=0c<4c++) {
                
    sourcefile.getline (linesizeof(line));
                
    strcpy (item[count].answers[c], line);
             }
             
    sourcefile.getline (linesizeof(line));
             
    strcpy (item[count].rightanswerline);
             
    count ++;
          }    
       
    sourcefile.close();
       return;
    }
     
    void doquiz (qtype item[12], char ans[12]) {
       
    int count;
       
    int c;
       for (
    count=0count<12count++) {
          
    cout << item[count].question << endl;
          for (
    c=0c<4c++) 
             
    cout <<item[count].answers[c] << endl;
          
    cout << "Your Answer: ";
          
    cin >> ans[count];
       }
       return;    
    }

    void evaluate (qtype item[12], char ans[12], int right) {
       
    int c;
       for (
    c=0c<12c++) 
          if ( 
    ans[c] == item[c].rightanswer)
             
    right++;
       return;
    }

    void comment (int right) {
       if (
    right == 12)
          
    cout << "\nPerfect score, good job!";
       else if (
    right 8)
          
    cout << "\nNot bad, you do know some networking.";
       else if (
    right 4)
          
    cout << "\nYou need some review..";
       else
          
    cout << "\nNot good at all! You should forget about networking.";
       return;
    }

    void main () {
       
    qtype item [12];
       
    char ans [12];
       
    int rightones 0;  //the number of answers user got right
       
    getquestion (item);
       
    doquiz (itemans);
       
    evaluate (itemansrightones);
       
    comment (rightones);
       return;


  13. #13
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Getting close

    Info :Compiling C:\DOCUMENTS AND SETTINGS\INCOGNITO\DESKTOP\help guy online.cpp
    Error: help guy online.cpp(28,48):Cannot convert 'int' to 'char *'
    Error: help guy online.cpp(28,48):Type mismatch in parameter '__dest' in call to 'strcpy(char *,const char *)'
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  14. #14
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    This is the line that the compiler flags........


    strcpy (item[count].rightanswer, line);
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  15. #15
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Hey have you tried DevC++ at bloodshed? It's quite good although I had some problems with it today.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WYSIWYG editor problem
    By Akkernight in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 04-01-2009, 08:50 AM
  2. Replies: 19
    Last Post: 05-30-2007, 05:47 PM
  3. Replies: 12
    Last Post: 08-05-2003, 02:16 PM
  4. OpenGL terrain demo (EDITOR)
    By Jeremy G in forum Game Programming
    Replies: 2
    Last Post: 03-30-2003, 07:11 PM
  5. PFE (prorgammers file editor, for Windows)
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 06-09-2002, 11:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21