Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // --- Your code here
- #include <iostream>
- #include <string>
- #include <iomanip>
- #include <cmath>
- // repeatString function
- // std::string repeatString(const std::string &some_string, int num){
- // for(int i = 1; i < num; i++){
- // std::cout << some_string;
- // }
- // return some_string;
- // }
- std::string repeatString(std::string &some_string, int num){
- if (num == 0){
- return " ";
- }
- else{
- for(int i = 0; i < num-1; i++){
- std::cout << some_string;
- }
- return some_string;
- }
- }
- //multiply function
- long double multiply(const long long unsigned int &large_number, const long long unsigned int &even_larger_number){
- long double result = large_number * even_larger_number;
- return result;
- }
- // ---
- // include the standard library files that defines the std:: functions
- int main() {
- // --- Your code here
- double some_number;
- std::string some_string;
- unsigned long long int large_number;
- unsigned long long int even_larger_number;
- int negative_number;
- // declare the variables used below
- some_number = 5.5;
- // std::endl and '\n' are equivalent
- std::cout << some_number << ' ' << std::round(some_number + M_PI) << '\n';
- // this one may be a bit tricky since you can't assign a string literal to char* in C++
- some_string = "my string";
- std::cout << some_string << '\n';
- // implement this function
- // should print empty string
- std::cout << repeatString(some_string, 0) << std::endl;
- // should print it 5 times, with nothing separating them
- std::cout << repeatString(some_string, 5) << std::endl;
- // there are many numerical types, each with different signedness and size
- // declare the appropriate types for them such that none of them overflow
- // note that 2^32 ~= 4 billion
- large_number = 1000000;
- large_number *= 3;
- std::cout << large_number << std::endl;
- even_larger_number = large_number * large_number;
- std::cout << even_larger_number << std::endl;
- // implement this multiply function
- std::cout << std::fixed << std::setprecision(1) << multiply(large_number, even_larger_number) << std::endl;
- // beware of numeric types' signedness
- negative_number = -250;
- std::cout << negative_number << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment