Skip to main content

Infection Simulation

Nov 18, 2022AustinLeath
Loading...

More C++ Posts

Stock Options Analyzer

Nov 18, 2022AustinLeath

0 likes • 0 views

#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;
}

Simple Greedy sort C++

Jun 30, 2023Iceman_71

0 likes • 5 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;
}

minimum matrix values

Nov 18, 2022AustinLeath

0 likes • 3 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;
}

Test

Jun 17, 2024oceantran27

0 likes • 2 views

#include <iostream>
using namespace std;
int main {
cout << 1;
}

sum function

Sep 3, 2023AustinLeath

0 likes • 9 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;
}

C++ SigFigs

Sep 7, 2022LeifMessinger

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;
}