• Nov 18, 2022 •AustinLeath
0 likes • 2 views
#include <iostream> #include "PlaylistNode.h" using namespace std; void PrintMenu(string title); int main() { string plTitle; cout << "Enter playlist's title:" << endl; getline(cin, plTitle); PrintMenu(plTitle); return 0; } void PrintMenu(string title) { Playlist list; string id; string sname; string aname; int length; int oldPos; int newPos; char choice; while(true) { cout << endl << title << " PLAYLIST MENU" << endl; cout << "a - Add song" << endl; cout << "d - Remove song" << endl; cout << "c - Change position of song" << endl; cout << "s - Output songs by specific artist" << endl; cout << "t - Output total time of playlist (in seconds)" << endl; cout << "o - Output full playlist" << endl; cout << "q - Quit" << endl << endl; cout << "Choose an option:" << endl; cin >> choice; cin.ignore(); if (choice == 'q') { exit(1); } else if (choice == 'a') { cout << "\nADD SONG" << endl; cout << "Enter song's unique ID: "; cin >> id; cin.ignore(); cout << "Enter song's name: "; getline(cin,sname); cout << "Enter artist's name: "; getline(cin,aname); cout << "Enter song's length (in seconds): "; cin >> length; list.AddSong(id, sname, aname, length); } else if (choice == 'd') { cout << "\nREMOVE SONG" << endl; cout << "Enter song's unique ID: "; cin >> id; list.RemoveSong(id); } else if (choice == 'c') { cout << "\nCHANGE POSITION OF SONG" << endl; cout << "Enter song's current position: "; cin >> oldPos; cout << "Enter new position for song: "; cin >> newPos; list.ChangePosition(oldPos, newPos); } else if (choice == 's') { cout << "\nOUTPUT SONGS BY SPECIFIC ARTIST" << endl; cout << "Enter artist's name: "; getline(cin, aname); list.SongsByArtist(aname); } else if (choice == 't') { cout << "\nOUTPUT TOTAL TIME OF PLAYLIST (IN SECONDS)" << endl; cout << "Total time: " << list.TotalTime() << " seconds" << endl; } else if (choice == 'o') { cout << endl << title << " - OUTPUT FULL PLAYLIST" << endl; list.PrintList(); } else { cout << "Invalid menu choice! Please try again." << endl; } } }
• Jul 30, 2023 •LeifMessinger
1 like • 6 views
//Constant prefix notation solver using bruh //Could make it infix or postfix later #include<string> #include<vector> #include<iostream> std::vector<long double> bruhBuff; long double operator ""bruh(long double a){ bruhBuff.push_back(a); return a; } long double operator ""bruh(const char op){ if(bruhBuff.size() < 2) throw "Bruh weak"; long double b = bruhBuff.back(); bruhBuff.pop_back(); long double a = bruhBuff.back(); bruhBuff.pop_back(); switch(op){ case (int)('+'): return a + b; case (int)('-'): return a - b; case (int)('*'): return a * b; case (int)('/'): return a / b; } return 69l; } int main(){ 1.0bruh; 2.0bruh; std::cout << '+'bruh << std::endl; return 0; }
• Sep 7, 2022 •LeifMessinger
0 likes • 0 views
#include <iostream> #include <cstring> int main(int argc, char** argv){ //With decimal if(strstr(argv[1], ".") != nullptr){ int i = 0; //Skip i to first non 0 digit while(argv[1][i] < '1' || argv[1][i] > '9') ++i; //If digit comes before decimal if((argv[1] + i) < strstr(argv[1], ".")){ //Good example of pointer arithmetic std::cout << strlen(argv[1] + i) - 1 << std::endl; //Another good example }else{ //If digit is after decimal std::cout << strlen(argv[1] + i) << std::endl; } }else{ //Without decimal int m = 0; int i = 0; while(argv[1][i] < '1' || argv[1][i] > '9') ++i; //In case of some number like 0045 for(; argv[1][i] != '\0'; ++i){ if(argv[1][i] >= '1' && argv[1][i] <= '9') m = i + 1; } std::cout << m << std::endl; } return 0; }
0 likes • 1 view
#include <iostream> #include <cmath> #include <string.h> using namespace std; int main() { string tickerName; int numOfContracts; float currentOptionValue; cout << "Enter a stock ticker: "; getline(cin, tickerName); cout << "Enter the current number of " << tickerName << " contracts you are holding: "; cin >> numOfContracts; cout << "Enter the current price of the option: "; cin >> currentOptionValue; cout << "The value of your " << tickerName << " options are: $" << (currentOptionValue * 100.00) * (numOfContracts); cout << endl; return 0; }
• Jun 17, 2024 •oceantran27
0 likes • 3 views
#include <iostream> using namespace std; int main { cout << 1; }
#include <iostream> #include <fstream> #include <string> #include <cstring> using namespace std; //This program makes a new text file that contains all combinations of two letters. // aa, ab, ..., zy, zz int main(){ string filename = "two_letters.txt"; ofstream outFile; outFile.open(filename.c_str()); if(!outFile.is_open()){ cout << "Something's wrong. Closing..." << endl; return 0; } for(char first = 'a'; first <= 'z'; first++){ for(char second = 'a'; second <= 'z'; second++){ outFile << first << second << " "; } outFile << endl; } return 0; }