Answer:
The answer to this question is given below in the explanation section
Explanation:
The expression that computes the average of value 12 and 40 is given below:
average = (12+40)/2;
in programming language we can write this expression as like;
int average = (12+40)/2;
Answer:
Here is the Python program:
#the method acronym that takes an argument phrase
def acronym(phrases):
acronym = "" #to store acronym of a phrase
#loop to split the input phrase and return its acronym in upper case letters
for phrase in phrases.split():
acronym = acronym + phrase[0].upper()
return acronym
#main function that takes input phrase from user and display its acronym
def main():
phrases = input("Enter a phrase: ")
print("The acronym for your phrase is ",acronym(phrases))
main()
Explanation:
First let me explain the method acronym. This method takes a parameter phrase to return its corresponding acronym. First the phrase is split using split() method which is used to return the list of words in a phrase. For loop is used that will keep splitting the words in the string (phrase) entered by the user.
In this statement: acronym = acronym + phrase[0].upper() the acronym is computed. phrase[0] means the first character of each word in the phrase which is found out by the split() method is converted to upper case by using upper() function and then stored in acronym variable. Each time the acronym is found and its first character is converted to upper case and added to the acronym variable.
Then the main() function prompts the user to enter a phrase and then calls the acronym function and passed that phrase as parameter to that function. Then the computed acronym for the phrase is printed on the screen.
Answer:
true.
Explanation:
your point fingers should always be
your left should rest on F
your right should rest on J
Answer:
<h2>
C++ Code:</h2>
#include <iostream> //header file for input output functions like cout cin
#include <sstream> // reads from string as a stream
#include <string>
// header file for strings
using namespace std; // used for computer to detect endl cout, cin
int main() { //start of the main function of the program
string userItem; // declare string type variable
ostringstream itemsOSS; // output string stream
cout << "Enter items (type Exit to quit):" << endl;
// prompts user to enter items and type Exit to quit
cin >> userItem; //reads input userItems
while (userItem != "Exit") { //loop that runs untill userItem gets equal to Exit
itemsOSS << userItem << " ";
// inserts userItem into the output string stream itemsOSS
cin >> userItem;
} //reads items stored in userItem variable
cout << itemsOSS.str() << endl;} // prints current contents of the itemsOSS.
<h2>
Explanation:</h2>
I will explain the code line by line.
- The first line includes a header file iostream which is used for input and output functions such as cin, cout etc.
- The next line includes sstream header file to read from a string as a stream. String streams are streams containing strings. Strings are treated like streams and stream operations are used on these strings.
- The next line includes string header file in order to use strings in the program.
- Next line namespace is used for the computer to identify objects like endl, cin, cout.
- This lines starts the main function and enters the body of main function.
- A string type variable userItem is declared.
- ostringstream type variable itemsOSS is declared. ostringstream class works on strings.
- This line prompts the user to enter the items and type Exit word to quit. endl is used to insert new line.
- This line read input from variable userItem which is inserted by the user.
- This statement starts a loop which will continue to execute until the user types Exit.
- In the body of while loop, this line shows that the items entered by the user in userItem will be inserted into the output string stream itemsOSS. Every userItem is followed by a space. << this is insertion operator. This retrieves items from the input sequence and inserts them into the itemsOSS, until Exit is typed.
- Next line reads items stored in userItem variable.
- str() returns a copy of the string which is manipulated by the current stream string and it outputs the contents of the itemsOSS stream.
<h2>
Output:</h2>
Enter items (type Exit to quit):
red purple yellow Exit
red purple yellow