Combine java and C++ gits

This commit is contained in:
Logen Kain 2021-02-19 12:06:26 -05:00
parent 2a44fd5f5b
commit 9611d12b57
102 changed files with 767 additions and 0 deletions

BIN
cpp/2.12.1-input-output/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,17 @@
#include <iostream>
using namespace std;
int main() {
int currentPrice;
int lastMonthsPrice;
cin >> currentPrice;
cin >> lastMonthsPrice;
/* Type your code here. */
cout << "This house is $" << currentPrice << ". The change is $" << currentPrice-lastMonthsPrice << " since last month." << endl
<< "The estimated monthly mortgage is $" << (currentPrice*0.051)/12 << "." << endl;
return 0;
}

Binary file not shown.

View File

@ -0,0 +1,13 @@
#include <iostream>
using namespace std;
int main() {
/* Type your code here. */
int totalInches;
cin >> totalInches;
cout << totalInches/12 << "'" << totalInches%12 << endl;
return 0;
}

BIN
cpp/2.14-madlib/a.out Executable file

Binary file not shown.

20
cpp/2.14-madlib/main.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <iostream>
using namespace std;
int main() {
string name;
string location;
int number;
string pluralNoun;
/* Type your code here. */
cin >> name;
cin >> location;
cin >> number;
cin >> pluralNoun;
cout << name << " went to " << location << " to buy " << number << " different types of " << pluralNoun << "." << endl;
return 0;
}

BIN
cpp/2.15-seconds-simplified/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,24 @@
#include <iostream>
using namespace std;
int main() {
int seconds;
int minutes;
int hours;
/* Type your code here. */
/* get totals */
cin >> seconds;
minutes = seconds/60;
hours = minutes/60;
/* Get remainders */
minutes = minutes % 60;
seconds = seconds % 60;
cout << "Hours: " << hours << endl
<< "Minutes: " << minutes << endl
<< "Seconds: " << seconds << endl;
return 0;
}

Binary file not shown.

View File

@ -0,0 +1,17 @@
#include <iostream>
using namespace std;
int main() {
int seconds;
int minutes;
int hours;
/* Type your code here. */
cin >> hours >> minutes >> seconds;
cout << "Seconds: " << (hours * 60 * 60) + (minutes * 60) + seconds << endl;
return 0;
}

BIN
cpp/3.14-pizza-party/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,21 @@
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main() {
int people;
int numPizzas;
double cost;
/* Type your code here. */
//people eat two slices each
// Pizza has 12 slices
// costs 14.95 each
cost = 14.95;
cin >> people;
numPizzas = ceil((2 * people)/12.0);
cout << "Pizzas: " << numPizzas << endl;
cout << "Cost: $" << fixed << setprecision(2) << cost*numPizzas << endl;
}

BIN
cpp/3.15-ordering-pizza/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,23 @@
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main() {
int numPizza;
double subTotal;
double totalDue;
/* Type your code here */
double const cost = 9.99;
double const salesTax = 1.06;
cin >> numPizza;
subTotal = cost * numPizza;
totalDue = subTotal * salesTax;
cout << "Subtotal: $" << fixed << setprecision(2) << subTotal << endl;
cout << "Total due: $" << fixed << setprecision(2) << totalDue << endl;
return 0;
}

View File

@ -0,0 +1,17 @@
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
string result;
/* Type your code here */
cin >> s;
result = s.substr(s.length()-3, 3);
cout << "Postfix: " << result << endl;
return 0;
}

BIN
cpp/3.17-prefix-of-3/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,17 @@
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
string result;
/* Type your code here */
cin >> s;
result = s.substr(0,3);
cout << "Prefix: " << result << endl;
return 0;
}

BIN
cpp/3.18-midfix-of-3/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,18 @@
#include <iostream>
#include <string>
using namespace std;
int main() {
/* Type your code here. */
string s;
string result;
cin >> s;
result = s.substr((s.length()/2)-1, 3);
cout << "Midfix: " << result << endl;
return 0;
}

Binary file not shown.

View File

