Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ programming Complete each of the nine functions one at a time using the one assert for each in int main() Add more tests as

C++ programming

  • Complete each of the nine functions one at a time using the one assert for each in int main()
  • Add more tests as asserts in main().

Code:

#include #include #include #include using namespace std; /////////////////////////////////////////////////////////////////////// double roundto(double x, int decimals) { /* Return the floating point number x rounded to decimals decimal places. You will need cmath's round and pow functions */ // TODO: Complete this function return std::numeric_limits::max(); }

/////////////////////////////////////////////////////////////////////// double circle_area(double radius) { /* Return the area of a circle rounded to two decimal places of the given radius. You might have to look up this formula on the web. You will need cmath's M_PI constant and the pow function */ // TODO: complete this function return std::numeric_limits::max(); }

/////////////////////////////////////////////////////////////////////// double projectile_range(double degrees, double velocity) { /* Complete this function so it returns the range of a projectile rounded to two decimal places. Here is the formula: range = sin(2 * radians) * velocity**2 / gravity Since the input is degrees, we must convert degrees to radians for use in the sin() function that expects radians, not degrees. Here is the formula: radians = degrees * math.pi / 180 You will need the constant the sin function and the M_PI constatn from . You will also need to use your working roundto function to reound to 2 decimal places. */

// TODO: complete this function return std::numeric_limits::max(); }

/////////////////////////////////////////////////////////////////////// string anti_matter(const string &matter) { /* Everyone knows that interplanetary space travel systems are fueled by mixing matter and anti-matter. Complete this function that will take a string with the name of some thing or idea and return a string with "Anti-" prepended to it. anti_matter("lol") returns Anti-lol you will need string concatenation with +' */ // TODO: complete this function return "Under construction "; }

/////////////////////////////////////////////////////////////////////// string abba(const string &a, const string &b) { /* Given two strings, a and b, return the result of putting them together in the order abba, e.g. "Hi" and "Bye" returns "HiByeByeHi". abba("Hi", "Bye") returns "HiByeByeHi" abba("Yo", "Alice") returns "YoAliceAliceYo" You will need string concatenation. */ // TODO: complete this function return "Under construction "; }

/////////////////////////////////////////////////////////////////////// // Precondition: < len(sequence) std::string wrap(const string &sequence, int n) { /* Return a string that moves the first count words to the end of sequence You will need the substr function from */ // TODO: Complete this function return "Under construction "; }

/////////////////////////////////////////////////////////////////////// std::string make_tags(const string &tag, const string &word) { /* The web is built with HTML strings like "Yay" which draws Yay as italic text. In this example, the "i" tag makes and which surround the word "Yay". Given tag and word strings, create the HTML string with tags around the word. For example, make_tags("i", "italic") returns "italic" You will need string concatenation with + */

// TODO: complete this function return "Under construction "; }

/////////////////////////////////////////////////////////////////////// // Precondition word.length() == 5 exactly, all the time. If not, this function won't work. string in_lat(const string &word) { /* Aoccdrnig to a rscheearch at an Elingsh uinervtisy, it deosn"t mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht frist and lsat ltteer is at the rghit pclae. Create a function that will mix up the middle characters in a five letter word. The precondition states the word must have exactly 5 letters. If the argument is a different len, the function will not work. Assuming the letters are indexed as 0-1-2-3-4, they should end up in the order 0-3-2-1-4. Your function will accept a 5-character string as an argument and return a 5-character string reordered as described. in_lat("gears") returns "gares" in_lat("prior") returns "piorr" in_lat("scone") returns "sonce" You cannot use .at(int) or [int] because C++ thinks a string of length 1 is a char, which C then turns into an integer. It appears this string function is returning an int Instead, use substr or to_string. */ // TODO: complete this function return "Under construction "; }

// Precondition: name must in the format of a firstname, followed by a space, followed by one // letter and a dot, followed by a space, followed by a last name, "Rick H. Mercer" for example. void name_rearrange(string &name) { /* * Modify name to change the format form "Rick H. Mercer" to "Mercer, Rick H." * * You will need the string functions find and substr in addition to string concatenation. */ // TODO: complete this function name = "Under construction "; } int main() { // Test roundto(double x, int decimals) ------------------ cout << roundto(5.67, 1) << endl; assert(roundto(2.4999999, 0) == 2); // Test for circle_area(radius) -------------------------- assert(circle_area(1) == 3.14); // Test projectile_range --------------------------------- assert(projectile_range(45, 100) == 1020.41); // Test Anti_matter --------------------------------------

assert(anti_matter("LOL") == "Anti-LOL"); // Test abba -------------------------------------------- assert(abba("Hi", "Bye") == "HiByeByeHi"); // Test wrap --------------------------------------------- assert(wrap("XY", 1) == "YX"); // Test make_tags --------------------------------------- assert(make_tags("i", "italic") == "italic"); // Test in_lat ------------------------------------------- assert(in_lat("apple") == "alppe"); assert (in_lat("Quick") + " " + in_lat("brown") + " " + in_lat("foxes")

+ " " + in_lat("jumps") == "Qciuk bworn fexos jpmus"); // Test name_rearrange ---------------------------------- string t1 = "First M. Last"; // Modfiy t1 inside the function name_rearrange(t1); assert(t1 == "Last, First M."); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions

Question

Discuss the need to split data into test and training data.

Answered: 1 week ago