Skip to content

Commit

Permalink
added new files.
Browse files Browse the repository at this point in the history
  • Loading branch information
jesushilarioh committed Nov 22, 2016
1 parent 4717c8c commit a224113
Show file tree
Hide file tree
Showing 4 changed files with 314 additions and 41 deletions.
29 changes: 29 additions & 0 deletions Chapter-1-Intro-to-Computers-and-Programming/1-1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//***********************************************
// This program calculates the user's pay.
//
// By: Jesus Hilario Hernandez
// Last Updated: November 21, 2016
//***********************************************
#include <iostream>
using namespace std;

int main()
{
double hours, rate, pay;

// Get the number of hours worked.
cout << "How many hours did you work?";
cin >> hours;

// Get the hourly pay rate.
cout << "How much do you get paid per hour?";
cin >> rate;

// Calculate the pay.
pay = hours * rate;

// Display the pay.
cout << "You have earned $" << pay << endl;

return 0;
}
26 changes: 26 additions & 0 deletions Chapter-1-Intro-to-Computers-and-Programming/1-30.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//*******************************************************
// This program calculates a customer's available credit.
//
// By: Jesus Hilario Hernandez
// Last Updated: November 21, 2016
//*******************************************************
#include <iostream>
using namespace std;

int main()
{
int maxCredit, creditUsed, availableCredit;

cout << "Enter the customer's maximum credit $";
cin >> maxCredit;

cout << "Enter the amount of credit used by the customer $";
cin >> creditUsed;

availableCredit = maxCredit - creditUsed;

cout << "The customer's available credit is $"
<< availableCredit << endl;

return 0;
}
140 changes: 140 additions & 0 deletions Projects/BookFlix/GroupProject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
//#include <windows.h>
#include <cstdlib> //for rand and srand
#include <ctime> // for the time
using namespace std;


int menu_choice; //declare vaiables
char repeat_menu;

void Romance(); //function pretotypes
void Fantasy();


int main()
{

cout << "This program allows you to find a book you would like to read\n";
cout << "based on which genre you would prefer to read." << endl;

do
{

cout << "\nChoose a genre from the list below\n" << endl;

cout << "\n1. Sheet Music " << endl;
cout << "\n2. Romance" << endl;
cout << "\n3. Adventure\n" << endl;

cin >> menu_choice;

while (menu_choice != 1 && menu_choice != 2 && menu_choice != 3)
{
cout << "\nError! Please enter a number from the choices above." << endl;
cin >> menu_choice;
}

switch (menu_choice)
{

case 1:
{

}
break;

case 2:
{

cout << "You have chosen romance as your genre." << endl;
Romance();

}
break;

case 3:
{
Fantasy();
}
break;

default:
break;

}

cout << "\nWould you like to return to the main menu? (Y/N)" << endl;

cin >> repeat_menu;

} while (repeat_menu == 'Y' || repeat_menu == 'y');

cout << "\nHave a nice day!" << endl;
return 0;
}

void Romance()
{

}

void Fantasy()
{
cout << "\nHere's a list of 3 Adventure books you'd might like to read.\n" << endl;
//Sleep (1000);

fstream inFile;
const int SIZE = 10; //array size
const int min_value = 0; //min random value
const int max_value = 5; //max random value

string book[SIZE]; //declare arrays
string author[SIZE];
string date[SIZE];

int count = 0;
int num = 1;
int RNG; //for random generator

inFile.open ("Booklist2.csv"); //open the file

if (inFile.fail()) //if file did not open
{
cout << "Error! Could not open file." << endl;
}
if (inFile)
{

while (getline (inFile, book[count], ','))
{
getline (inFile, author[count], ',');
getline (inFile, date[count], '\n');
count++;
}

cout << "Title" << "\t\t" << setw(25) << "Author" << "\t" << setw(14) << "Date\n" << endl;

for (int numloop = 0; numloop < 3; numloop++)
{
//get the system time
unsigned seed = time(0);
//seed the random num generator
srand(seed);

RNG = (rand() % (max_value - min_value + 1)) + min_value;
cout << num << ". " << book[RNG] << setw(25) << right << author[RNG] << setw(10) << right << date[RNG] << endl << endl;
num++;


//Sleep (1000);
}
}


inFile.close(); //close the file

}
160 changes: 119 additions & 41 deletions Projects/BookFlix/music.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,69 +6,147 @@
// By: Jesus Hilario Hernandez
// Last Updated: November 8, 2016
//*********************************************************

#include <fstream>
#include <iostream>
#include <string>
using namespace std;

// Directives for clearing the screen
#ifdef _WIN32
char buffer[4] = "cls";
const char* clearVar = buffer;
#ifdef _WIN64
char buffer[4] = "cls";
const char* clearVar = buffer;
#endif
#else
char buffer[6] = "clear";
const char* clearVar = buffer;
#endif

