Compare commits

..

No commits in common. "678b854b74e364d32bb6915afd791812bcf4e429" and "9a72aa272888b42226c44f7658a6c04fd8c81f6e" have entirely different histories.

6 changed files with 3 additions and 147 deletions

View file

@ -10,5 +10,3 @@ add_executable(FunctionArguments FunctionArguments.cc)
add_executable(exceptions exceptions.cc)
add_executable(HeapMemory HeapMemory.cc)
add_executable(AbstractClasses AbstractClasses.cc)
add_executable(vector vector.cc)
add_executable(Vector2 Vector2.cc)

View file

@ -1,4 +1,3 @@
#include <format>
#include <iostream>
#include <string>
@ -12,7 +11,7 @@ void sus(std::string susValue, std::string& susReference)
void print_string(std::string nameOf, std::string& string)
{
std::cout << std::format("The value of {} is {}", nameOf, string) << std::endl;
std::cout << "The value of " << nameOf << " is " << string << std::endl;
}
void print_sussy_strings(std::string& sus1, std::string& sus2)

View file

@ -1,54 +0,0 @@
#include <format>
#include <iostream>
#include <string>
class Vector2 {
public:
double x;
double y;
Vector2(double x, double y)
{
this->x = x;
this->y = y;
}
Vector2 operator+(const Vector2& vec)
{
return Vector2(x + vec.x, y + vec.y);
}
Vector2 operator-(const Vector2& vec)
{
return Vector2(x - vec.x, y - vec.y);
}
Vector2 operator*(const Vector2& vec)
{
return Vector2(x * vec.x, y * vec.y);
}
Vector2 operator/(const Vector2& vec)
{
return Vector2(x / vec.x, y / vec.y);
}
constexpr std::string to_string() {
return std::format("<{},{}>",x,y);
}
};
int main()
{
Vector2 position(5, 10);
Vector2 offset(10, 5);
Vector2 destination = position + offset;
Vector2 negativeDestination = position - offset;
Vector2 multipledDestination = position * offset;
Vector2 dividedDestination = position / offset;
std::cout << std::format("positive destination: {}", destination.to_string()) << std::endl;
std::cout << std::format("negative destination: {}", negativeDestination.to_string()) << std::endl;
std::cout << std::format("multipled destination: {}", multipledDestination.to_string()) << std::endl;
std::cout << std::format("divided destination: {}", dividedDestination.to_string()) << std::endl;
}

View file

@ -1,4 +1,3 @@
#include <format>
#include <iostream>
#include <string>
@ -12,7 +11,6 @@ public:
static void PrintName(Crewmate crewmate)
{
std::cout << "Crewmates Name: " << crewmate.name << std::endl;
std::cout << std::format("Crewmates Name: {}", crewmate.name) << std::endl;
}
};
@ -35,6 +33,6 @@ int main()
crewmate.PrintName(crewmate);
if (imposter.imposter) {
std::cout << std::format("Imposter is a sussy imposter and their name is {}", imposter.name) << std::endl;
std::cout << "Imposter is a sussy imposter and their name is " << imposter.name << std::endl;
}
}

View file

@ -1,5 +1,4 @@
import Math;
#include <format>
#include <iostream>
void print_squared(double x);
@ -12,5 +11,5 @@ int main()
void print_squared(double x)
{
std::cout << std::format("the squared of {} is {}", x, Math::square(x)) << std::endl;
std::cout << "the squared of " << x << " is " << Math::square(x) << std::endl;
}

View file

@ -1,84 +0,0 @@
#include <format>
#include <iostream>
#include <stdexcept>
class Vector {
public:
Vector(int size)
: elem { new double[size] }
, sz { size }
{
for (int i = 0; i != size; ++i) {
elem[i] = 0;
}
}
~Vector()
{
delete[] elem;
}
Vector(const Vector& a)
: elem(new double[a.sz])
, sz { a.sz }
{
for (int i = 0; i!=sz;++i) {
elem[i] = a.elem[i];
}
}
Vector& operator=(const Vector& a) {
double* p = new double[a.sz];
for (int i =0; i!=sz; ++i) {
p[i] = a.elem[i];
}
delete[] elem;
elem = p;
sz = a.sz;
return *this;
}
double& operator[](int i)
{
if (i < 0 || i > size() - 1) {
throw std::out_of_range { "Vector::operator[]" };
}
return elem[i];
}
void print_element(int i)
{
if (i < 0 || i > size() - 1) {
throw std::out_of_range { "Vector::print_element(int i)" };
}
std::cout << std::format("element[{}] : {}", i, elem[i]) << std::endl;
}
int size() const
{
return sz;
}
private:
double* elem;
int sz;
};
int main()
{
Vector vec(3);
vec[0] = 1;
vec[1] = 2;
vec[2] = 3;
vec.print_element(0);
vec.print_element(1);
vec.print_element(2);
Vector longVector(100000);
for (int i = 0; i < longVector.size(); i++) {
longVector[i] = 21;
}
}