Question

6.25.1: Unit testing C++ Add two more statements to main() to test inputs 3 and -1....

6.25.1: Unit testing C++

Add two more statements to main() to test inputs 3 and -1. Use print statements similar to the existing one (don't use assert).

#include <iostream>
using namespace std;

// Function returns origNum cubed

int CubeNum(int origNum) {
return origNum * origNum * origNum;
}

int main() {

cout << "Testing started" << endl;

cout << "2, expecting 8, got: " << CubeNum(2) << endl;

/* Your solution goes here */

cout << "Testing completed" << endl;

return 0;
}

Homework Answers

Answer #1
#include <iostream>
using namespace std;

// Function returns origNum cubed
int CubeNum(int origNum) {
    return origNum * origNum * origNum;
}

int main() {
    cout << "Testing started" << endl;

    cout << "2, expecting 8, got: " << CubeNum(2) << endl;
    cout << "3, expecting 27, got: " << CubeNum(3) << endl;
    cout << "-1, expecting -1, got: " << CubeNum(-1) << endl;

    cout << "Testing completed" << endl;
    return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C++ please Write code to implement the Karatsuba multiplication algorithm in the file linked in Assignment...
C++ please Write code to implement the Karatsuba multiplication algorithm in the file linked in Assignment 2 (karatsuba.cpp) in Canvas (please do not rename file or use cout/cin statements in your solution). As a reminder, the algorithm uses recursion to produce the results, so make sure you implement it as a recursive function. Please develop your code in small The test program (karatsuba_test.cpp) is also given. PLEASE DO NOT MODIFY THE TEST FILE. KARATSUBA.CPP /* Karatsuba multiplication */ #include <iostream>...
In C++ Please, In the main(), below, write a program that prompts for (1) how many...
In C++ Please, In the main(), below, write a program that prompts for (1) how many values to sum, and then (2) uses a summing loop to prompt for and add up 5 numbers. #include <iostream> #include <iomanip> using namespace std; int main() { < your answer goes here> return 0; }
In main.cpp, write a templated function more which takes in two variables of the same type...
In main.cpp, write a templated function more which takes in two variables of the same type and returns whichever variable is greater than (>) the other. You can and may need to add something to the food class in order for more to be able to be called properly. //food.h #ifndef _FOOD_H #define _FOOD_H #include <iostream> #include <string> using namespace std; class Food { private: string name; int quantity; public: Food(); void setName(string newName); void setQuantity(int newQuantity); string getName(); int...
Strings The example program below, with a few notes following, shows how strings work in C++....
Strings The example program below, with a few notes following, shows how strings work in C++. Example 1: #include <iostream> using namespace std; int main() { string s="eggplant"; string t="okra"; cout<<s[2]<<endl; cout<< s.length()<<endl; ​//prints 8 cout<<s.substr(1,4)<<endl; ​//prints ggpl...kind of like a slice, but the second num is the length of the piece cout<<s+t<<endl; //concatenates: prints eggplantokra cout<<s+"a"<<endl; cout<<s.append("a")<<endl; ​//prints eggplanta: see Note 1 below //cout<<s.append(t[1])<<endl; ​//an error; see Note 1 cout<<s.append(t.substr(1,1))<<endl; ​//prints eggplantak; see Note 1 cout<<s.find("gg")<<endl; if (s.find("gg")!=-1) cout<<"found...
Write a C++ program that processes orders for our company Widgets and More. Your program will...
Write a C++ program that processes orders for our company Widgets and More. Your program will read the product code and quantity for all the products in an order from a file, order.txt. You will be given a sample order.txt with the starter code. There are two items on each line of the file the first is a letter that represents the product and the second is an integer representing the number bought. Based on the product and quantity, you...
my code has several functions; delete and backward functions are not working, rewrite the code for...
my code has several functions; delete and backward functions are not working, rewrite the code for both functions and check them in the main: #include<iostream> #include<cassert> using namespace std; struct nodeType {    int info;    nodeType *link; }; class linkedList { public:    void initializeList();    bool isEmptyList();    void print();    int length();    void destroyList();    void insertFirst(int newItem);    void insertLast(int newItem);    int front();    linkedList();    void copyList(const linkedList otherList);    void insertNewValue(int value);...
For some reason I followed the steps in my project and I am getting the incorrect...
For some reason I followed the steps in my project and I am getting the incorrect output and when I am submitting it, it gives me compilation error. Printing empty array -- next line should be blank Testing append: Shouldn't crash! Should print 100 through 110 below, with 110 on a new line: 100 101 102 103 104 105 106 107 108 109 110 Checking capacity of new array: OK Append test #2: Should print 100 through 120 below, on...
Using a for Loop visual c++ Summary In this lab the completed program should print the...
Using a for Loop visual c++ Summary In this lab the completed program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. You should accomplish this using a for loop instead of a counter-controlled while loop. Instructions Write a for loop that uses the loop control variable to take on the values 0 through 10. In the body of the loop, multiply the value of the loop control variable by 2 and...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort algorithm to sort this list. Fill in this table with each iteration of the loop in the selection sort algorithm. Mark the place from which you are looking for the 'next smallest element'. In this display, the upper numbers are the indices, the lower numbers are in the corresponding positions. Use the several rows provided to show the sequence of steps. 0 1 2...
The C++ program steps through the array x[]. For each i, if x[i] < x[i+1], i...
The C++ program steps through the array x[]. For each i, if x[i] < x[i+1], i is saved in the array ascend[], in order. Compile and run the program; it should print 0 4 5. In this exercise, you’ll try to translate the C++ program to MIPS. Some of the more tedious parts are already given in Assignment3.F19.s. You won’t have to write the data allocation sections, some of the initializations, and the output loop at the end. So the...