a.h b.h 1 #include 2 #include "b.h" 3 /** 4 5 6 7 8 10 2 3 4 5 6 7 8 9 234 */ string charToString(char c); Tester2.cpp 3 Converts a character into the corresponding string form. For example, calling charToString('Q') returns the string "Q". @param c the character to convert. @return the string form of the character. #include #include "a.h" /** */ string boolToString(bool b); 1 #include using namespace std; #include "a.h" Returns a string version of the bool argument. @param b the Boolean value to convert @return "true" or "false" } 5 6 int main() 7 { 8 9 10 11 12 13 cout << "boolToString(true): << boolToString(true) << endl; cout << "Expected: true" << endl; cout << "charToString('X'): << charToString('X') << endl; cout << "Expected: X" << endl; 11
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
The two header files a.h and b.h both have a prototype for a single function. Both have at least two mistakes. Fix the mistakes so that the tester program works correctly.
Solution: Fix the mistakes so that the tester program works correctly.
Code :
#include <iostream>
#include <string>
using namespace std;
string charToString(char c)
{
return string(1, c);
}
string boolToString(bool b)
{
if (b)
return "true";
return "false";
}
int main(int argc, char const *argv[])
{
char c = 'Q';
cout << charToString(c) << endl;
cout << boolToString(true) << endl;
return 0;
}
Step by step
Solved in 2 steps with 2 images