#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
#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; }
int main() { std::string first, last; std::cout << "Enter your first name: "; std::cin >> first; std::cout << "Enter your last name: "; std::cin >> last; }
#include<iostream> #include<vector> #include<string> struct employee { std::string forename; std::string surname; std::string department; }; struct directory { std::vector<employee> v; void add_employee (const std::string&, const std::string&, const std::string&); }; void directory::add_employee (const std::string& forename, const std::string& surname, const std::string& department) { v.push_back (employee{forename, surname, department}); } int main() { std::string forename, surname, department; std::cout << "Enter employee's forename: "; std::cin >> forename; std::cout << "Enter employee's surname: "; std::cin >> surname; std::cout << "Enter employee's department: "; std::cin >> department; add_employee (forename, surname, department); }
#include<iostream> #include<fstream> #include<vector> #include<string> std::string get_input_file() { while (true) { std::cout << "Enter the input file name: "; std::string filename; std::getline (std::cin, filename); std::ifstream file (filename); if (file.is_open()) { file.close(); return filename; } std::cerr << "The file could not be opened.\n" << std::endl; } } std::string get_search_word() { while (true) { std::cout << "Enter the word to search for: "; std::string search; std::cin >> search; if (search.size()) return search; std::cerr << "The search word cannot be an empty string.\n" << std::endl; } } std::vector<size_t> get_offsets(const std::string& filename, const std::string& search) { std::vector<size_t> offsets; std::ifstream file (filename); if (!file.is_open()) throw std::exception("The file could not be opened."); size_t offset = 0; while (!file.eof()) { size_t pos = 0; char c; while (!file.read(&c, 1).eof() && c!=search[pos]) ++offset; while (pos!=search.size()-1 && !file.read(&c, 1).eof() && c==search[++pos]); if (pos==search.size()-1 && c==search[pos]) offsets.push_back (offset); offset += pos; pos = 0; } file.close(); return offsets; } int main() { std::cout << "Word Search\n" << std::endl; std::string filename = get_input_file(); std::string search = get_search_word(); std::vector<size_t> offsets = get_offsets (filename, search); std::cout << "The word was found " << offsets.size() << " time" << (offsets.size()==1?"":"s") << ".\n" << std::endl; if (offsets.size()) { std::cout << "Offsets:\n"; for (auto off : offsets) std::cout << off << std::endl; } }
iwould like to know what lymphocele means
Lymphocele is a condition that usually happens after extensive pelvic surgery. This is when lymphatic fluid collects within the retroperitoneal space.
#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
#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; }
The following example demonstrates all 4 loop structures in C++. #include<iostream> int main() { int i; std::cout<<"For loop...\n"<<std::endl; for(i=0; i<10; ++i) std::cout<<i; std::cout<<'\n'<<std::endl; std::cout<<"While loop...\n"<<std::endl; i=0; while(i<10) std::cout<<i++; std::cout<<'\n'<<std::endl; std::cout<<"Do-while loop...\n"<<std::endl; i=0; do { std::cout<<i; }while( ++i<10 ); std::cout<<'\n'<<std::endl; std::cout<<"Goto loop...\n"<<std::endl; i=0; again: std::cout<<i; if(++i<10) goto again; std::cout<<'\n'<<std::endl; } Output: For loop... 0123456789 While loop... 0123456789 Do-while loop... 0123456789 Goto loop... 0123456789
Mumps is not a STD.
Haemophilus is not a STD.
int main() { std::string first, last; std::cout << "Enter your first name: "; std::cin >> first; std::cout << "Enter your last name: "; std::cin >> last; }
std::cout << std::bitset<CHAR_BIT>( 876 ) << std::endl;
#include<iostream> int main() { int num1, num2; std::cout << "C++ addition program" << std::endl; std::cout << "Enter a number: "; std::cin >> num1; std::cout << "Enter another number: "; std::cin >> num2; std::cout << "The sum is " << num1 + num2 << std::endl; }
Insomnia is not a symptom of an std.
You can become a surgeon if you have a STD.