1

Help please this is C/C++ code /* * Lab12, the purpose of this lab is to...

Question

Help please this is C/C++ code /* * Lab12, the purpose of this lab is to...

Help please this is C/C++ code

/*

* Lab12, the purpose of this lab is to improve your skills in handling c strings

* with pointers .

* use of : strlen ,string concatenation strcat, compare strcmp,

* copy strcpy and search strrchr

*

*/

#include <cstdlib>

#include <iostream>

#include<cstring>

using namespace std;

/**

* Create a method that prompts the user for only lowercase letters to represent

* a name.

* Start a Label, then prompt the user to enter a name

* Make a static char array to represent the name with size 30

* use scanf to scan for the name , specifier for char is %s

* Declare a flag with a premise that the name is not all lowercase

* Loop the length of the name , use strlen(name) for the length of name

* The loop checks if the name is all lowercase letters

* If the user provides invalid characters other than lowercase,goto label

* @return pointer of Char

*/

char * setName(){

}

/**

* Similar to the previous method ,

* It restricts providing characters other than digits

* @return

*/

char * setBadge(){

}

/**

* Similar to the previous method ,

* It restricts providing characters other than uppercase

* @return

*/

char * setComp(){

}

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

// Declare a name pointer and set it using setName

char*name= setName();

// Declare a badge pointer and set it using the method

// Declare a company pointer and set it using the method

// Declare a character array of size 30

char email[30];

// COPY name TO email

//Concatenate email with '.'

//Concatenate badge with email

//Concatenate @ with email

//Concatenate company name with email

// Add a domain by concatenating .edu with email

// Search for the last occurrence of .

//The method returns a pointer pointing to the beginning of .edu

// Change the values next of the pointer to make '.edu' all uppercase

// Subtract -32 from the letters and that will make it uppercase

// answer will be .EDU

// Use strcmp to compare the previous pointer to ".EDU"

// Print the email using printf, the specifier is %s

//an outcome will look like : [email protected]

Answers

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

/*
* Lab12, the purpose of this lab is to improve your skills in handling c strings
* with pointers .
* use of : strlen ,string concatenation strcat, compare strcmp,
* copy strcpy and search strrchr
*
*/

#include <cstdlib>
#include <iostream>
#include<cstring>
using namespace std;

/**

* Create a method that prompts the user for only lowercase letters to represent
* a name.
* Start a Label, then prompt the user to enter a name
* Make a static char array to represent the name with size 30
* use scanf to scan for the name , specifier for char is %s
* Declare a flag with a premise that the name is not all lowercase
* Loop the length of the name , use strlen(name) for the length of name
* The loop checks if the name is all lowercase letters
* If the user provides invalid characters other than lowercase,goto label
* @return pointer of Char
*/

char * setName(){
   static char name[30];
   bool flag = false;
   int i;
   inputname:
   printf("Enter a name in lowercase: ");
   scanf("%s", name);
   for(i = 0; i < strlen(name); i++){
       if(name[i] < 'a' || name[i] > 'z')
           goto inputname;
   }

   flag = true;
   return name;
}

/**
* Similar to the previous method ,
* It restricts providing characters other than digits
* @return
*/

char * setBadge(){
   static char badge[30];
   bool flag = false;
   int i;
   inputbadge:
   printf("Enter a badge (digits): ");
   scanf("%s", badge);
   for(i = 0; i < strlen(badge); i++){
       if(badge[i] < '0' || badge[i] > '9')
           goto inputbadge;
   }

   flag = true;
   return badge;
}


/**
* Similar to the previous method ,
* It restricts providing characters other than uppercase
* @return
*/

char * setComp(){
   static char comp[30];
   bool flag = false;
   int i;
   inputcomp:
   printf("Enter a company in uppercase: ");
   scanf("%s", comp);
   for(i = 0; i < strlen(comp); i++){
       if(comp[i] < 'A' || comp[i] > 'Z')
           goto inputcomp;
   }

   flag = true;
   return comp;
}

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

// Declare a name pointer and set it using setName

char*name= setName();

