Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ confusing question. Hi, I have my program already done but I do not what the assignment is trying to say in step 7. Do

C++ confusing question. Hi, I have my program already done but I do not what the assignment is trying to say in step 7. Do I need to put everything in functions instead of main? And if so how can I put it. Thanks.

image text in transcribed

This is my code:

#include

using std::cout;

using std::cin;

using std::endl;

//function templates

int myStrLen(const char*);

void myStrCpy(char*, const char*);

int myStrCmp(const char*, const char*);

void myStrSwap(char*, char*);

void myStrUpr(char*);

void myStrLwr(char*);

int main()

{

//STEP 1

char step1[] = { "Star" };

cout

cout

//STEP 2

char step2a[] = { "This" };

char step2b[] = { "That" };

cout

cout

myStrCpy(step2a, step2b);

cout

cout

//STEP 3

char step3a[] = { "Those" };

char step3b[] = { "These" };

cout

cout

if (myStrCmp(step3a, step3b) == 0)

cout

else

cout

//STEP 4

char step4a[] = { "Them" };

char step4b[] = { "They" };

cout

cout

myStrSwap(step4a, step4b);

cout

cout

//STEP 5

char step5[] = { "toupper" };

cout

myStrUpr(step5);

cout

//STEP 6

char step6[] = { "TOLOWER" };

cout

myStrLwr(step6);

cout

system("pause");

}

//STEP 1 of 7: C - String Length Function

int myStrLen(const char* str)

{

int len = 0;

for (int i = 0; str[i] != '\0'; i++)

{

len += 1;

}

return len;

}

//STEP 2 of 7: C - String Copy Function

void myStrCpy(char* dest, const char* src)

{

int srcLen = 0;

for (int i = 0; src[i] != '\0'; i++)

{

dest[i] = src[i];

srcLen += 1;

}

dest[srcLen] = '\0';

}

//STEP 3 of 7: Write A C - String Compare Function

int myStrCmp(const char* str1, const char* str2)

{

int i = 0;

for (i = 0; str1[i] != '\0' && str2[i] != '\0'; i++)

{

if (str1[i] != str2[i])

{

return 1;

}

}

if (str1[i] == '\0' && str2[i] == '\0')

{

return 0;

}

else

{

return 1;

}

}

//STEP 4 of 7: Write A C-String Swap Function

void myStrSwap(char* str1, char* str2)

{

for (int i = 0; str1[i] != '\0' || str2[i] != '\0'; i++)

{

char temp = str1[i];

str1[i] = str2[i];

str2[i] = temp;

}

}

//STEP 5

void myStrUpr(char* str)

{

for (int i = 0; str[i] != '\0'; i++)

{

str[i] = toupper(str[i]);

}

}

//STEP 6

void myStrLwr(char* str)

{

for (int i = 0; str[i] != '\0'; i++)

{

str[i] = tolower(str[i]);

}

}

STEP 7 of 7: Combine All Functions Into A Test Program Create a new console application named Include in it the functions you developed and tested in step 1-6 above: myStrLen, myStrCmp, myStrCpy, myStrSwap, myStrUpr, and myStrLwr. To do so, simply copy and paste them into Strings.cpp. Include enough testing to convince yourself that the functions will work right in any C/C++ program that uses them. You can assume that the user of your functions will properly size their Cstrings, and include null terminators to mark the ends of strings[Your program will not be scored using your main

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

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago