float AverageDisplacement(float u, float v, float t) { return ((u + v) / 2) * t; }
Describe(Average_Displacement)
{
It(Calculate_Average_Displacement)
{
Assert::That(AverageDisplacement(5, 8, 2), Equals(13));
}
};
This calculator can multiply, divide, add and subtract.
#include <iostream>
#include <string>
class Operations
{
public:
float Addition(float a, float b) {
return a + b;
}
float Subtraction(float a, float b) {
return a - b;
}
float Multiplication(float a, float b) {
return a * b;
}
float Division(float a, float b) {
return a / b;
}
};
void CaculatorInterface();
int main()
{
CaculatorInterface();
return 0;
}
void CaculatorInterface() {
Operations OP;
std::string CNT;
std::string Op;
char op;
float A;
float B;
float result;
for (;;) {
system("cls");
std::cout << "\n\n\n\n\t\tEnter Integar : ";
std::cin >> A;
std::cout << "\n\n\t\tEnter Operator : ";
std::cin >> op;
std::cout << "\n\n\t\tEnter Second Integar : ";
std::cin >> B;
if (op == '+') {
result = OP.Addition(A, B);
Op = "sum";
}
if (op == '-') {
result = OP.Subtraction(A, B);
Op = "Diffrence";
}
if (op == '*') {
result = OP.Multiplication(A, B);
Op = "Product";
}
if (op == '/') {
result = OP.Division(A, B);
Op = "Quationt";
}
std::cout << "\n\n\n\t\t" << Op << " : " << result;
std::cout << "\n\n\t\t";
std::cin >> CNT;
if (CNT == "Continue" || CNT == "continue") {
continue;
}
else {
system("cls");
std::cout << "\n\n\n\n\t\tInviled Input : " << CNT << "\n\t\t";
system("PAUSE");
system("cls");
exit(0);
}
}
return;
}
Describe(none)
{
It(none)
{
Assert::That("some value", Equals("another value"));
}
};
This function claculates the area of a Triangle;
float AreaOfTriangle(float w, float h) {
float A = (w * h) / 2;
return A;
}
Describe(any_group_name_you_want)
{
It(should_do_something)
{
Assert::That(AreaOfTriangle(4, 3), Equals(6));
Assert::That(AreaOfTriangle(6, 10), Equals(30));
Assert::That(AreaOfTriangle(10, 2), Equals(10));
}
};