1
0

String vector tester.

This commit is contained in:
Captain ALM 2023-08-20 22:19:14 +01:00
parent 798006c8d0
commit 891ee1959a
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1

View File

@ -1,42 +1,49 @@
#include <string>
#include <vector>
#include <algorithm>
#include <iostream> #include <iostream>
#include <random>
#include <chrono>
class A { using string = std::string;
public: using svector = std::vector<string>;
A() {
std::cout << "Class A Created\n";
}
virtual ~A() {
std::cout << "Class A Destroyed\n";
}
};
class B { string prompts(const string&,bool*);
public: void sortVStringsAsc(svector &v);
B() {
std::cout << "Class B Created\n";
}
~B() {
std::cout << "Class B Destroyed\n";
}
};
class C : public A { int main() {
B b{}; svector inputs;
public: bool s{true};
C() { while (s) {
std::cout << "Class C Created\n"; auto inp = prompts("Enter a string (Invalid to begin processing): ",&s);
if (s) inputs.push_back(inp);
} }
virtual ~C() { sortVStringsAsc(inputs);
std::cout << "Class C Destroyed\n"; for (const auto &c : inputs) std::cout << c << "\n";
}
};
int main()
{
A v{};
B w{};
C x{};
return 0; return 0;
} }
void sortVStringsAsc(svector &v) {
sort(v.begin(), v.end(), [] (const string &x, const string &y) {return x.length() < y.length();});
}
double sumList(const std::vector<double> &l) {
double sum = 0.0;
for (const auto &c : l) sum += c;
return sum;
}
class A {
std::vector<string> s;
};
string prompts(const string &message, bool *success) {
string tr{""};
*success = false;
std::cout << message;
if (!(std::cin >> tr)) {
std::cin.clear();
std::cin.ignore();
return "";
}
*success = true;
return tr;
}