// Declare a badge pointer and set it using the method
char *badge = setBadge();
// Declare a company pointer and set it using the method
char *comp = setComp();
// Declare a character array of size 30

char email[30];

// COPY name TO email
strcpy(email, name);
//Concatenate email with '.'
strcat(email, ".");
//Concatenate badge with email
strcat(email, badge);
//Concatenate @ with email
strcat(email, "@");
//Concatenate company name with email
strcat(email, comp);
// Add a domain by concatenating .edu with email
strcat(email, ".edu");
// Search for the last occurrence of .
//The method returns a pointer pointing to the beginning of .edu

char *p = strrchr(email, '.');


// Change the values next of the pointer to make '.edu' all uppercase
for(char *q = p+1; *q != '\0'; q++){

   // Subtract -32 from the letters and that will make it uppercase
   // answer will be .EDU
   *q = *q - 32;
}

// Use strcmp to compare the previous pointer to ".EDU"
if(strcmp(p, ".EDU") == 0)
   printf("p points to .EDU\n");
else
   printf("p does not point to .EDU\n");

// Print the email using printf, the specifier is %s
printf("email is %s\n", email);

//an outcome will look like : [email protected]
return 0;
}

output
======
Enter a name in lowercase: ADDieoe
Enter a name in lowercase: sadiq
Enter a badge (digits): sfsd;k
Enter a badge (digits): 1234
Enter a company in uppercase: dfjk
Enter a company in uppercase: OKSTATE
p points to .EDU
email is [email protected]


Similar Solved Questions

