Question

Assume you have the following declarations: enum StudentType {BILL, JANE, MARY}; StudentType oneStudent; Write a function,...

Assume you have the following declarations:

enum StudentType {BILL, JANE, MARY};
StudentType oneStudent;

Write a function, GetName, that will accept a string as a parameter and return the appropriate StudentType. Provide a main function demonstrating the GetName function in use.

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

C++ CODE:

#include <iostream>
using namespace std;
// Here, BILL=0, JANE=1, and MARY=2
enum StudentType {BILL, JANE, MARY};
StudentType oneStudent;
StudentType GetName(string name){
    // To convert name to uppercase
    for(int i = 0; i < name.length(); i++)
        name[i] = toupper(name[i]);
    if(name == "BILL")
        return BILL;
    if(name == "JANE")
        return JANE;
    if(name == "MARY")
        return MARY;
}
int main(){
    oneStudent = GetName("Bill");
    cout << oneStudent << endl;// This will print 0 as BILL=0 in enum declaration
    oneStudent = GetName("Jane");
    cout << oneStudent << endl;// This will print 1 as JANE=1 in enum declaration
    oneStudent = GetName("mary");
    cout << oneStudent << endl;// This will print 2 as MARY=2 in enum declaration
    return 0;
}

OUTPUT:

./main 0 1 2

FOR ANY HELP JUST DROP A COMMENT

Add a comment
Know the answer?
Add Answer to:
Assume you have the following declarations: enum StudentType {BILL, JANE, MARY}; StudentType oneStudent; Write a function,...
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
  • Assume you have a list L whose members are different stock values. Write a function in...

    Assume you have a list L whose members are different stock values. Write a function in R with one parameter X that will return “S” if the number is bigger than X and “B” otherwise Apply this function to each member of the list How can you modify this function so that will accept sequence in its parameter?

  • Assume you have the following variable declarations: SimpleReader in = new SimpleReader1L(); SimpleWriter out = new...

    Assume you have the following variable declarations: SimpleReader in = new SimpleReader1L(); SimpleWriter out = new SimpleWriter1L(); Write program fragments (i.e., you do not need to write complete programs) that read a line of input as a String and print: Only the uppercase letters in the String Every second letter of the String The String with all vowels replaced by an underscore The number of vowels in the String The positions of all vowels in the String

  • 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...

  • Assume that you have a String "name" attribute in a Java class definition.  Write a public method...

    Assume that you have a String "name" attribute in a Java class definition.  Write a public method to return this "name" attribute. public String getName() { return name;         } 1.) Write a statement that throws an IllegalArgumentException with the error message “Argument cannot be negative”.​ 2.) The method getValueFromFile is public and returns an int. It accepts no arguments. The method is capable of throwing an IOException and a FileNotFoundException. Write the header for this method.

  • use swift language Write a function that will accept an array of Emoji symbols of size...

    use swift language Write a function that will accept an array of Emoji symbols of size N and randomly returns a sumbol from the array. This function will have one parameter, the Array of Emoji Symbols and will return One emoji symbol as a String.

  • In C# You will be prompting the user for a text string a list of bills...

    In C# You will be prompting the user for a text string a list of bills they have every month. a. This should be a comma separated list , bill1, bill2, bill3 b. Validate that this text string is not left blank. 3. Create a custom function called CreateBillArray a. This function should accept the string variable that holds the bills. b. Inside of the function, split the text string of the bills into a string array with each individual...

  • Part1. Write a C program contains the following declarations: char customer_name[N_CUSTOMERS][MAX...

    Part1. Write a C program contains the following declarations: char customer_name[N_CUSTOMERS][MAX_NAME_LENGTH]; int customer_number[N_CUSTOMERS] A program uses a text file that contains the following data on each line: The customer number is an int, and the first and last names are alphabetic strings that contain no whitespace. The last and first names themselves are however separated by whitespace. Write a C function with the following prototype: void read_customer (char name[][MAX_NAME_LENGTH], int number[], int position, FILE *cust_file) Your function should read a...

  • Write a full class definition for a class named Player , and containing the following members: A data member name of t...

    Write a full class definition for a class named Player , and containing the following members: A data member name of type string . A data member score of type int . A member function called setName that accepts a parameter and assigns it to name . The function returns no value. A member function called setScore that accepts a parameter and assigns it to score . The function returns no value. A member function called getName that accepts no...

  • C++ //get_letter_grade.h /* Write a function gpa_to_letter_grade that returns a string and accepts a double gpa...

    C++ //get_letter_grade.h /* Write a function gpa_to_letter_grade that returns a string and accepts a double gpa parameter */ //get_letter_grade.cpp /* Write function code for gpa_to_letter_grade that returns a string and accepts a double gpa parameter YOU MUST USE A SWITCH STATEMENT Given a double 3.5 returns the string A TIP: You'll have to convert the double to an int using multiplication Table 3.5 to 4 returns an A 3.0 to 3.49 returns a B 1.7 to 2.99 returns a C...

  • assume we have the following constant declarations const int MAXIMUM = 60; const int letters_Size =...

    assume we have the following constant declarations const int MAXIMUM = 60; const int letters_Size = 15; we then have the function void Adjusting(char C_string[ ] [ ], int amount_words); assume that youve taken in a string from the user now just simply read the input wnd analyze the sentence into its parts and describe its roles basically parse into words and save it and sort into an array of C-strings. note code is in C++ complete the function definition...

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