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]

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.

/*
* 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]

Add a comment
Know the answer?
Add Answer to:
Help please this is C/C++ code /* * Lab12, the purpose of this lab is 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
  • Please help with writing this code. The language is C++. I'm using vim. Thanks Problem Statement...

    Please help with writing this code. The language is C++. I'm using vim. Thanks Problem Statement A good password has many requirements. Humans have a hard time meeting these requirements left to their own devices. You are tasked with creating a program that will generate a password based on what the user wants in the password The user should be able to choose if they want a password with: letters upper case "lower case *numbers The user should also provide...

  • In the space below, write a C function definition for a function named StrLower, which will...

    In the space below, write a C function definition for a function named StrLower, which will receive one parameter, a pointer to a null-terminated string (i.e., pointer to char), convert each character in the string to lowercase (using the tolower function from <ctype.h>), and return nothing to the caller. Inside the function definition, you may use a for loop or a while loop. If you use any variables other than the incoming parameter, you must define them locally in the...

  • Intro to Programming in C – Large Program 1 – Character/ Number converter Assignment Purpose: To...

    Intro to Programming in C – Large Program 1 – Character/ Number converter Assignment Purpose: To compile, build, and execute an interactive program with a simple loop, conditions, user defined functions and library functions from stdio.h and ctype.h. You will write a program that will convert characters to integers and integers to characters General Requirements • In your program you will change each letter entered by the user to both uppercase AND lowercase– o Use the function toupper in #include...

  • JAVA PROBLEM! PLEASE DO IT ASAP!! REALLY URGENT! PLEASE DO NOT POST INCOMPLETE OR INCORRECT CODE...

    JAVA PROBLEM! PLEASE DO IT ASAP!! REALLY URGENT! PLEASE DO NOT POST INCOMPLETE OR INCORRECT CODE Below is the program -- fill the code as per the instructions commented: //---------------------------------------------------------------------------------------------------------------------------------------------------------------// /* The idea of this HW is as follows : A password must meet special requirements, for instance , it has to be of specific length, contains at least 2 capital letters , 2 lowercase letters, 2 symbols and 2 digits. A customer is hiring you to create a class...

  • I was asked to write a program that when divisible by 2- reverses the order of...

    I was asked to write a program that when divisible by 2- reverses the order of the letters in a sentence when divisible by 3- changes all lowercase letter into uppercase letters in a sentence when divisible by 5 skips the vowels in a sentence this is what I have so far. my reverseMode works fine. #include <iostream> #include <string> #include<cstring> using namespace std; void reverseMode(char* str); void upperMode(char* str); void goodbyeVowels(char* str); char str[50], rstr[50]; //initializing my character arrray...

  • /// c ++ question plz help me fix this not a new code and explain to...

    /// c ++ question plz help me fix this not a new code and explain to me plz /// Write a function to verify the format of an email address: bool VeryifyEmail(char email[ ]); Do NOT parse the email array once character at a time. Use cstring functions to do most of the work. Take a look at the available cstring and string class functions on cplusplus website. Use a two dimensional array to store the acceptable top domain names:...

  • 1. You are given a C file which contains a partially completed program. Follow the instructions...

    1. You are given a C file which contains a partially completed program. Follow the instructions contained in comments and complete the required functions. You will be rewriting four functions from HW03 (initializeStrings, printStrings, encryptStrings, decryptStrings) using only pointer operations instead of using array operations. In addition to this, you will be writing two new functions (printReversedString, isValidPassword). You should not be using any array operations in any of functions for this assignment. You may use only the strlen() function...

  • In this lab assignment, you'll write code that parses an email address and formats the ci and zip...

    Using Microsoft Visual Studio C# In this lab assignment, you'll write code that parses an email address and formats the ci and zip code portion of an address. String Handling Email: [email protected] Parse City: Fresno State: ca Zp code: 93722 Format ให้ 2 Parsed String Formatted String User name: anne Domain name: murach.comm City, State, Zip: Fresno, CA 93722 OK OK Create a new Windows Forms Application named StringHandling and build the form as shown above. 1. Add code to...

  • Here is the UML for the class Contact -fullName : string -phoneNum: string -emailAddress : string...

    Here is the UML for the class Contact -fullName : string -phoneNum: string -emailAddress : string +Contact()                     //default constructor sets all attribute strings to “unknown”; no other constructor +setName(string name) : void +setPhone(string pn) : void +setEmail(string em) : void +getName() : string +getPhone() : string +getEmail() : string +printContact() : void         //print out the name, phone numbers and email address Create New Project Name your project: CIS247_Lab7_YourLastName. For this exercise, you may use a header file or one file...

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