• 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; }
• 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; } } }
• Aug 31, 2020 •joshwrou
1 like • 2 views
#include <iostream> using namespace std; int main() { cout << "Hello World!\n"; // Prints out "Hello World" return 0; }
• Sep 3, 2023 •AustinLeath
0 likes • 10 views
#include "stdio.h" #include <stdlib.h> int main (int argCount, char** args) { int a = atoi(args[1]); int b = atoi(args[2]); unsigned int sum = 0; unsigned int p = 1; for (unsigned int i = 1; i < b; i++) { p = p * i; } // (b!, (1 + b)!, (2 + b)!, ..., (n + b)!) for (unsigned int i = 0; i < a; i++) { p = p * (i + b); sum = sum + p; } printf("y: %u\n", sum); return 0; }
0 likes • 4 views
#include <iostream> using namespace std; int main() { const int ROW_SIZE = 2; const int COLUMN_SIZE = 5; //establish all variables int matrix[ROW_SIZE][COLUMN_SIZE]; int minVal; for (int i = 0; i < ROW_SIZE; ++i) // for loop to ask user to enter data. { for (int h = 0; h < COLUMN_SIZE; ++h) { cout << "Enter data for row #" << i + 1 << " and column #" << h + 1 << ": "; cin >> matrix[i][h]; } } cout << "You entered: " << endl; for (int i = 0; i < ROW_SIZE; ++i) //for statements to output the array neatly { for (int h = 0; h < COLUMN_SIZE; ++h) { cout << matrix[i][h] << "\t"; } cout << endl; } cout << "Minimum for each row is: {"; for (int i = 0; i < ROW_SIZE; i++) //for statements to find the minimum in each row { minVal = matrix[i][0]; for (int h = 0; h < COLUMN_SIZE; h++) { if (matrix[i][h] < minVal) // if matrix[i][h] < minVal -> minVal = matrix[i][h]; { minVal = matrix[i][h]; } } cout << minVal << ", "; } cout << "}" << endl; cout << "Minimum for each column is: {"; for (int i = 0; i < COLUMN_SIZE; i++) //for statements to find the minimum in each column { minVal = matrix[0][i]; for (int h = 0; h < ROW_SIZE; h++) { if (matrix[h][i] < minVal) //replaces minVal with array index for that column that is lowest { minVal = matrix[h][i]; } } cout << minVal << ", "; } cout << "}" << endl; return 0; }
• Apr 15, 2025 •hasnaoui1
int main()