C++ Assignment 6.3

Moderators: vinyard, KreepingMonkey

Post Reply
Message
Author
User avatar
vinyard
Server Admin
Posts: 301
Joined: Fri Jun 15, 2007 7:43 pm
Operating System: Windows Vista Ultimate 32bit
CPU: Intel C2D E8200 [Stock]
Video Card: EVGA GeForce 8800 GT 512MB SC
Sound Card: Onboard
Memory: Corsair Twin2x2048-6400Pro
Motherboard: EVGA 680i AR1 p32
Contact:

C++ Assignment 6.3

#1 Post by vinyard » Mon Oct 22, 2007 12:54 am

Here is assignment 6.3:

Code: Select all

/**Assignment 6.3**********
***Code by: David Rivera***
***10.22.2007*************/

#include <iostream>

using std::cout;
using std::cin;
using std::endl;
using std::string;

bool validateInput(char i);

int main()
{
    char response;                                                                                      //create char response
    bool valid = false;                                                                                 //create boolean valid, set to fasle
    cout << "Please enter one of the following choices." << endl;                                       //output
    cout << "m) Motherboard          c) CPU" << endl;                                                   //the
    cout << "g) GPU                  h) Hard Drive" << endl;                                            //menu
    cout << "i) I hate computers." << endl;                                                             //to screen
    
    /* Loop here until the response in valid */
    do
    {
         cin >> response;
         cout << endl;
         valid = validateInput(response);
    } while(!valid);
    
    system("pause");                                                                                    //wait for user input
    return 0;
}

/* unser input validation function */
bool validateInput(char i)                                                                
{
       bool valid = false;                                                                              //create booloean valid, set to false
       switch(i)
       {
                case 'm':                                                                               //if user input matches 'm'
                     cout << "This is the main board of a computer." << endl;                           //output definition
                     valid = true;                                                                      //cahracter is valid, valid = true
                     break;
                case 'c':
                     cout << "The CPU is the brains of the computer." << endl;
                     valid = true;
                     break;
                case 'g':
                     cout << "The GPU is a dedicated graphics rendering device." << endl;
                     valid = true;
                     break;
                case 'h':
                     cout << "A Hard Disk Drive is a non-volatile storage device"
                          << " which stores digitally encoded data." << endl;
                     valid = true;
                     break;
                case 'i':
                     cout << "You Sir/ma'am are dumb." << endl;
                     valid = true;
                     break;
                default:                                                                                //user input does not match
                     cout << "Please slelect m, c, g, h or i: ";                                        //promt for a valid character
       }
       return valid;                                                                                    //return valid )true or false)
} 
Here is a SS of the output.
Assignment 6.3 (10.22.2007)
Assignment 6.3 (10.22.2007)
6_3.jpg (28.52 KiB) Viewed 972 times
- vinyard.

User avatar
zero86ea
C.S. Server Admin
Posts: 318
Joined: Tue Jun 19, 2007 12:02 am
Contact:

Re: C++ Assignment 6.3

#2 Post by zero86ea » Thu Oct 25, 2007 11:20 am

niiiice vin!
Image

skaterbasist
C.S. Server Admin
Posts: 91
Joined: Fri Jul 13, 2007 11:43 pm
Contact:

Re: C++ Assignment 6.3

#3 Post by skaterbasist » Thu Oct 25, 2007 3:46 pm

Interesting to see that the switch is almost exactly how we use it in Java. Just shows how if you learn one language, you can easily learn another!

.
Image

User avatar
zero86ea
C.S. Server Admin
Posts: 318
Joined: Tue Jun 19, 2007 12:02 am
Contact:

Re: C++ Assignment 6.3

#4 Post by zero86ea » Thu Oct 25, 2007 3:53 pm

skaterbasist wrote:Interesting to see that the switch is almost exactly how we use it in Java. Just shows how if you learn one language, you can easily learn another!

.
true!
Image

Post Reply