Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.1 kB
1
Indexable
Never
#include "Maths.h"
#include <string>
#include <iostream>

using namespace std;

int CHOICE;

vector<float> getVector(int vectorNumber) {
    cout << "Enter vector " << vectorNumber << " (x, y, z): ";
    string input;
    getline(cin, input);
    stringstream ss(input);
    vector<float> vector;
    float number;
    while (ss >> number) {
        vector.push_back(number);
        char comma;
        ss >> comma;
    }

    cout << "Vector " << vectorNumber << ": ";
    for (float i : vector) {
        cout << i << " ";
    }
    cout << endl;

    return vector;
}

void newline() {
    cout << "\n";
}

std::string vectorToString(const std::vector<float>& vec) {
    std::stringstream ss;
    for (size_t i = 0; i < vec.size(); ++i) {
        ss << vec[i];
        if (i < vec.size() - 1) {
            ss << ", ";
        }
    }
    return ss.str();
}

int main() {
    cout << "Week 2 Vector Calculator" << endl;

    vector<float> vector1 = getVector(1);
    vector<float> vector2 = getVector(2);

    std::string vectorStr; // Declare vectorStr here

    cout << "What type of arithmetic operation would you like to perform?" << endl
        << " (1) Addition" << endl
        << " (2) Subtraction" << endl
        << " (3) Multiplication" << endl
        << " (4) Negate" << endl
        << " (5) Scale" << endl
        << " (6) Distance" << endl;

    cin >> CHOICE;

    switch (CHOICE) {
    case 1:
        cout << "You chose Addition." << endl;
        vectorStr = vectorToString(addVectors(vector1, vector2)); // Converting here
        std::cout << "Vector as string: " << vectorStr << std::endl;
        break;
    case 2:
        cout << "You chose Subtraction." << endl;
        
        break;
    case 3:
        cout << "You chose Multiplication." << endl;
        
        break;
    case 4:
        cout << "You chose Negate." << endl;
        
        break;
    case 5:
        cout << "You chose Scale." << endl;
        
        break;
    case 6:
        cout << "You chose Distance." << endl;
        
        break;
    default:
        cout << "Invalid choice" << endl;
        break;
    }
    return 0;
}