g Write a method that accepts a String object as an argument and displays its contents backward. For instance, if the string argument is "gravity" the method should display -"ytivarg". Demonstrate the method in a program that asks the user to input a string and then passes it to the method.

Answers

Answer 1
Answer:

Answer:

The program written in C++ is as follows; (See Explanation Section for explanation)

#include <iostream>

using namespace std;

void revstring(string word)

{

   string  stringreverse = "";

   for(int i = word.length() - 1; i>=0; i--)

 {

     stringreverse+=word[i];

 }

 cout<<stringreverse;

}

int main()

{

 string user_input;

 cout << "Enter a string:  ";

 getline (std::cin, user_input);

 getstring(user_input);

 return 0;

}

Explanation:

The method starts here

void getstring(string word)

{

This line initializes a string variable to an empty string

   string  stringreverse = "";

This iteration iterates through the character of the user input from the last to the first

   for(int i = word.length() - 1; i>=0; i--)   {

     stringreverse+=word[i];

 }

This line prints the reversed string

 cout<<stringreverse;

}

The main method starts here

int main()

{

This line declares a string variable for user input

 string user_input;

This line prompts the user for input

 cout << "Enter a string:  ";

This line gets user input

 getline (std::cin, user_input);

This line passes the input string to the method

 revstring(user_input);

 return 0;

}


Related Questions

Convert the binary number into a hexadecimal number.
Once a device has failed, what metric measures the average amount of time to repair?a.mean field replacement time (MFRT)b.mean time to repair (MTTR)c.mean time to restore (MTTR)d.mean restoration time (MRT)
Which business application uses electronic tags and labels to identify objects wirelessly over short distances? A. Radio-frequency identificationB. Global positioning systemsC. Geographic information systemsD. Location-based services
Write an if statement that assigns 100 to x when y is equal to 0. 32. Write an if/else statement that assigns 0 to x when y is equal to 10. Otherwise it should assign 1 to x. 33. Using the following chart, write an if/else if statement that assigns .10, .15, or .20 to commission, depending on the value in sales. Sales Commission Rate Up to $10,000 10% $10,000 to $15,000 15% Over $15,000 20%
(Numerical Data Representation) How many bits per word are required to represent the following positive decimal integers: a.0 through 100b.0 through 255c.0 through 256d.0 through 10,000,000

Write a Python function fun3(e) to update a list of numbers e such that the first and last elements have been exchanged. The function needs to also return multiplication of elements of e. You should assume that the list e has at least 2 elements.Example:

>>>lst = [4, 1, 2, -1]

>>>fun3(list)

-8

Answers

Answer:

Here is code in Python:

#function to swap first and last element of the list

#and calculate product of all elements of list

def fun3(e):

   product = 1

   temp = e[0]

   e[0] = e[-1]

   e[-1] = temp

   for a in e:

       product *= a

   return product

#create a list

inp_lst = [4, 1, 2, -1]

#call the fun3() with parameter inp_lst

print("product of all elements of list is: ",fun3(inp_lst))

#print the list after swapping

print("list after swapping first and last element: ",inp_lst)

Explanation:

Create a list "inp_lst" and initialize it with [4,1,2,-1]. In the function fun3() pass a list parameter "e". create a variable "product" to calculate the product of all elements.Also create a temporary variable to swap the first and last element of the list.

Output:

product of all elements of list is:  -8                                                                                        

list after swaping first and last element:  [-1, 1, 2, 4]

The energy company in Program 1 now uses different rates for residential and business customers. Residential customers pay $0.12 per kWh for the first 500 kWh. After the first 500 kWh, the rate is $0.15 per kWh. Business customers pay $0.16 per kWh for the first 800 kWh. After the first 800 kWh, the rate is $0.20 per kWh. Write a program to calculate energy charge. You must write and use the following two functions. (a)A main function: Ask the user to enter number of kWh used and customer type (enter R for residential or B for business). Call the bill_calculator function and pass number of kWh used and customer type to it as arguments. You must use positional arguments to pass kWh used and customer type. (b)A bill_calculator function: This function has two parameters to receive number of kWh used and customer type. Calculate and display the energy charge.

Answers

Answer:

The c# program for the scenario is given below.

using System;

public class Program2 {

 double total = 0;

 static void Main() {

     Program2 ob = new Program2();

   Console.WriteLine("Enter total energy used in kilo watts ");

   int p;

   p = Convert.ToInt32(Console.ReadLine());

   Console.WriteLine("Enter type of customer ");

   char t;

   t = Convert.ToChar(Console.ReadLine());

   ob.bill_calculator(p, t);

   Console.WriteLine("Total charge for " + p + " kilo watts electricity for " + t + " customers is " + ob.total);

 }

 public void bill_calculator(int e, char c)

 {

     int first=500, second = 800;

     double chg_one = 0.12, chg_two=0.15, chg_three = 0.16, chg_four = 0.20;

     if(c == 'R')

     {

        if(e <= 500)

        {      

            total = (e * chg_one);

        }

        else if(e > 500)

        {

           total = ( first * chg_one);

           total = total + ((e-first) * chg_two);

        }

     }

     if(c == 'B')

     {

        if(e <= 800)

        {      

          total = (e * chg_three);

        }

        else if(e > 800)

        {

          total = ( first * chg_three);

          total = total + ((e-second) * chg_four);

        }

     }

  }

}

