• Nov 18, 2022 •AustinLeath
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; }
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! }
• 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; }
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; }
• 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; }
• Jun 30, 2023 •Iceman_71
0 likes • 7 views
#include <iostream> using namespace std; int main() { int arr[] = {5, 1, 4, 20, 10, 2, 13, 11, 6, 21}; int greed[] = {0, 0, 0, 0}; int k = 0; int i; int set_index; while (k < 4) { i = 0; while (i < 10) { if (arr[i] > greed[k]) { greed[k] = arr[i]; set_index = i; } i++; } arr[set_index] = 0; k++; } cout << greed[0] << " " << greed[1] << " " << greed[2] << " " << greed[3] << endl; }