Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write all methods and classes as given in the instructions. If this isn't done, you're getting a downvote even if the output is correct. This

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Write all methods and classes as given in the instructions. If this isn't done, you're getting a downvote even if the output is correct.

This exercise is all about procedural programming (lec3), and specifically the topics of pointers, arrays, and loops. Write a C++ program that prints out all command line arguments both in their original order and in the sorted alphabetic order. To demonstrate your grasp of the language's built-in facility, your program should NOT use any standard library features except for cout from iostream. Specifically you should write your own versions of the following functions (some of these are named differently from their standard library counterparts): int strlen(const char* s); // returns the length of s (Note: you actually don't need to use this function in hw2_1, but you will need it in hw2_2) int strcmp(const char* si, const char* s2); // returns -1 if sl should appear before s2, 0 if sl and s2 are exactly the same, 1 if sl appears after s2. All in alphabetic order according to the ASCII table void strSwap(char* &s1, char* &s2); // allows two pointers to char* to be swapped, i.e. afterwards, sl will point to what s2 was pointing at and vice versa void strBubbleSort(char* arrstr[], int n); // uses bubble sort to put all strings in arrStr in an alphabetic order. The array has size of n and will be modified as the result of this function Example output >hw2_1 an agile fox jumps over a lazy dog Your input is: an agile fox jumps over a lazy dog Your output is: a agile an dog fox jumps lazy over Some Helpful Info In int main(int argc, char* argv[]){}, the value of argc is 1 plus the actual number of command line parameters entered after the executable. argv[1] is the first paramter (argv[0] refers to the executable itself) Your program should leave argv[] untouched, i.e. do not modify argv[] itself! This means that you need to allocate memory (using new) to make a copy of argv[], and properly release the memory when you're done with it. In the unlikely event that you don't know about bubble sort, please take a look at this wiki article - only that now we're comparing c-style strings, not integers. Your program should print an error message and exit if no command line parameters were passed Please make sure to test with the example shown above OrdPair You are asked to define a template class called OrdPair, which stands for an ordered pair of some parameterized type, T. Your definition should form an ordpair.hpp header file which can be included in your main cpp file (#include "ordpair.hpp"). The key feature of ordPair is that the pair is strictly ordered, with its two data members, named first and second, always satisfying the invariant: first

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

Power Bi And Azure Integrating Cloud Analytics For Scalable Solutions

Authors: Kiet Huynh

1st Edition

B0CMHKB85L, 979-8868959943

More Books

Students also viewed these Databases questions

Question

e. What do you know about your ethnic background?

Answered: 1 week ago

Question

b. Why were these values considered important?

Answered: 1 week ago