OUTPUT

Enter total energy used in kilo watts                                                                                                            

1111                                                                                                                                            

Enter type of customer                                                                                                                          

B                                                                                                                                                

Total charge for 1111 kilo watts electricity for B customers is 142.2

Explanation:

The program takes user input for the type of customer and the amount of electric current used by that customer.

The two input values decide the rate at which total charge is calculated.

For residential customers, charges are divided into slabs of 500 or less and more than 500.

Alternatively, for business customers, charges are divided into slabs of 800 or less and more than 800.

User input is taken in main function.

Charges are calculated in the bill_calculator method which takes both user input as parameters.

If else block is used to calculate the charges.

No input validation is implemented as it is not mentioned in the question.

All code is written inside the class. An object is created of the class.

The methods outside main() are called using the object of the class.

The Clean Air Act Amendments of 1990 prohibit service-related releases of all ____________. A) GasB) OzoneC) MercuryD) Refrigerants

Answers

Answer:

D. Refrigerants

Explanation:

In the United States of America, the agency which was established by US Congress and saddled with the responsibility of overseeing all aspects of pollution, environmental clean up, pesticide use, contamination, and hazardous waste spills is the Environmental Protection Agency (EPA). Also, EPA research solutions, policy development, and enforcement of regulations through the resource Conservation and Recovery Act .

The Clean Air Act Amendments of 1990 prohibit service-related releases of all refrigerants such as R-12 and R-134a. This ban became effective on the 1st of January, 1993.

Refrigerants refers to any chemical substance that undergoes a phase change (liquid and gas) so as to enable the cooling and freezing of materials. They are typically used in air conditioners, refrigerators, water dispensers, etc.

The Clean Air Act Amendments of 1990 prohibit service-related releases of all refrigerants. The correct option is D.

Thus, The Environmental Protection Agency (EPA), which was formed by US Congress, is the organization tasked with regulating all facets of pollution, environmental cleanup, pesticide use, contamination, and hazardous material spills.

All refrigerants, including R-12 and R-134a, are forbidden from being released during service under the Clean Air Act Amendments of 1990. On January 1st, 1993, this ban came into force.

Any chemical compound that transforms into a different phase (liquid or gas) to allow for the cooling or freezing of items is referred to as a refrigerant. They are frequently found in refrigerators, water dispensers, air conditioners, and other appliances.

Thus, The Clean Air Act Amendments of 1990 prohibit service-related releases of all refrigerants. The correct option is D.

Learn more about Clean air act, refer to the link:

brainly.com/question/2375762

#SPJ3

Which of the following is an example of computer hardware App
PowerPoint
Web browser
Microchip

Answers

Answer:

its mircrochip

Explanation:

Answer:

i think  either microchip or an app im not sure

the other answers smarter than mine make him brainliest

Explanation:

Consider the following two code segments, which are both intended to determine the longest of the three strings "pea", "pear", and "pearl" that occur in String str. For example, if str has the value "the pear in the bowl", the code segments should both print "pear" and if str has the value "the pea and the pearl", the code segments should both print "pearl". Assume that str contains at least one instance of "pea".I.

if (str.indexOf("pea") >= 0)

{

System.out.println("pea");

}

else if (str.indexOf("pear") >= 0)

{

System.out.println("pear");

}

else if (str.indexOf("pearl") >= 0)

{

System.out.println("pearl");

}

II.

if (str.indexOf("pearl") >= 0)

{

System.out.println("pearl");

}

else if (str.indexOf("pear") >= 0)

{

System.out.println("pear");

}

else if (str.indexOf("pea") >= 0)

{

System.out.println("pea");

}

Which of the following best describes the output produced by code segment I and code segment II?

Both code segment I and code segment II produce correct output for all values of str.

Neither code segment I nor code segment II produce correct output for all values of str.

Code segment II produces correct output for all values of str, but code segment I produces correct output only for values of str that contain "pear" but not "pearl".

Code segment II produces correct output for all values of str, but code segment I produces correct output only for values of str that contain "pearl".

Code segment II produces correct output for all values of str, but code segment I produces correct output only for values of str that contain "pea" but not "pear".

Answers

Answer:

Code segment II produces correct output for all values of str, but code segment I produces correct output only for values of str that contain "pea" but not "pear".

Explanation:

The main issue with the first code segment is the way how the if else if condition are arranged. The "pea" is checked at the earliest time in the first code segment and therefore so long as there is the "pea" exist in the string (regardless there is pear or pearl exist in the string as well), the if condition will become true and display "pea" to terminal. This is the reason why the code segment 1 only work for the values of str that contain "pea".

software that interprets commands from the keyboard and mouse is also known as the? A. desktop B. Operating system C. operating disk D. hard drive

Answers

Answer:

C

Explanation: