Tuesday, October 28, 2014

Drivers licence exam C++

/////////////////////////////////////////////////////////////////////////////////////////////////
// Author:Joe Student                                               //
//                                                                                                      //
// Date:                    09/06/14    34                                                  //
// Program Description:Write a program that grades the written   //
//portion of the driver's license exam.                                            //
//                                                                                                     //
// Input:  Answers (A,B,C,D)                                                        //
// Processing:   Compared to prepared answer bank                     //
// Output: Number wrong, number right , pass/fail                       //
///////////////////////////////////////////////////////////////////////////////////////////////

#include <iostream>
#include <cctype>
using namespace std;
void checkAnswers(char[], char[], int, int);
int main() {
    const int NUM_QUESTIONS = 20;
    const int MIN_CORRECT = 15;
    char answers[NUM_QUESTIONS] = {'B', 'D', 'A', 'A', 'C','A', 'B', 'A', 'C', 'D','B', 'C', 'D', 'A', 'D','C', 'C', 'B', 'D','A'};
    char stu_answers[NUM_QUESTIONS];
    //Loop for users answers
    for (int replies = 0; replies < NUM_QUESTIONS; replies++) {
        cout<< "Please enter your answers (Hint: Use capital letters): "
            << (replies + 1) << ": ";
        cin >> stu_answers[replies];
        //Validation of users answers
        while (stu_answers[replies] != 'A' && stu_answers[replies] != 'B' && stu_answers[replies] != 'C' && stu_answers[replies] != 'D') {
            cout << "You must enter A, B, C, or D\n";
            cout<< "Please enter your answers (Hint: Use capital letters): "
                << (replies + 1) << ": ";
            cin >> stu_answers[replies];
        }
    }
    checkAnswers(answers, stu_answers, NUM_QUESTIONS, MIN_CORRECT);
    return 0;
}
void checkAnswers(char answers1[], char stu_answers1[], int NUM_QUESTIONS, int MIN_CORRECT) {
    //cout << "max: " << NUM_QUESTIONS;
    int correctAnswers = 0;
    //Check the student's replies against the correct answers
    for (int i = 0; i < NUM_QUESTIONS; i++)  {
        if (answers1[i] == stu_answers1[i])
            correctAnswers++;
    }
    //Did they pass or fail?
    cout << "\n\n\n\n\n\n\n\n\nYou must have at least 15 correct to pass.";
    cout << "\n-------------------------------------------";

    if (correctAnswers >= MIN_CORRECT) {
        cout << "\nStudent passed the exam";
       cout << "\n---------------------------\n\n\n\n\n";

    }
    else {
        cout <<"\nStudent failed the exam";
       cout << "\n---------------------------\n\n\n\n\n";

    }
    //Display a list of the questions that were incorrectly answered.
    cout << "The list below shows the question numbers of the incorrectly";
    cout << " answered questions.\n";
    for (int i = 0; i < NUM_QUESTIONS; i++)  {
        if (answers1[i] != stu_answers1[i])
            cout << "Question # " << i << " is incorrect." << endl;
    }
    //Display the number of correct and incorrect answers provided by the student.
    cout << "\nCorrect Answers = " << correctAnswers << endl;
    cout << "Incorrect Answers = " << NUM_QUESTIONS - correctAnswers << endl;
}

Monday, October 13, 2014

Simple Write your name in ASCII C++



///////////////////////////////////////////////////////////////////
// Author:Zachary //
//                                                               //
// Date: 08/21/2014                                              //
// Program Description: Write a C++ program using output         //
//statements (cout) to print the first three letters of your     //
//first name in big blocks. This program does not read anything  //
//from the keyboard.                                             //
//Each letter is formed using 7 rows and 5 columns using the     //
//letter itself.                                                 //
//                                                               //
// Input:                                                        //
// Processing:                                                   //
// Output:                                                       //
///////////////////////////////////////////////////////////////////
#include <iostream>

using namespace std;

int main()
{
    cout << "ZZZZZ  DDDDD SSSSS" << endl;
    cout << "    Z  D   D S    " << endl;
    cout << "   Z   D   D S    " << endl;
    cout << "  Z    D   D SSSSS" << endl;
    cout << " Z     D   D     S" << endl;
    cout << "Z      D   D     S" << endl;
    cout << "ZZZZZ  DDDDD SSSSS" << endl;
    return 0;
}

Internet Service Provider C++

/*
 * isp.cpp
 *
 *  Created on: Sep 24, 2014
 *      Author: Zach
 */

#include "isp.h"
#include <iostream>
using namespace std;

int main ()
{
int choice;
int hours;
double total;

double A = 9.95;
double B = 14.95;
double C = 19.95;
double D = 2.00;
double E = 1.00;

//Display
cout << " \t\What is your package subscription \n";
cout << "1. A.$9.95 per month. 10 hours access. Additional Hours are $2.00\n";
cout << "2. B.$14.95 per month. 20 hours access. Additional hours are $1.00\n";
cout << "3. C.$19.95 per month. Unlimited access.\n";
cout << "Enter your choice: ";
cin >> choice;

if (choice >=1 && choice <=3)
{
cout << "How many hours were used?  ";
cin >> hours;
switch (choice)
{
case 1:
{
total = A + (hours - 10)*D;
break;
}
case 2:
{
total = B + (hours - 20)*E;
break;
}
case 3:
{
total = C;
break;
}

default:
cout<<"You enter a wrong value!"<<endl;
cout << "The valid choices are 1 through 3. \n Run the program again.";
}

cout << "Your charge for this month is: $ "<<total<<endl;
}
else if (choice !=3)
{
cout << "The valid choices are 1 through 3. \n Run the program again.";
}
return 0;
}

Celsius to Fahrenheit converter C++

//============================================================================
// Name        : f2c.cpp
// Author      : Zachary S
// Version     :X^e2
// Copyright   : my granny will find you
// Description : Using a loop that counts to 20, it takes in the loop number, converts it as a temp in F and prints it out as a C
//============================================================================
#include <iostream>
 using namespace std;
 double toCelcius(int Temp)
 {
     return (5.0/9.0)*((double)Temp - 32.0);
 }
 int main()
 {
     cout << "fahrenheit \t to \t  celsius\n";
     for (int i = 0;i <= 20;i++)
     {
         cout << i << "\t\t" << (int)toCelcius(i) << endl;
     }
 }

Simple Miles per gallon calculator C++

/*
// Author:Zachary //
//                                                               //
// Date:                    09/06/14 1:34                        //
// Program Description:Write a program that asks the user for    //
 *  how many miles they drove and how much gas they used         //
//                                                               //
// Input:  distance, gallons                             //
// Processing:   MPG = MilesDriven / GallonsUsed                 //
// Output: MPG                                                   //

 */

#include <iostream>

using namespace std;

/*
 *
 */

int main()
{
   
   int gallons = 0;      
   double distance = 0.0;    
   double mpg = 0.0;
   do
   {
      cout << "Please input how many gallons of gasoline are in your vehicle: ";
      cin >> gallons;
      cout << "Please input the distance in miles you traveled in your vehicle: ";
      cin >> distance;
      mpg = distance / gallons;
       cout << "Your vehicle's MPG is: " << mpg << endl;
    }while(gallons >-1);
 
    return 0;
}