Question

You are given a Q1.h file with overloaded function prototypes for isOrdered. Implement this overloaded function into a file named Q1.cpp. Q1.cpp should only include your function implementation, the necessary #include directives if needed, and should not contain anything else such as the main function or global variable declarations. Test your code using a separate main.cpp file where you implement a sufficient number of test cases. You should use Q1.h as a header file and Q1main.cpp as a main function to test your code. Feel free to modify Q1main.cpp for testing.

Q1main.cpp:

Q1.h:#include #include #include <íost <string> Q1.h ream> using namespace std; int main(int argc, char *argv[) { cout << Testin//Do not change this file R4LDC 2019 Agenda PUBLIC - Google Sheets using namespace stdi bool isordered (string s) //Returns t

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Q1.h file

#ifndef Q1_H

#define Q1_H

#include <string>

using namespace std;

class Q1

{

public:

bool isOrdered(string s);

bool isOrdered(unsigned int n);

};

#endif

Q1.cpp file

#include<string>

#include "Q1.h"

using namespace std;

bool Q1::isOrdered(string s){

for(int i=0;i<s.length()-1;i++){

if(s[i]>s[i+1]){

return false;

}

}

return true;

}

bool Q1::isOrdered(unsigned int n){

int prev = n%10;

int pres;

n/=10;

while(n>0){

pres = n%10;

if(pres > prev){

return false;

}

n/=10;

prev = pres;

}

return true;

}

Q1main.cpp file

#include <iostream>

#include <string>

#include "Q1.h"

using namespace std;

int main(int argc, char* argv[]){

Q1 q1;

cout << "Testing isOrdered(string)..." << endl;

string s = "Test";

cout << q1.isOrdered(s) << endl;

cout << "Testing isOrdered(unsigned int)..." << endl;

unsigned int n = 1235;

cout << q1.isOrdered(n) << endl;

cout << "Done!" << endl;

return 0;

}

/*

sample output

Testing isOrdered(string)...

1

Testing isOrdered(unsigned int)...

1

Done!

*/

Add a comment
Know the answer?
Add Answer to:
You are given a Q1.h file with overloaded function prototypes for isOrdered. Implement this overloaded function...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • can you please split this program into .h and .cpp file #include <iostream> #include<string> #include<fstream> #define...

    can you please split this program into .h and .cpp file #include <iostream> #include<string> #include<fstream> #define SIZE 100 using namespace std; //declare struct struct word_block {    std::string word;    int count; }; int getIndex(word_block arr[], int n, string s); int main(int argc, char **argv) {    string filename="input.txt";    //declare array of struct word_block    word_block arr[SIZE];    int count = 0;    if (argc < 2)    {        cout << "Usage: " << argv[0] << "...

  • 1. In ANSII standard C++, there is no library function to convert an integer to a...

    1. In ANSII standard C++, there is no library function to convert an integer to a string. Your program should develop such a function. In other words complete the following program using your itos function. (Use of other C functions is prohibitted) // this program will read in an integer and convert it to a string #include <iostream> #include <cstdlib> #include <string> using namespace std; string itos(int n) { } int main(int argc, char* argv[]){ int n = atoi(argv[1]); cout...

  • ***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName)...

    ***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName) { cout << "Usage: " << executableName << " [-c] [-s] string ... " << endl; cout << " -c: turn on case sensitivity" << endl; cout << " -s: turn off ignoring spaces" << endl; exit(1); //prints program usage message in case no strings were found at command line } string tolower(string str) { for(unsigned int i = 0; i < str.length(); i++)...

  • I've posted 3 classes after the instruction that were given at start You will implement and...

    I've posted 3 classes after the instruction that were given at start You will implement and test a PriorityQueue class, where the items of the priority queue are stored on a linked list. The material from Ch1 ~ 8 of the textbook can help you tremendously. You can get a lot of good information about implementing this assignment from chapter 8. There are couple notes about this assignment. 1. Using structure Node with a pointer point to Node structure to...

  • C++ problem. hi heys, i am trying to remove beginning and the end whitespace in one...

    C++ problem. hi heys, i am trying to remove beginning and the end whitespace in one file, and output the result to another file. But i am confused about how to remove whitespace. i need to make a function to do it. It should use string, anyone can help me ? here is my code. #include <iostream> #include <iomanip> #include <cstdlib> #include <fstream> using namespace std; void IsFileName(string filename); int main(int argc, char const *argv[]) { string inputfileName = argv[1];...

  • Requirements I have already build a hpp file for the class architecture, and your job is to imple...

    Requirements I have already build a hpp file for the class architecture, and your job is to implement the specific functions. In order to prevent name conflicts, I have already declared a namespace for payment system. There will be some more details: // username should be a combination of letters and numbers and the length should be in [6,20] // correct: ["Alice1995", "Heart2you", "love2you", "5201314"] // incorrect: ["222@_@222", "12306", "abc12?"] std::string username; // password should be a combination of letters...

  • Please help me modify the Stash3.cpp and Stash3.h files below to utilize default arguments in the...

    Please help me modify the Stash3.cpp and Stash3.h files below to utilize default arguments in the constructor. Please test the constructor by creating two different versions of a Stash object. Please see the source code below: //Stash3.cpp //: C07:Stash3.cpp {O} // From Thinking in C++, 2nd Edition // Available at http://www.BruceEckel.com // (c) Bruce Eckel 2000 // Copyright notice in Copyright.txt // Function overloading #include "Stash3.h" #include "../require.h" #include <iostream> #include <cassert> using namespace std; const int increment = 100;...

  • create a programn in C++ that creates a class that represents a manufactured part on a...

    create a programn in C++ that creates a class that represents a manufactured part on a bill of material (BOM). with the following attributes: identifier (The parts identifier as an alpha numeric string), drawing (The AutoCAD drawing file that represents the part), quantity (The number of parts that are required). implement the functions for the Part class in the file Part.cpp. The file main.cpp will only be used for testing purposes, no code should be written in main.cpp. -part.cpp file:...

  • You are to implement a MyString class which is our own limited implementation of the std::string...

    You are to implement a MyString class which is our own limited implementation of the std::string Header file and test (main) file are given in below, code for mystring.cpp. Here is header file mystring.h /* MyString class */ #ifndef MyString_H #define MyString_H #include <iostream> using namespace std; class MyString { private:    char* str;    int len; public:    MyString();    MyString(const char* s);    MyString(MyString& s);    ~MyString();    friend ostream& operator <<(ostream& os, MyString& s); // Prints string    MyString& operator=(MyString& s); //Copy assignment    MyString& operator+(MyString&...

  • Question 19 4 pts Using the program below, please complete the program by adding 2 functions...

    Question 19 4 pts Using the program below, please complete the program by adding 2 functions as follow: 1. A function named getAverage that calculates and returns the Average. 2. A function named getMaximum that returns the maximum of the three numbers. Make sure to use the proper data types for all variables and functions. #include <iostream> using namespace std; //function getAverage //function getMaximum int main(int argc, char** argv) { int x, y, z; cout << "Enter three whole numbers:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT