#include<iostream> int doubleValue(int x) { return x * 2; }
- #include<iostream>
- int doubleValue(int x) {
- return x * 2;
- }
int main(){int x = 5; //example valueint result = doubleValue(x);std::cout << "The double of " << x << " is " << result << std::endl;return 0;}
// TODO: Replace examples and use TDD by writing your own tests Describe(sampleTests) { It(shouldBe) { Assert::That(doubleValue(5), Equals(10)); } };
- // TODO: Replace examples and use TDD by writing your own tests
Describe(any_group_name_you_want){It(should_do_something){Assert::That("some value", Equals("another value"));}};- Describe(sampleTests) {
- It(shouldBe) {
- Assert::That(doubleValue(5), Equals(10));
- }
- };
class Triangle {
public:
static int otherAngle(int a, int b)
{
return (180 - (a + b));
}
};
// TODO: Replace examples and use TDD by writing your own tests
Describe(sampleTests) {
It(shouldBe) {
Assert::That(Triangle::otherAngle(30, 60), Equals(90));
Assert::That(Triangle::otherAngle(60, 60), Equals(60));
Assert::That(Triangle::otherAngle(43, 78), Equals(59));
Assert::That(Triangle::otherAngle(10, 20), Equals(150));
}
};
#include<iostream>
int doubleValue(int x) {
return x * 2;
}
int main(){
int x = 5; //example value
int result = doubleValue(x);
std::cout << "The double of " << x << " is " << result << std::endl;
return 0;
}
// TODO: Replace examples and use TDD by writing your own tests
Describe(any_group_name_you_want)
{
It(should_do_something)
{
Assert::That("some value", Equals("another value"));
}
};
It prints out the leaderboard by iterating through the sorted vector and printing out each student's name and score.
#include <iostream>
#include <vector>
#include <algorithm>
struct Student {
std::string name;
int score;
};
bool compare(const Student &a, const Student &b) {
return a.score > b.score;
}
int main() {
std::vector<Student> students;
// Add some students to the vector
students.push_back({"Alex", 90});
students.push_back({"max", 70});
students.push_back({"Charlie", 85});
students.push_back({"David", 78});
students.push_back({"Eve", 94});
// Sort the students by score
std::sort(students.begin(), students.end(), compare);
// Print the leaderboard
std::cout << "Leaderboard:" << std::endl;
for (const auto &student : students) {
std::cout << student.name << ": " << student.score << std::endl;
}
return 0;
}