answersLogoWhite

0

What else can I help you with?

Continue Learning about Engineering

When writing code what can be nested for statement or if statement or both?

Both. for (int x=0; x<10; ++x) { // outer loop for (int y=0; y<10; ++y) { // nested loop std::cout << x*y << '\t'; } // end nested loop std::cout << std::endl; } // end outer loop std::cout << std::endl; void f(bool x, bool y) { if (x==y) { if (x) { std::cout << "x and y are both true\n"; } else { std::cout << "x and y are both false\n"; } } else { if (x) { std::cout << "Only x is true\n" } else { std::cout << "Only y is true\n" } } } Note that the nested if within the else clause of the outer if can also be written as an else if statement: void f(bool x, bool y) { if (x==y) { if (x) { std::cout << "x and y are both true\n"; } else { std::cout << "x and y are both false\n"; } } else if (x) { std::cout << "Only x is true\n" } else { std::cout << "Only y is true\n" } }


How do you use sin in c plus plus?

#include<iostream> int main() { std::cout << "sin(1) = " << std::sin(1.0) << std::endl; std::cout << "cos(1) = " << std::cos(1.0) << std::endl; std::cout << "tan(1) = " << std::tan(1.0) << std::endl; std::cout << "asin(1) = " << std::asin(1.0) << std::endl; std::cout << "acos(1) = " << std::acos(1.0) << std::endl; std::cout << "atan(1) = " << std::atan(1.0) << std::endl; } Output: sin(1) = 0.841471 cos(1) = 0.540302 tan(1) = 1.55741 asin(1) = 1.5708 acos(1) = 0 atan(1) = 0.785398


How do you split a string in delimit c plus plus?

#include<iostream> #include<vector> #include<string> std::vector<std::string> parse (const std::string& s, const char delim) { std::vector<std::string> result {}; auto start = 0U; auto end = s.find (delim); while (end != s.npos) { result.push_back (s.substr(start, end - start)); start = ++end; end = s.find (delim, start); } result.push_back (s.substr (start, s.npos - start)); return result; } std::vector<std::string> parse (const std::string& s, const std::string& delim) { std::vector<std::string> result {}; auto start = 0U; auto end = s.find (delim); while (end != s.npos) { result.push_back (s.substr(start, end - start)); start = end + delim.length(); end = s.find (delim, start); } result.push_back (s.substr (start, s.npos - start)); return result; } int main() { std::string str1 = "This is a string that will be parsed by a single-space delimiter."; std::string str2 = "This==is==a==string==that==will==be==parsed==by==equal==operator."; std::string str3 = "This string has no delimiter."; std::cout << str1 << std::endl; std::vector<std::string> v1 = parse (str1, ' '); for (auto i : v1 ) std::cout << i << std::endl; std::cout << std::endl; std::cout << str2 << std::endl; std::vector<std::string> v2 = parse (str2, "=="); for (auto i : v2 ) std::cout << i << std::endl; std::cout << std::endl; std::cout << str3 << std::endl; std::vector<std::string> v3 = parse (str3, '\\'); for (auto i : v3 ) std::cout << i << std::endl; std::cout << std::endl; }


A c comma c plus plus program that can accept first name surname and display it?

int main() { std::string first, last; std::cout << "Enter your first name: "; std::cin >> first; std::cout << "Enter your last name: "; std::cin >> last; }


How do you make quiz master in c plus plus programm?

Assuming the quiz is a simple question/answer style quiz, use a map to associate question strings with answer strings. In order to prevent people from simply examining the program resources to get the answers, you should also consider encrypting the map. For multiple choice quizzes, use a structure containing the question string, a vector of strings for the possible answers and an unsigned integer to identify the correct answer (as an index into the vector).