@ -0,0 +1,36 @@
#include <iostream>
#include <string> // Supports use of "string" data type
using namespace std;
int main() {
int userInt;
double userDouble;
// FIXME: Define char and string variables
char userChar;
string userString;
cout << "Enter integer:" << endl;
cin >> userInt;
cout << "Enter double:" << endl;
cin >> userDouble;
cout << "Enter character:" << endl;
cin >> userChar;
cout << "Enter string:" << endl;
cin >> userString;
cout << userInt << " " << userDouble << " " << userChar << " " << userString << endl;
// FIXME (2): Output the four values in reverse
cout << userString << " " << userChar << " " << userDouble << " " << userInt << endl;
// FIXME (3): Cast the double to an integer, and output that integer
cout << userDouble << " cast to an integer is " << (int)userDouble << endl;
return 0;
}

BIN
cpp/4.22-Smallest-number/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,35 @@
/*
* Write program that takes three ints and outputs the smallest
* so if input is 7 15 3
* then answer is 3
*/
#include <iostream>
using namespace std;
int main() {
/* Type your code here. */
int num1, num2, num3;
int smallest;
cin >> num1;
cin >> num2;
cin >> num3;
if (num1 < num2){
smallest = num1;
}
else{
smallest = num2;
}
if (num3 < smallest){
smallest = num3;
}
cout << smallest << endl;
return 0;
}

View File

@ -0,0 +1,63 @@
/*
* Primary interstate highway numbers are 1-99
* Odds go north/south
* evens go east/west
*
* Aux highways are 100-999
* Right most two digest are the primary highway it services
*
* givein a highway number, indicate primary or aux
* if aux indicate which highway it serves
*
* Also indicate if the primary highway runs north/south
* or east/west
*
* input: 90
* output: I-90 is primary, going east/west.
*
* input: 290
* output: I-290 is auxiliary, serving I-90, going east/west.
*
* input: 0
* output: 0 is not a valid interstate highway number.
*/
#include <iostream>
using namespace std;
int main() {
int highwayNumber;
string highwayDirection;
cin >> highwayNumber;
/* Type your code here. */
if (highwayNumber % 2 == 0){
highwayDirection="east/west";
}
else{
highwayDirection="north/south";
}
if ((highwayNumber < 1) ||
(highwayNumber > 999)){
cout << highwayNumber << " is not a valid interstate highway number.\n";
}
//Primary
else if (highwayNumber < 100){
cout << "I-" << highwayNumber << " is primary, going " <<
highwayDirection << ".\n";
//Aux
}
else{
cout << "I-" << highwayNumber << " is auxiliary, serving I-"<<
highwayNumber%100 << ", going " << highwayDirection << ".\n";
}
return 0;
}

View File

@ -0,0 +1,75 @@
/*
* Write program that takes an int
* it returns the change
* simple simple
*
* input: 0
* output: No change
*
* input: 45
* output:
* 1 Quarter
* 2 Dimes
*
* Do Dollar, Quarter, Dime, Nickel, Penny
* Note that 1 dollar and 2 dollars matter
*/
#include <iostream>
using namespace std;
int main() {
/* Type your code here. */
int runningTotal;
cin >> runningTotal;
//Forgot none so haste
if(runningTotal <=0){cout << "No change\n";}
//dollars
if (runningTotal >= 100){
if (runningTotal/100 == 1){
cout << runningTotal/100 << " dollar\n";
}
else {
cout << runningTotal/100 << " dollars\n";
}
runningTotal %=100;
}
//quarters
if (runningTotal >= 25){
if (runningTotal/25 == 1){
cout << runningTotal/25 << " quarter\n";
}
else {
cout << runningTotal/25 << " quarters\n";
}
runningTotal %=25;
}
//dimes
if (runningTotal >= 10){
if (runningTotal/10 == 1){
cout << runningTotal/10 << " dime\n";
}
else {
cout << runningTotal/10 << " dimes\n";
}
runningTotal %=10;
}
//Nickels
if (runningTotal >= 5){
cout << runningTotal/5 << " nickel\n";
runningTotal %=5;
}
//Pennies
if(runningTotal == 1){
cout << runningTotal << " penny\n";
}
else if (runningTotal >1) {
cout << runningTotal << " pennies\n";
}
return 0;
}

View File

