1

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

Question

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

6.12 Lab Exercise Ch.6b: C-string functions Create and debug this program in Visual Studio. Name your code Source.c and uploaYour main program should (1) Prompt the user to enter 2 strings, and save into 2 char(40] arrays using fgets0. Assume the use

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 new length of the dstl. not counting the null terminator character. You may assume dstl was declared large enough to handle the combined length Write the loops to find the end of the first string and to do the copy. DO NOT make calls to C-string library functions 2 int cstrcmp(char s. char t) which compares the char array s to char array tD.and returns 1 if the strings are identical, and zero otherwise. Write the loop to do the compare DO NOT make calls to C-string library functions. Be sure you don't compare past the end of either string.
Your main program should (1) Prompt the user to enter 2 strings, and save into 2 char(40] arrays using fgets0. Assume the user will enter less than 40 characters for each string. NOTE THAT YOUR PROGRAM WILL HAVE TO REMOVE THE NEWLINE CHARACTER FROM THE END OF EACH STRING, as fgets0 puts the newline in the string as its last character. You can do that by overwriting the newline char, which is at index strlen(stringname)-1, with \0' Ex: Enter 2 strings on separate lines: Hello, world! Hello there. (2) Use the cstrcmp0 function to determine if they are equal, and print out a statement (1pt): Ex: The strings are NOT equal. 3) Call the cstrcat0 function to append the 2nd string to the first, then print out the new longer string and its length (1 pt Ex: Concatenated string:Hello, world!Hello there. Length: 25

Answers

#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int cstrcat(char dst[], char src[]) {
int i=0;
for(i=0;dst[i]!='\0';i++) {
}
for(int j=0;src[j]!='\0';j++) {
dst[i++]=src[j];
}
dst[i]='\0';
return i;
}
bool cstrcmp(char s[], char t[]) {
if(strlen(s) != strlen(t))
return false;
for(int i=0;s[i]!='\0' && t[i] != '\0';i++) {
if(s[i] != t[i])
{
return false;
}
}
return true;
}
int main()
{
char s1[100], s2[100];
cout << "Enter 2 strings:" << endl;
cin.getline(s1, 100);
cin.getline(s2, 100);
if(cstrcmp(s1,s2)) {
cout<<"The strings are equal."<<endl;
} else {
cout<<"The strings are NOT equal."<<endl;
}
int count = cstrcat(s1,s2);
cout<<"Concatenated string: "<<s1<<endl;
cout<<"Length: "<<count<<endl;
return 0;

}

=============
See Output


Similar Solved Questions

1 answers
A water balloon is launched with an initial speed of 40 m/s at 60 degrees above...
A water balloon is launched with an initial speed of 40 m/s at 60 degrees above the horizontal. A tall building is 40 m from the launch site. Neglect air resistance and use g = 10 m/s^2. (numbers 8-11) A water balloon is launched with an initial speed of 40 m/s at 60 degrees above the horizontal. A ...
1 answers
Harry is looking at a double cab truck which has an MSRP of $54,999. The dealer...
Harry is looking at a double cab truck which has an MSRP of $54,999. The dealer will finance the truck at 1.91% interest for 60 months. Harry thinks he can afford monthly payments of $911.00 per month. Can Harry afford the truck? Why? Yes; he can afford a loan amount of exactly $54,999. ...
1 answers
P6-4A Sandoval Skateshop Ltd. reports the following inventory transactions for its skateboards for the month of...
P6-4A Sandoval Skateshop Ltd. reports the following inventory transactions for its skateboards for the month of April. The company uses a perpetual inventory system. Date Explanation        Units Unit Cost Total Cost Apr. 1 Beginning inventor...
1 answers
Critical Thinking Assignment Answer the following questions about the "breakeven analysis and how it relates to...
Critical Thinking Assignment Answer the following questions about the "breakeven analysis and how it relates to Pricing (Ch. 13) strategy. How does a breakeven analysis help marketers determine the best price for their products? What other factors should companies consider? Why?...
1 answers
What is the rate of return for an investor who pays $943.11 for a three year...
What is the rate of return for an investor who pays $943.11 for a three year bond with a 5.9% coupon paid annually and a face value of $1,000 and sells the bond one year later for $925.44? Enter your answer as a percentage. Do not include the percentage sign in your answer. Enter your response below...
1 answers
Consider continuous joint density function f(x,y)= (x+y)/7; 1<x<2, 1<y<3 Marginal density for Y? Select one: (2+3x)/14...
consider continuous joint density function f(x,y)= (x+y)/7; 1<x<2, 1<y<3 Marginal density for Y? Select one: (2+3x)/14 (3+2y)/7 (2+3y)/14 (3+2y)/14 consider continuous joint density function f(x,y)= (x+y)/7 ; 1<x<2, 1<y<3 P(0<x<3, 0<y<4)=? Select one: 0.5 1 0.15 0...
1 answers
5. An unknown compound with molecular CHz NO, hasthe 'H NIMR and IR spectra below. Propose...
5. An unknown compound with molecular CHz NO, hasthe 'H NIMR and IR spectra below. Propose a structure for the compound and assign the peaks on each spectrum 10 9 8765 4321 0 ppm...
1 answers
KAssignment 10 Problem 15.93 2 of 3 Review Disks A and B have a mass of...
KAssignment 10 Problem 15.93 2 of 3 Review Disks A and B have a mass of 16 kg and 10 kg respectively. Part A If they are slding on a smooth horlzontal plane with the velocitles shown, determine their speeds just after Impact. The coefficlent of restitution between them is e= 0.7.(Figure 1) Enter you...
1 answers
The following table gives the joint probability distribution between employment status and college graduation among those...
The following table gives the joint probability distribution between employment status and college graduation among those either employed or looking for work (unemployed) in the working age U.S. population Unemployed (Y-0) 0.0426 0.0103 0.0529 Employed Non-college grads (X- 0) College grads (X= 1) T...
1 answers
A) The rear window in a car is approximately a rectangle, 1.22 m wide and 0.230...
a) The rear window in a car is approximately a rectangle, 1.22 m wide and 0.230 m high. The inside rear-view mirror is 0.480 m from the driver's eyes, and 1.41 m from the rear window. What is the minimum height of the rear-view mirror if the driver is to be able to see the entire height of the r...
1 answers
On August 1, Delta Corp. received $2,000 cash for providing services to a customer. On August...
On August 1, Delta Corp. received $2,000 cash for providing services to a customer. On August 30, the customer returned one-fourth of the inventory back to Delta for a cash refund. Required: In the general journal below, record each of the above transactions. Note: Do not use decimals, currency symb...
1 answers
13.A white blood cell count may be decreased because of: a. A chronic viral infection b.      ...
13.A white blood cell count may be decreased because of: a. A chronic viral infection b.       Exposure to toxins C. Chemotherapy use D- All of the above 14 – The reference or nor mil range for the platelet count is: a.     &...
1 answers
To remind you, the LP is Min Transportation costs: 3x11 + 2 x12 + 7 x13...
To remind you, the LP is Min Transportation costs: 3x11 + 2 x12 + 7 x13 + 6 x14 + 7x21 + 5 x22 + 2 x23 + 3 x24 + 2x31 + 5 x32 + 4 x33 + 5 x34 s.t. Need to make sure demand at destination is satisfied: Boston demand: x11 + x21 + x31 = 6000 Chicago demand: x12 + x22 + x32 = 4000 St. Louis demand: x...

-- 0.011024--