• Jun 17, 2024 •oceantran27
0 likes • 3 views
#include <iostream> using namespace std; int main { cout << 1; }
• Nov 18, 2022 •AustinLeath
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; }
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 • 1 view
#include "goat.h" //include goat.h void Goat::setBreed(string breed) { this->breed = breed; } void Goat::setWeight(float weight) { this->weight = weight; } void Goat::setName(string name) { this->name = name; } void Goat::setGender(char gender) { this->gender = gender; } void Goat::setSpayed(bool goatIsSpayed) { this->goatIsSpayed = goatIsSpayed; } void Goat::setRegistrationID(string registrationID) { this->registrationID = registrationID; } void Goat::setColor(string color) { this->color = color; } void Goat::setOtherComments(string otherComments) { this->otherComments = otherComments; } string Goat::getBreed() { return breed; } float Goat::getWeight() { return weight; } string Goat::getName() { return name; } char Goat::getGender() { return gender; } bool Goat::getSpayed() { return goatIsSpayed; } string Goat::getRegistrationID() { return registrationID; } string Goat::getColor() { return color; } string Goat::getOtherComments() { return otherComments; } Goat::Goat() { breed = ""; weight = 0.0; name = ""; gender = '\0'; goatIsSpayed = false; registrationID = ""; color = ""; otherComments = ""; } Goat::Goat(string goatBreed, float goatWeight, string goatName, char goatGender, bool goatSpayedStatus, string goatRegistrationID, string goatColor, string goatOtherComments) { breed = goatBreed; weight = goatWeight; name = goatName; gender = goatGender; goatIsSpayed = goatSpayedStatus; registrationID = goatRegistrationID; color = goatColor; otherComments = goatOtherComments; } Goat::~Goat() { cout << "goat destroyed" << endl; } void Goat::printinfo() { cout << "Breed: " << breed << endl << "weight: " << weight << endl << "Name: " << name << endl << "Gender: " << gender << endl << "is Spayed: "; if(goatIsSpayed) { //here I do a logical test on boolean goatIsSpayed. if true cout << true else cout << false cout << "True"; } else { cout << "False"; } cout << endl << "Registration ID: " << registrationID << endl << "Color Description: " << color << endl << "Other Comments: " << otherComments << endl << endl; }
• 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; }
0 likes • 0 views
using namespace std; class Hash { int BUCKET; // No. of buckets // Pointer to an array containing buckets list<int> *table; public: Hash(int V); // Constructor // inserts a key into hash table void insertItem(int x); // deletes a key from hash table void deleteItem(int key); // hash function to map values to key int hashFunction(int x) { return (x % BUCKET); } void displayHash(); }; Hash::Hash(int b) { this->BUCKET = b; table = new list<int>[BUCKET]; } void Hash::insertItem(int key) { int index = hashFunction(key); table[index].push_back(key); } void Hash::deleteItem(int key) { // get the hash index of key int index = hashFunction(key); // find the key in (inex)th list list <int> :: iterator i; for (i = table[index].begin(); i != table[index].end(); i++) { if (*i == key) break; } // if key is found in hash table, remove it if (i != table[index].end()) table[index].erase(i); } // function to display hash table void Hash::displayHash() { for (int i = 0; i < BUCKET; i++) { cout << i; for (auto x : table[i]) cout << " --> " << x; cout << endl; } } // Driver program int main() { // array that contains keys to be mapped int a[] = {15, 11, 27, 8, 12}; int n = sizeof(a)/sizeof(a[0]); // insert the keys into the hash table Hash h(7); // 7 is count of buckets in // hash table for (int i = 0; i < n; i++) h.insertItem(a[i]); // delete 12 from hash table h.deleteItem(12); // display the Hash table h.displayHash(); return 0; }