• Nov 18, 2022 •AustinLeath
0 likes • 4 views
#include <iostream> using namespace std; int main() { cout << "Hello, World!" << endl; return 0; }
0 likes • 0 views
/* Algorithm: Step 1: Get radius of the cylinder from the user and store in variable r Step 2: Get height of the cylinder from the user and store in variable h Step 3: Multiply radius * radius * height * pi and store in v Step 4: Display the volume */ #include <iostream> using namespace std; int main() { float r; //define variable for radius float h; //define variable for height float v; float pi; pi=3.1416; cout<<"Enter radius:"; cin>>r; cout<<"Enter height:"; cin>>h; v=r*r*h*pi; //compute volume cout<<"Radius:"<<r<<"\tHeight:"<<h<<endl; //display radius and height cout<<"\n************************\n"; cout<<"Volume:"<<v<<endl;//display volume return 0; }
• Oct 7, 2023 •AustinLeath
0 likes • 12 views
#include <iostream> #include <cstring> #include <unistd.h> #include <sys/utsname.h> int main() { char newHostname[] = "newhostname"; // Replace with the desired hostname if (sethostname(newHostname, strlen(newHostname)) == 0) { std::cout << "Hostname set to: " << newHostname << std::endl; // Optionally, update the /etc/hostname file to make the change permanent FILE *hostnameFile = fopen("/etc/hostname", "w"); if (hostnameFile != NULL) { fprintf(hostnameFile, "%s\n", newHostname); fclose(hostnameFile); } else { perror("Failed to update /etc/hostname"); } } else { perror("Failed to set hostname"); } return 0; }
• Apr 15, 2025 •hasnaoui1
int main()
0 likes • 10 views
#include <iostream> using namespace std; /* Description: uses switch case statements to determine whether it is hot or not outside. Also uses toupper() function which forces user input char to be uppercase in order to work for the switch statement */ int main() { char choice; cout << "S = Summer, F = Fall, W = Winter, P = Spring" << endl; cout << "Enter a character to represent a season: ";asdasdasdasd cin >> choice; enum Season {SUMMER='S', FALL='F', WINTER='W', SPRING='P'}; switch(toupper(choice)) // This switch statement compares a character entered with values stored inside of an enum { case SUMMER: cout << "It's very hot outside." << endl; break; case FALL: cout << "It's great weather outside." << endl; break; case WINTER: cout << "It's fairly cold outside." << endl; break; case SPRING: cout << "It's rather warm outside." << endl; break; default: cout << "Wrong choice" << endl; break; } return 0; }
0 likes • 5 views
#include <iostream> using namespace std; /* Function: get_coeff Parameters: double& coeff, int pos passed from bb_4ac Return: type is void so no return, but does ask for user to input data that establishes what a b and c are. */ void get_coeff(double& coeff, int pos) { char position; if(pos == 1) { position = 'a'; } else if(pos == 2) { //a simple system to determine what coefficient the program is asking for. position = 'b'; } else { position = 'c'; } cout << "Enter the co-efficient " << position << ":"; //prompt to input coeff coeff = 5; //input coeff } /* Function: bb_4ac Parameters: no parameters passed from main, but 3 params established in function, double a, b, c. Return: b * b - 4 * a * c */ double bb_4ac() { double a, b, c; //coefficients of a quadratic equation get_coeff(a, 1); // call function 1st time get_coeff(b, 2); // call function 2nd time get_coeff(c, 3); // call function 3rd time return b * b - 4 * a * c; //return b * b - 4 * a * c } int main() { cout << "Function to calculate the discriminant of the equation. . . " << endl; double determinate = bb_4ac(); //assign double determinate to bb_4ac function cout << "The discriminant for given values is: " << determinate << endl; //output the determinate! }