@ -0,0 +1,57 @@
/*
* input is:
*
* firstName middleName lastName
*
* output is:
*
* lastName, firstInitial.middleInitial.
*
* Ex:
*
* input:
* Pat Silly Doe
*
* output:
*
* Doe, P.S.
*/
#include <iostream>
#include <string>
using namespace std;
int main() {
/* Type your code here. */
string f, m, l, s;
//getline(cin, s);
cin >> f;
cin >> m;
cin >> l;
if(l.size() != 0){
cout << l << ", " << f.at(0) << "." << m.at(0) << ".\n";
}
else{
cout << m << ", " << f.at(0) << ".\n";
}
/*
if(true){
cout << l << ", " << f.at(0) << "." << l.at(0) << ".\n";
}
else{
cout << l << ", " << f.at(0) << ".\n";
}
*/
return 0;
}

Binary file not shown.

View File

@ -0,0 +1,50 @@
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
int main() {
/* Type your code here. */
//Take in values
//Divide all values by largest value
//input begins with INT indicating number of floats
//Output each float with two digits after decimal
//cout << fixed << setprecision(2) once before other cout statements
//EX
//input: 5 30.0 50.0 10.0 100.0 65.0
//Output: 0.30 0.50 0.10 1.00 0.65
//For simplicity, follow every output value by a space, including last one
vector<float> userFloats;
int unsigned i;
int numFloats;
float fltLargest;
cin >> numFloats;
userFloats.resize(numFloats);
//Get numbers
for (i=0; i<userFloats.size();i++){
cin >> userFloats.at(i);
}
//Find max
fltLargest = userFloats.at(0);
for (i=0; i<userFloats.size();i++){
if (userFloats.at(i) > fltLargest){
fltLargest = userFloats.at(i);
}
}
//divde values by largest
for (i=0; i<userFloats.size(); i++){
userFloats.at(i) = userFloats.at(i)/fltLargest;
}
cout << fixed << setprecision(2);
for (i=0; i<userFloats.size();i++){
cout << userFloats.at(i) << " ";
}
cout << endl;
return 0;
}

BIN
cpp/6.24-elements-in-range/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,55 @@
#include <iostream>
#include <vector>
using namespace std;
int main() {
/* Type your code here. */
/*
* get list of ints from input
* input begins with number of inputs
* Then the list
* Then two more numbers, upper and lower bounds of a range
* incluseive of bounds
* Output all ints within the range
* follow each output with a comma
* end with newline
* example:
* Input:
* 5 25 51 0 200 33
* 0 50
* Output: 25,0,33,
*/
vector<int> intList;
int vectorSize;
int unsigned i;
int max;
int min;
//get list size
cin >> vectorSize;
intList.resize(vectorSize);
// Get list
for (i=0; i < intList.size(); i++){
cin >> intList.at(i);
}
// get max and min
cin >> min;
cin >> max;
for (i=0; i<intList.size(); i++){
if( intList.at(i) >= min &&
intList.at(i) <= max){
cout << intList.at(i) << ",";
}
}
cout << endl;
return 0;
}