4 answers
NEED HELP PLEASE !!!! ASSIGNMENT DUE IN 2 HOURS !!
A helicopter carrying Dr. Evil takes off with a constant upward acceleration of 7.0 m/s^2. Secret agent Austin Powers jumps on just as the helicopter lifts off theground. After the two men struggle for 15.0 s, Powers shuts off the engine and steps out of the helicopter. Assume that the helicopter is...
1 answers
January 1, 2016, Lexo co bought fixed assets for $ 80,000. The expected life of the...
January 1, 2016, Lexo co bought fixed assets for $ 80,000. The expected life of the property, at the date of purchase, was five years and the residual value is estimated at $ 16,000. Lexo co uses a straight-line depreciation method for depreciation. At the beginning of the fourth year, the managers ...
1 answers
Natalie has prepared the balance sheet and income statement of Cookie & Coffee Creations Inc. for...
Natalie has prepared the balance sheet and income statement of Cookie & Coffee Creations Inc. for the first year of operations, but does not understand how to prepare the cash flow statement. The income statement and balance sheet appear below. Recall that the company started operations on Novem...
1 answers
Scenario: Mercedes Bents is a 56 year old female admitted to the hospital for aggressive treatment...
Scenario: Mercedes Bents is a 56 year old female admitted to the hospital for aggressive treatment of a bone infection that has not responded to usual methods. Her daughter has been taking care of her at home for the past 3 weeks. She stated that the medicines the doctor prescribed made her mother f...
1 answers
Please Do NOT USE excel to solve .... Show me the steps and the equations to...
Please Do NOT USE excel to solve .... Show me the steps and the equations to better understand the question You have a habit of drinking a cup of coffee ($2.00 a cup) on the way to work every morning for 30 years. If you put the money in the bank for the same period, how much would you have, assumi...
1 answers
4. (30 points) A statistics exam has five easy questions and three hard questions. You have...
4. (30 points) A statistics exam has five easy questions and three hard questions. You have six friends who are in the class, five are moderately prepared and one is very prepared. Probability Easy Questions Correct 80% Chance 95% Probability Hard Questions Correct 66.666% (two-thirds) 5 Moderately ...
1 answers
Problem 03-29 Thirty patients who check out of the Rock Creek Regional Hospital each week are...
Problem 03-29 Thirty patients who check out of the Rock Creek Regional Hospital each week are asked to complete a questionnaire about hospital service. Since patients do not feel well when they are in the hospital, they typically are very critical of the service. The number of patients who indicated...
1 answers
Air contains methanol at 75% relative saturation at 1 atm total pressure and 25 degree C....
Air contains methanol at 75% relative saturation at 1 atm total pressure and 25 degree C. a) Calculate the dew point b) Calculate the temperature required to condense 90% of the methanol as liquid if the total pressure remains constant...
1 answers
13. 2.50 points MC Qu. 112 If the wage... Unit of Output Marginal Price TotalMarginal Revenue...
13. 2.50 points MC Qu. 112 If the wage... Unit of Output Marginal Price TotalMarginal Revenue Revenue Physical Product Labor ProductProduct $10 10 10 10 10 10 10 10 10 26 46 70 76 78 78 If the wage rate were $30, how many workers would be hired? O 4 O 6 References Multiple Cholce Difficulty: 3 Hard ...
1 answers
Find the area of APQR. P(1, 0, 1), Q(0, 1, 0), R(4, 9, 10) Need Help?...
Find the area of APQR. P(1, 0, 1), Q(0, 1, 0), R(4, 9, 10) Need Help? Read It Watch It Talk to a Tutor Show My Work (Optional) Submit Answer [-/2 Points] DETAILS SPRECALC7 9.5.029. MY NOTES AS Three vectors u, v, and w are given. u = (1, 2, 3), v = (-3, 2, 1), w = (0,4, 5) (a) Find their scalar trip...
1 answers
1. Do you think that majority of SAR activity is illegal or false alarm?
1. Do you think that majority of SAR activity is illegal or false alarm?...
1 answers
The Regal Cycle Company manufactures three types of bicycles—a dirt bike, a mountain bike, and a...
The Regal Cycle Company manufactures three types of bicycles—a dirt bike, a mountain bike, and a racing bike. Data on sales and expenses for the past quarter follow: Total Dirt Bikes Mountain Bikes Racing Bikes Sales $ 922,000 $ 268,000 $ 404,000 $ 250,000 Variable manufacturing an...
1 answers
How do you simplify #cos(2 arcsin x)#?
How do you simplify #cos(2 arcsin x)#?...
1 answers
Question 30 (Mandatory) (1 point) Saved If the rate of inflation is 12 percent per year,...
Question 30 (Mandatory) (1 point) Saved If the rate of inflation is 12 percent per year, the price level will double in about 4.1 years. 5.8 years. 10.2 years. 12.4 years. Question 31 (Mandatory) (1 point) Compared to other industrial nations, inflation rates in the United States are significantly h...
1 answers
27. Give the 28 Give the major organic prodact for the feig to 21. Give the most stalble enol tas...
27. Give the 28 Give the major organic prodact for the feig to 21. Give the most stalble enol tastomer for the cmpound hown below3e cefs cylo 23. Give the major organic prodact for the ollowing tice (3 pts) 27. Give the 28 Give the major organic prodact for the feig to 21. Give the most stalble eno...
1 answers
TB4 The quasi-static ideal gas cycle shown to the right has three legs, an adiabatic leg #1 from (PyVị) to (P-1 atm, V3), followed by an isobaric compression leg #2 from (P-1 atm, V3) to (P -1 atm,Vi...
TB4 The quasi-static ideal gas cycle shown to the right has three legs, an adiabatic leg #1 from (PyVị) to (P-1 atm, V3), followed by an isobaric compression leg #2 from (P-1 atm, V3) to (P -1 atm,Vi), and ending with a constant volume pressurization leg #3 from (P-1 atm, VI) back to the initi...
1 answers
4. A GC sample of a mixture of two compounds produces a single peak in the...
4. A GC sample of a mixture of two compounds produces a single peak in the chromatograph. Give two factors that you could change in the GC experiment to increase the resolution so that the two compounds are separated. 2 points Change 1 Change 2...
1 answers
Exercise 4-49 (Static) Dropping Product Lines (LO 4-4) Cotrone Beverages makes energy drinks in three flavors:...
Exercise 4-49 (Static) Dropping Product Lines (LO 4-4) Cotrone Beverages makes energy drinks in three flavors: Original, Strawberry, and Orange. The company is currently operating at 75 percent of capacity. Worried about the company's performance, the company president is considering dropping th...

-- 0.050204--