aboutsummaryrefslogtreecommitdiff
path: root/homework 4/program.cpp
diff options
context:
space:
mode:
authorNataliia Brown <[email protected]>2024-02-09 09:34:48 -0800
committerNataliia Brown <[email protected]>2024-02-09 09:34:48 -0800
commit0805347fc8bbca5dbfd670b378b316740ae395db (patch)
treee3428978efaa1e4dcd8f8508b1846ed275c5ed8a /homework 4/program.cpp
parentadd deadline (diff)
downloadhomework-4-natabrown-0805347fc8bbca5dbfd670b378b316740ae395db.tar.xz
homework-4-natabrown-0805347fc8bbca5dbfd670b378b316740ae395db.zip
Commit
Diffstat (limited to 'homework 4/program.cpp')
-rw-r--r--homework 4/program.cpp130
1 files changed, 130 insertions, 0 deletions
diff --git a/homework 4/program.cpp b/homework 4/program.cpp
new file mode 100644
index 0000000..4eee49e
--- /dev/null
+++ b/homework 4/program.cpp
@@ -0,0 +1,130 @@
+// Name: Nataliia Brown
+// Date: 2/5/24
+// Class: CST 116
+// Assignment: Homework 4
+
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+
+void Menu() {
+ cout << endl << endl << "Choose an option: enter 1 for A, 2 for B, 3 for C or 4 for D" << endl;
+ cout << "A. Print100" << endl;
+ cout << "B. Input Personal Information" << endl;
+ cout << "C. Print Fibonacci" << endl;
+ cout << "D. Exit" << endl;
+}
+
+void Print100(size_t n) {
+ for (int j = 0; j <= n; j++) {
+ cout << j << " ";
+ }
+ cout << endl;
+}
+
+void PrintFibonacci(size_t n) {
+ int k, t1 = 0, t2 = 1, nextTerm = 0;
+
+ cout << "Enter the number of terms: ";
+ cin >> k;
+
+ cout << "Fibonacci Series: ";
+
+ for (int i = 1; i <= k; ++i) {
+
+ if (i == 1) {
+ cout << t1 << ", ";
+ continue;
+ }
+ if (i == 2) {
+ cout << t2 << ", ";
+ continue;
+ }
+ nextTerm = t1 + t2;
+ t1 = t2;
+ t2 = nextTerm;
+
+ cout << nextTerm << ", ";
+ }
+
+
+}
+
+struct UserDob
+{
+ int day;
+ int month;
+ int year;
+};
+
+UserDob InputPersonalInfo()
+{
+ UserDob user = {};
+
+ cout << "\nDay: ";
+ cin >> user.day;
+
+ cout << "Month: ";
+ cin >> user.month;
+
+ cout << "Year: ";
+ cin >> user.year;
+
+ return user;
+
+}
+
+void PrintUserInfo(UserDob newUser) {
+
+ cout << "User's DOB: " << newUser.month << "/" << newUser.day << "/" << newUser.year << endl;
+}
+
+int main() {
+ int i;
+ Menu();
+ cin >> i;
+
+
+ while (i != 4) {
+ system("cls");
+ if (i == 1)
+
+ {
+ cout << "Enter the number for Print 100 function: ";
+ int n;
+ cin >> n;
+ Print100(n);
+ }
+ else if (i == 2)
+ {
+ UserDob newUser = InputPersonalInfo();
+ PrintUserInfo(newUser);
+ }
+ else if (i == 3)
+ {
+ PrintFibonacci(i);
+ }
+
+ else if (i == 4)
+ {
+ return 0;
+ }
+ else
+ {
+ cout << "Print Menu";
+ }
+ int j;
+ Menu();
+
+ cin >> j;
+ i = j;
+ }
+
+
+}
+
+
+