BIN
cpp/6.27-soccer-team-roster/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,209 @@
/*
This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team.
(1) Prompt the user to input five pairs of numbers: A player's jersey number (0 - 99) and the player's rating (1 - 9). Store the jersey numbers in one int vector and the ratings in another int vector. Output these vectors (i.e., output the roster). (3 pts)
Ex:
Enter player 1's jersey number:
84
Enter player 1's rating:
7
Enter player 2's jersey number:
23
Enter player 2's rating:
4
Enter player 3's jersey number:
4
Enter player 3's rating:
5
Enter player 4's jersey number:
30
Enter player 4's rating:
2
Enter player 5's jersey number:
66
Enter player 5's rating:
9
ROSTER
Player 1 -- Jersey number: 84, Rating: 7
Player 2 -- Jersey number: 23, Rating: 4
...
(2) Implement a menu of options for a user to modify the roster. Each option is represented by a single character. The program initially outputs the menu, and outputs the menu after a user chooses an option. The program ends when the user chooses the option to Quit. For this step, the other options do nothing. (2 pts)
Ex:
MENU
a - Add player
d - Remove player
u - Update player rating
r - Output players above a rating
o - Output roster
q - Quit
Choose an option:
(3) Implement the "Output roster" menu option. (1 pt)
Ex:
ROSTER
Player 1 -- Jersey number: 84, Rating: 7
Player 2 -- Jersey number: 23, Rating: 4
...
(4) Implement the "Add player" menu option. Prompt the user for a new player's jersey number and rating. Append the values to the two vectors. (1 pt)
Ex:
Enter a new player's jersey number:
49
Enter the player's rating:
8
(5) Implement the "Delete player" menu option. Prompt the user for a player's jersey number. Remove the player from the roster (delete the jersey number and rating). (2 pts)
Ex:
Enter a jersey number:
4
(6) Implement the "Update player rating" menu option. Prompt the user for a player's jersey number. Prompt again for a new rating for the player, and then change that player's rating. (1 pt)
Ex:
Enter a jersey number:
23
Enter a new rating for player:
6
(7) Implement the "Output players above a rating" menu option. Prompt the user for a rating. Print the jersey number and rating for all players with ratings above the entered value. (2 pts)
Ex:
Enter a rating:
5
ABOVE 5
Player 1 -- Jersey number: 84, Rating: 7
...
*/
#include <iostream>
#include <vector>// FIXME include vector library
using namespace std;
int main() {
/* Type your code here. */
vector<int> jerseyNumber(5);
vector<int> playerRating(5);
int unsigned i;
for (i=0; i < jerseyNumber.size(); i++){
cout << "Enter player " << (i + 1) << "'s jersey number:\n";
cin >> jerseyNumber.at(i);
cout << "Enter player " << (i + 1) << "'s rating:\n";
cin >> playerRating.at(i);
cout << endl;
}
cout << "ROSTER\n";
for (i=0; i < jerseyNumber.size(); i++){
cout << "Player " << (i + 1) <<
" -- Jersey number: " << jerseyNumber.at(i) <<
", Rating: " << playerRating.at(i) << endl;
}
cout << endl;
char userInput = 0;
int tempJersey;
int tempRating;
while (userInput != 'q'){
userInput = 0;
cout << "MENU\n";
cout << "a - Add player\n";
cout << "d - Remove player\n";
cout << "u - Update player rating\n";
cout << "r - Output players above a rating\n";
cout << "o - Output roster\n";
cout << "q - Quit\n\n";
cout << "Choose an option:\n";
cin >> userInput;
if (userInput == 'a') {
cout << "Enter a new player's jersey number:\n";
cin >> tempJersey;
jerseyNumber.push_back(tempJersey);
cout << "Enter the player's rating:\n\n";
cin >> tempRating;
playerRating.push_back(tempRating);
}
//REMOVE
if (userInput == 'd'){
cout << "Enter a jersey number:\n";
cin >> tempJersey;
for (i=0; i<jerseyNumber.size(); i++){
if (tempJersey == jerseyNumber.at(i)){
jerseyNumber.erase(jerseyNumber.begin()+i);
playerRating.erase(playerRating.begin()+i);
break;
}
}
}
if (userInput == 'u'){
cout << "Enter a jersey number:\n";
cin >> tempJersey;
cout << "Enter a new rating for player:\n";
cin >> tempRating;
for (i=0; i<jerseyNumber.size(); i++){
if (tempJersey == jerseyNumber.at(i)){
playerRating.at(i) = tempRating;
}
}
}
//RATING ABOVE
if (userInput == 'r'){
cout << "Enter a rating:\n";
cin >> tempRating;
cout << "\nABOVE " << tempRating << endl;
for (i=0; i < jerseyNumber.size(); i++){
if (playerRating.at(i) > tempRating){
cout << "Player " << (i+1) <<
" -- Jersey number: " << jerseyNumber.at(i) <<
", Rating: " << playerRating.at(i) << endl;
}
}
cout << endl;
}
if (userInput == 'o'){
cout << "ROSTER\n";
for (i=0; i < jerseyNumber.size(); i++){
cout << "Player " << (i + 1) <<
" -- Jersey number: " << jerseyNumber.at(i) <<
", Rating: " << playerRating.at(i) << endl;
}
cout << endl;
}
if (userInput == 'q'){
break;
}
}
return 0;
}

Some files were not shown because too many files have changed in this diff Show More