//Function Prototypes
void clearScreen();

// Main Function
int main()
{
// Input Stream Objects
ifstream inputAuthors, // For Authors.txt
inputBooks, // For Books.txt
inputDates; // For Date.txt
inputBooks, // For Books.txt
inputDates; // For Date.txt

// Output Stream Objects
ofstream outputFile; // Output Stream Object
ofstream keptBooks; // Output Stream Object

// Constants
const int SIZE = 3;
const int SIZE = 3,
SELECT_BOOK_1 = 0,
SELECT_BOOK_2 = 1,
SELECT_BOOK_3 = 2;

// Variables
string author[SIZE], // Holds author names
book[SIZE], // Holds book names
date[SIZE]; // Holds book dates
string author[SIZE], // Holds author names
book[SIZE], // Holds book names
date[SIZE]; // Holds book dates
int selectBook;
char keepBook, anotherSelection;

// Open input files
inputAuthors.open("Authors.txt");
inputBooks.open("Books.txt");
inputDates.open("Date.txt");
// Selecting Books from a list
do // main Do While Loop
{
// Open input files
inputAuthors.open("Authors.txt");
inputBooks.open("Books.txt");
inputDates.open("Date.txt");

clearScreen();
// Display list of music books
cout << "Here are the available music books: \n" << endl;
// Receive contents of each array from a file
for (int count = 0; count < SIZE; count++)
{
getline(inputAuthors, author[count]);
getline(inputBooks, book[count]);
getline(inputDates, date[count]);
cout << '\t' << (count + 1) << ". "
<< author[count] << ", " << endl
<< "\t\t" << book[count] << ", " << endl
<< "\t\t" << date[count] << endl << endl;
}

cout << "Here are books that are available" << endl
<< "in the sheet music genre:\n" << endl;
cout << "Select a book: ";
cin >> selectBook;

// Receive and display array contents
for (int count = 0; count < SIZE; count++)
{
getline(inputAuthors, author[count]);
getline(inputBooks, book[count]);
getline(inputDates, date[count]);
cout << (count + 1) << ". "
<< author[count] << ", " << endl
<< book[count] << ", " << endl
<< date[count] << endl << endl;
}

// Close inputFile
inputAuthors.close();
inputBooks.close();
inputDates.close();
switch (selectBook)
{
case (SELECT_BOOK_1 + 1):
clearScreen();
cout << "\nYou've selected:" << endl
<< book[SELECT_BOOK_1] << ", by "
<< author[SELECT_BOOK_1] << endl;

// Ask is user would like to keep book
cout << "\nWould you like to keep this book?";
cout << " (Y/N)";
cin >> keepBook;
break;
case (SELECT_BOOK_2 + 1):
clearScreen();
cout << "\nYou've selected:" << endl
<< book[SELECT_BOOK_2] << ", by "
<< author[SELECT_BOOK_2] << endl;

// Ask is user would like to keep book
cout << "\nWould you like to keep this book?";
cout << " (Y/N)";
cin >> keepBook;
break;
case (SELECT_BOOK_3 + 1):
clearScreen();
cout << "\nYou've selected:" << endl
<< book[SELECT_BOOK_3] << ", by "
<< author[SELECT_BOOK_3] << endl;

// Ask user to choose book
int chooseBook; // holds book choice
cout << "Choose a book that you would like to read: ";
cin >> chooseBook;
// Ask is user would like to keep book
cout << "\nWould you like to keep this book?";
cout << " (Y/N)";
cin >> keepBook;
break;
default:
cout << "NO WORK." << endl;
}

cout << "You chosen book " << chooseBook << '\n' << endl
<< author[(chooseBook - 1)] << ", " << endl
<< book[(chooseBook - 1)] << ", " << endl
<< date[(chooseBook -1)] << endl << endl;
// If no. Say ok.
if (keepBook == 'N' || keepBook == 'n')
{
cout << "Ok." << endl;
}
// If yes. Say awesome!
else if (keepBook == 'y' || keepBook == 'Y')
{
cout << "Awesome!\n";
}

char isThisCorrect; // Hold (Y/N) answer
cout << "Is this correct? ";
cin >> isThisCorrect;
// Ask if would like to make another music selection
cout << "Would you like to make another music genre selection?";
cin >> anotherSelection;

} while(anotherSelection == 'y' || anotherSelection == 'Y'); // End main Do While loop


// Close inputFiles
inputAuthors.close();
inputBooks.close();
inputDates.close();

return 0;
}

//***************************************************
// function to clear screen, using variable *
// created in PPD statement *
//***************************************************
void clearScreen()
{
system(clearVar);
}

0 comments on commit a224113

Please sign in to comment.