Question

•Create a project in Visual Studio (C++) •Have a function that compares two C-Strings (similar to...

Create a project in Visual Studio (C++)

•Have a function that compares two C-Strings (similar to strcmp)

•Have a function that copies one string to another string (strcpy)

•Have a function that returns a persons first name only

•I enter Bobby Loneker to the system, this function should cut my last name off

•Have a function that returns a C-string backwards

•I enter Bobby to the system it returns: ybboB

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

Given below is the code for the question. Please do rate the answer if it helped. Thank you.


#include <iostream>
using namespace std;
int my_strcmp(char *s1, char *s2);
void my_strcpy(char *src, char *dest);
void get_firstname(char *src, char *fname);
void my_strrev(char *src, char *dest);

int main(){
   char s1[20], s2[20];
  
   cout << "Enter 2 strings to compare- " << endl;
   cout << "\t string1? ";
   cin.getline(s1, 20);
   cout << "\t string2? ";
   cin.getline(s2, 20);
  
   if(my_strcmp(s1, s2) == 0)
       cout << s1 << " = " << s2 << endl;
   else if(my_strcmp(s1, s2) < 0)
       cout << s1 << " < " << s2 << endl;
   else
       cout << s1 << " > " << s2 << endl;
  
   cout << endl << "copying s1 to s2" << endl;
   my_strcpy(s2, s1);
   cout << "s1 = " << s1 << endl;
   cout << "s2 = " << s2 << endl;
  
  
   cout << endl << "Enter your full name: ";
   cin.getline(s1, 20);
   get_firstname(s1, s2);
   cout << "Your firstname is " << s2 << endl;
  
   cout << endl << "Enter a string to reverse: ";
   cin.getline(s1, 20);
   my_strrev(s1, s2);
   cout << "Reverse is " << s2 << endl;
  
   return 0;
}


int my_strcmp(char *s1, char *s2){
   int i = 0;
   while(s1[i] != '\0' && s2[i] != '\0')
   {
       if(s1[i] < s2[i])
           return -1;
       else if(s1[i] > s2[i])
           return 1;
       i++;
   }
  
   if(s1[i] == '\0')
   {
       if(s2[i] == '\0')
           return 0;
       else
           return -1;
   }
   else
       return 1;

}

void my_strcpy(char *dest, char *src ){
   int i = 0;
   while(src[i] != '\0')
   {
       dest[i] = src[i];
       i++;
   }
   dest[i] = '\0';
}

void get_firstname(char *src, char *fname)
{
   int i = 0;
   while(src[i] != '\0' && src[i] != ' ')
   {
       fname[i] = src[i];
       i++;
   }
   fname[i] = '\0';
}

void my_strrev(char *src, char *dest)
{
   int i = 0, j = 0;
   while(src[i] != '\0')
       i++;
  
   i--;
   while(i >= 0){
       dest[j] = src[i];
       i--;
       j++;
   }
   dest[j] = '\0';
}

output
----
Enter 2 strings to compare-
string1? hello
string2? world
hello < world

copying s1 to s2
s1 = hello
s2 = hello

Enter your full name: Bobby Loneker
Your firstname is Bobby

Enter a string to reverse: Bobby
Reverse is ybboB

Add a comment
Know the answer?
Add Answer to:
•Create a project in Visual Studio (C++) •Have a function that compares two C-Strings (similar to...
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
  • This program should be run on Visual Studio. Please use printf and scanf as input and output. Tha...

    This program should be run on Visual Studio. Please use printf and scanf as input and output. Thank you 6.12 Lab Exercise Ch.6b: C-string functions Create and debug this program in Visual Studio. Name your code Source.c and upload for testing by zyLabs You will write 2 functions which resemble functions in the cstring library. But they will be your own versions 1. int cstrcat(char dstDchar src) which concatenates the char array srcl to char array dstD, and returns the...

  • for my assignment, we have to create a basic quiz on c sharp using visual studio,...

    for my assignment, we have to create a basic quiz on c sharp using visual studio, i have my questions, gotten the score calculated if answered correct or not. but in having issues with looping back to the question until answered right.

  • Question 1 Which pre-written C function can be used to determine if two strings are the...

    Question 1 Which pre-written C function can be used to determine if two strings are the same? A) equals B) strcmp C) strlen D) strcpy E) None of the Above Question 2 The function below is most like which existing string function? int f(char a[ ]) {                int count = 0;                while (a[count] != ‘\0’)                               count++;                return count; } A) strcat B) strcmp C) strcpy D) strlen E) None of the Above Question 3 The function...

  • C++ visual studio program...Write your own version of a class template that will create a dynamic...

    C++ visual studio program...Write your own version of a class template that will create a dynamic stack of any data type. The pop function must return a bool; it should return a false if it was not able to pop an item off the stack. Otherwise it returns true. The parameter to the pop function is passed by reference and should be the item on the list if it was able to pop something. Create a driver program (main) that...

  • This program should be run on Visual Studio. Please use printf and scanf as input and...

    This program should be run on Visual Studio. Please use printf and scanf as input and output. Thank you 6.11 Lab Exercise Ch.6a: Functions: String analyzer Create and debug this program in Visual Studio. Upload your Source.cpp file for testing (1) Prompt the user to enter a string of their choosing. Output the string. (1 pt) Ex: ics Enter a sentence or phrase: The only thing we have to fear is fear itself. You entered: The only thing we have...

  • Subject: Advance application development Visual studio exercise The project is to create a simple Notepad style Tex...

    Subject: Advance application development Visual studio exercise The project is to create a simple Notepad style Text Editor. This will demonstrate the C# language basics. user interface controls and how to handle user events. Controls can be found in the Toolbox pane in its default location on the left side of the IDE, with the Control Properties pane on the right side of the IDE. Include the items on the following list in the program Create a C# Windows Forms...

  • I need this in Visual Studio C++ Write a function that count the number of vowels,...

    I need this in Visual Studio C++ Write a function that count the number of vowels, the number of consonants and the average number of letters in each word. The function accept a C-String (char array) or a string object as an argument and return the number of vowels, number of consonants and the average number of letters in each word. Problem: Requirements: . Use pointers as part of the solution Read a string from a text file. . Write...

  • This is to be in C# and this project is being made in Microsoft Visual Studio...

    This is to be in C# and this project is being made in Microsoft Visual Studio Create a Date class that does the following: o A default constructor o A constructor with a string argument o An integer member variable that represents the date in the following format:  YYYYMMDD  i.e. 20070212 means February 12, 2007 o A string member variable that represents the date in the following format:  YYYY-MM-DD o An integer member variable that represents a...

  • To conclude the project, use the UML diagram you created last week and create an application in Visual Studio name...

    To conclude the project, use the UML diagram you created last week and create an application in Visual Studio named School. Once you have written the code, be sure and test it to ensure it works before submitting it. Below is the UML diagram for the basic class we created last week for your reference, but for this project be sure you use the one that you created last week. Good luck and be sure to get started early in...

  • C# visual studio 2019 For this  you will create two student objects and then print out the...

    C# visual studio 2019 For this  you will create two student objects and then print out the objects values. Within the Student Class you will have the following properties: StudentID LastName FirstName Major Within the Main you will create 2 student objects by setting each of their property values. You will then write out a header line and each of the student objects to the console.

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