diff options
| author | till-t <[email protected]> | 2021-10-26 18:00:41 -0700 |
|---|---|---|
| committer | till-t <[email protected]> | 2021-10-26 18:00:41 -0700 |
| commit | 49d9861f9e88f1b0036a016625341f9e8b7e75a6 (patch) | |
| tree | c91334c89bd13c17bdf9f0dfbf42d4d32bdda0a5 | |
| parent | End of day. Complete through 9.4 exercises. Next to be done is 9.5 exercises ... (diff) | |
| download | cst116-lab4-till-t-49d9861f9e88f1b0036a016625341f9e8b7e75a6.tar.xz cst116-lab4-till-t-49d9861f9e88f1b0036a016625341f9e8b7e75a6.zip | |
End of day. Completed all exercises.
| -rw-r--r-- | .idea/cst116-lab4-till-t.iml | 8 | ||||
| -rw-r--r-- | CST116F2021-Lab4/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | CST116F2021-Lab4/CST116F2021-Lab4.cpp | 20 | ||||
| -rw-r--r-- | CST116F2021-Lab4/Lab4_Taormina | 292 | ||||
| -rw-r--r-- | CST116F2021-Lab4/lab4.cpp | 32 |
5 files changed, 309 insertions, 49 deletions
diff --git a/.idea/cst116-lab4-till-t.iml b/.idea/cst116-lab4-till-t.iml deleted file mode 100644 index bc2cd87..0000000 --- a/.idea/cst116-lab4-till-t.iml +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module type="CPP_MODULE" version="4"> - <component name="NewModuleRootManager"> - <content url="file://$MODULE_DIR$" /> - <orderEntry type="inheritedJdk" /> - <orderEntry type="sourceFolder" forTests="false" /> - </component> -</module>
\ No newline at end of file diff --git a/CST116F2021-Lab4/CMakeLists.txt b/CST116F2021-Lab4/CMakeLists.txt new file mode 100644 index 0000000..f0ed9c3 --- /dev/null +++ b/CST116F2021-Lab4/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.20) +project(cst116-lab4-till-t) + +set(CMAKE_CXX_STANDARD 14) + +add_executable(cst116-lab4-till-t lab4.cpp)
\ No newline at end of file diff --git a/CST116F2021-Lab4/CST116F2021-Lab4.cpp b/CST116F2021-Lab4/CST116F2021-Lab4.cpp deleted file mode 100644 index ff0073d..0000000 --- a/CST116F2021-Lab4/CST116F2021-Lab4.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// CST116F2021-Lab4.cpp : This file contains the 'main' function. Program execution begins and ends there. -// - -#include <iostream> - -int main() -{ - std::cout << "Hello World!\n"; -} - -// Run program: Ctrl + F5 or Debug > Start Without Debugging menu -// Debug program: F5 or Debug > Start Debugging menu - -// Tips for Getting Started: -// 1. Use the Solution Explorer window to add/manage files -// 2. Use the Team Explorer window to connect to source control -// 3. Use the Output window to see build output and other messages -// 4. Use the Error List window to view errors -// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project -// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file diff --git a/CST116F2021-Lab4/Lab4_Taormina b/CST116F2021-Lab4/Lab4_Taormina index ed8bd99..47a5f0c 100644 --- a/CST116F2021-Lab4/Lab4_Taormina +++ b/CST116F2021-Lab4/Lab4_Taormina @@ -1,4 +1,5 @@ -Tyler Taormina Lab 4 Text File +Tyler Taormina +Lab 4 Text File CST CST116 October 20, 2021 @@ -31,14 +32,10 @@ Total: 15 pts #include <cmath> // needed for square roots using namespace std; -int avg_score (float& num1, float& num2, float& num3) -{ - int avg = 0; - avg = ( num1 + num2 + num3 ) / 3; - return avg; -} +int avg_score (float& num1, float& num2, float& num3); -int main() { +int main() +{ float value1, value2, value3, average = 0.0; @@ -56,6 +53,13 @@ int main() { return 0; } +int avg_score (float& num1, float& num2, float& num3) +{ + int avg = 0; + avg = ( num1 + num2 + num3 ) / 3; + return avg; +} + RUN: C:\Users\Till\CLionProjects\gitDemo\cmake-build-debug\gitDemo.exe Enter 3 values that you want averaged. @@ -80,6 +84,25 @@ CODE: #include <iostream> using namespace std; +void GetInput (float& salary, int& years_service); +void CalcRaise (float& salary, int years_service); +int CalcBonus (int years_service); +void PrintCalc (int years_service, float salary, int bonus); + +int main() +{ + int years_service = 0, bonus = 0; + float salary = 0.0; + + GetInput(salary, years_service); + CalcRaise(salary, years_service); + bonus = CalcBonus(years_service); + PrintCalc(years_service, salary, bonus); + + return 0; +} + + void GetInput (float& salary, int& years_service) { cout << "Enter salary: "; @@ -115,18 +138,6 @@ void PrintCalc (int years_service, float salary, int bonus) cout << "The bonus you will receive is $" << bonus << endl; } -int main() -{ - int years_service = 0, bonus = 0; - float salary = 0.0; - - GetInput(salary, years_service); - CalcRaise(salary, years_service); - bonus = CalcBonus(years_service); - PrintCalc(years_service, salary, bonus); - - return 0; -} RUN: @@ -146,13 +157,137 @@ p 216 Submit: code & run CODE: +#include <iostream> +#include <iomanip> +using namespace std; +void getNum (int&, int&, int&); +void printTime (int&, int&, int&, int form = 1); +int main() +{ + int hour = 0, min = 0, sec = 0; + int format; + getNum(hour, min, sec); + printTime(hour, min, sec, format); + return 0; +} -RUN: +void getNum(int& hour, int& min, int& seconds) +{ + cout << "Enter hour for the current time: "; + cin >> hour; + cout << "Enter minute of the current time: "; + cin >> min; + cout << "Enter seconds for the current time: "; + cin >> seconds; +} + +void printTime(int& hour, int& min, int& seconds, int form) +{ + int time = 0; + cout << "Please enter your choice of clock formatting." << endl; + cout << "Enter 1 for standard formatting." << endl; + cout << "Enter 2 for 24 hour formatting." << endl; + cout << "Enter 3 for military formatting." << endl; + cin >> form; + + switch (form) + { + // standard time + case 1: + cout << "Enter 1 for AM or 2 for PM: "; + cin >> time; + cout << "Standard time: " << endl; + switch (time) + { + case 1: + cout << hour << ":" << setw(2) << setfill('0') << min << ":"; + cout << setw(2) << setfill('0') << seconds << " AM"; + break; + case 2: + cout << hour << ":" << setw(2) << setfill('0') << min << ":"; + cout << setw(2) << setfill('0') << seconds << " PM"; + break; + default: + cout << "INVALID ENTRY. TRY AGAIN." << endl; + main(); + + } + break; + + // 24 hour formatting + case 2: + cout << "Enter 1 for AM or 2 for PM: "; + cin >> time; + cout << "24-hour Formatting: " << endl; + switch (time) + { + case 1: + cout << hour << ":" << setw(2) << setfill('0') << min << ":"; + cout << setw(2) << setfill('0') << seconds; + break; + case 2: + hour += 12; + cout << hour << ":" << setw(2) << setfill('0') << min << ":"; + cout << setw(2) << setfill('0') << seconds; + break; + default: + cout << "INVALID ENTRY. TRY AGAIN." << endl; + main(); + + } + break; + + + // military time + case 3: + cout << "Enter 1 for AM or 2 for PM: "; + cin >> time; + cout << "Military Formatting: " << endl; + switch (time) + { + case 1: + cout << hour << setw(2) << setfill('0') << min; + cout << setw(2) << setfill('0') << seconds; + break; + case 2: + hour += 12; + cout << hour << setw(2) << setfill('0') << min; + cout << setw(2) << setfill('0') << seconds; + break; + default: + cout << "INVALID ENTRY. TRY AGAIN." << endl; + main(); + + } + break; + + default: + cout << "INVALID ENTRY. TRY AGAIN." << endl; + main (); + + break; + } +} +RUN: +C:\Users\Till\CLionProjects\gitDemo\cmake-build-debug\gitDemo.exe +Enter hour for the current time:2 + Enter minute of the current time:2 + Enter seconds for the current time:2 + Please enter your + choice of clock formatting. +Enter 1 for standard formatting. +Enter 2 for 24 hour formatting. +Enter 3 for military formatting. +2 +Enter 1 for AM or 2 for PM:2 + 24-hour Formatting: +14:02:02 +Process finished with exit code 0 @@ -163,10 +298,125 @@ pp 226-229 10 pts #1 Submit: code & runs +CODE: +#include <iostream> +using std::cout; +using std::cin; +using std::endl; + +const int DAYS_PER_YEAR = 365; + +int GetAge ( ); +int CalcDays ( int age ); +void PrintResults ( int& age, int days ); + +int main ( ) +{ + int age = 0; + int days = 0; + + // Breakpoint 1 + // Put breakpoint on the following line + age = GetAge ( ); + days = CalcDays ( age ); + + // Breakpoint 2 + // Put breakpoint on the following line + PrintResults ( age, days ); + + return 0; +} +int GetAge ( ) +{ + int age; + + cout << "Please enter your age: "; + cin >> age; + + return age; +} +int CalcDays ( int years ) +{ + int days; + + days = years * DAYS_PER_YEAR; + + return days; +} +void PrintResults ( int& age, int days ) +{ + cout << age << "! Boy are you old!\n"; + cout << "Did you know that you are at least " << days << " days old?\n\n"; +} + + + +RUN: +C:\Users\Till\CLionProjects\gitDemo\cmake-build-debug\gitDemo.exe +Please enter your age:21 + 21! Boy are you old! +Did you know that you are at least 7665 days old? + + +Process finished with exit code 0 + + + +________________________________________________________________________________________________________________________ 8b 9.14 Programming Exercises pp 229 10 pts #1 Submit: code & run +CODE: +#include <iostream> +using namespace std; + +void draw (int w, int h) +{ + int i; + cout << char(218); + for (int i = 0; i <= (w - 2); i++) + cout << char(196); + cout << char(191) << endl; + for (int i = 0; i <= (h - 1); i++) { + cout << char(179); + for (int i = 0; i <= (w - 2); i++) + cout << " "; + cout << char(179) << endl; + } + cout << char(192); + for (int i = 0; i <= (w - 2); i++) + cout << char(196); + cout << char(217); +} + +int main() +{ + int h = 0, w = 0; + cout << "Enter a height for your rectangle: "; + cin >> h; + cout << "Enter a width for your rectangle: "; + cin >> w; + cout << "Rectangle: " << endl; + + draw(w,h); + + return 0; +} + +RUN: +C:\Users\Till\CLionProjects\gitDemo\cmake-build-debug\gitDemo.exe +Enter a height for your rectangle:2 + Enter a width for your rectangle:10 + Rectangle: +┌─────────┐ +│ │ +│ │ +└─────────┘ +Process finished with exit code 0 + + + Total: 55 pts
\ No newline at end of file diff --git a/CST116F2021-Lab4/lab4.cpp b/CST116F2021-Lab4/lab4.cpp new file mode 100644 index 0000000..72cde42 --- /dev/null +++ b/CST116F2021-Lab4/lab4.cpp @@ -0,0 +1,32 @@ +// +// Created by Till on 20-Oct-21. +// + +#include <iostream> +#include <cmath> // needed for square roots +using namespace std; + +int avg_score (float& num1, float& num2, float& num3) +{ + int avg = 0; + avg = ( num1 + num2 + num3 ) / 3; + return avg; +} + +int main() { + + float value1, value2, value3, average = 0.0; + + cout << "Enter 3 values that you want averaged." << endl; + cout << "Enter value 1: " << endl; + cin >> value1; + cout << "Enter value 2: " << endl; + cin >> value2; + cout << "Enter value 3: " << endl; + cin >> value3; + + average = avg_score(value1, value2, value3); + cout << "Your average score is: " << average << endl; + + return 0; +} |