1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
trasher [3.6K]
3 years ago
12

C++ Language Use functions to solve all problems in the mentioned assignment

Computers and Technology
1 answer:
alexdok [17]3 years ago
7 0

Answer:

Following are the program to this question:

Q1:

#include <iostream> //including header file

using namespace std;

int main() //defining main method

{

   int m,n,i; //defining integer variable

   cout<<"Enter starting value: "; //print message

   cin>>m; //input m variable value

   cout<<"Enter ending value: ";//print message

   cin>>n;//input n variable value

   for(i=m;i<=n;i++) //defining loop to count even number  

   {

       if(i%2==0) //check even number condition

       {

           cout<<i<<" "; //print value

       }

   }

   return 0;

}

Q2:

#include<iostream> //include header file

using namespace std;

void menu() //define method menu

{

cout<<"Enter 1 for print your name and id: "<<endl; //print message

cout<<"Enter 2 for sum of odd numbers from 1 to 20: "<<endl;//print message

cout<<"Enter 3 for reverse of any number: "<<endl;//print message

cout<<"Enter 4 for exit"<<endl;//print message

}

void findsum() //define method findsum

{

int s=0,i; //defining integer variable

for(i=1;i<=20;i++) //defining loop to count odd number  

{

s=s+i; //add numbers

}

cout<<"Odd number sum from 1 to 20: "<<s; //print value

}

void revers() //defining method revers

{

int n,r,rev=0; //defining integer variable

cout<<"enter any number: "; //print message

cin>>n; //input value

while(n!=0) //define loop to reverse value

{

r=n%10; //store value in r variable

rev=(rev*10)+r; //add reverse value

n=n/10; //divide digit

}

cout<<"The reverse of a given number is: "<<rev; //print reverse value

}

int main() //defining main method

{

int c,rn; //defining integer variable

char n[30]; // defining char variable

menu(); //calling menu method

cout<<"Enter your selected choice: "<<endl; //print message

cin>>c; //input value in char variable

switch(c) //defining switch

{

   //defining case

case 1: cout<<"Enter your name: "<<endl; //print message for input name and id  

       cin>>n;//input name

       cout<<"Enter registration number: "<<endl; //print message  

       cout<<"Name: "<<n<<endl; // print name value

       cout<<"Registration number: "<<rn<<endl; // print id value

   break;

case 2: findsum(); //calling findsum method

   break;

case 3: revers(); //calling reverse method

   break;

case 4: exit(1); // calling exit method

   break;

default: cout<<"please enter valid choice"; //defining default choice

   break;

}

return 0;

}

Q3:

#include <iostream>//defining header file

using namespace std;

void reverse() //defining method readInput

{

  char x; //defining char variable

  cout<<"Enter a character: "; //print message

  cin>>x; //input value

  if(x=='.') //defining condition that check value is .  

   return; //using return keyword

  reverse(); //calling readInput method

  cout<<x; //print value

}

int main() //defining main method

{

  reverse(); //calling readInput method

return 0;    

}

Output:

please find the attachment.

Explanation:

Description of the given question as follows:

  • In question 1, three integer variable "m, n and i" is declared, in which variable "m and n" is used in user input, and variable "i" is used a loop to print even number from the user input values.
  • In question 2, a menu method is declared that prints a list menus in the next line, two methods "findsum() and revers()"is declared, in which "findsum" method is used to add odd values from 1 to 20 and the revers method is used to reverse value from an input digit. In the last line main method is declared, which uses switch to call the above methods.
  • In question 3, in this, a reverse method is defined, in which a char variable x is declared that input char value and define if block to check if char is equal to (.) if this is correct it will print the value in reverse order.

You might be interested in
Question = 5 Which of these causes problems because it causes all words to have the same shape? ​
Sever21 [200]
Where’s the picture?? Send the picture I’m not tryna just get points I want to help but you didn’t upload a picture
5 0
3 years ago
How could you insert a new row between rows 20 and 21?
podryga [215]
Highlight the row(20), then click on the insert cells button under the home ribbon.
3 0
3 years ago
Read 2 more answers
Write an algorithm whether the given number is positive negative or zero​
Ahat [919]

Answer:

See the code below in python.

Explanation:

num = int(input("Enter a number: "))

if (num == 0):

 print("You entered 0...")

elif (num < 0):

 print("Your entered a negative number...")

else:

 print("You entered a positive number...")

Regards: Your Friendly Study Co-Pilot!

6 0
3 years ago
When assigning a value to a string, which of the following rules needs to be followed?
Alecsey [184]

Answer:

Let's say you need to remember some information, the way moviegoers tried to remember the name of the movie. Instead of storing it in your human memory, you can store information in your computer's memory using Python. This is called assigning a string value to a variable.

To assign a string value to a variable in Python, follow this example. Select each part of the code to see how it works with the movie title example.

movieTitle = "Live. Die. Repeat."

This line of Python code is an example of an assignment statement. In an assignment statement, you tell Python, "This variable is assigned this string value."

Explanation:

4 0
3 years ago
Assume you have thefollowing declaration int beta[50];.Which of the following is a valid elementof beta?
ANEK [815]

Answer:

A - beta[0]

Explanation:

Beta[0] is the first element of the array, therefore automatically it is a valid element of beta. B and C are disqualified because you would not use single quotations when referring to an element. D is disqualified because the element starts at 0 (beta[0]) and has 50 elements declared, therefore it would end at 49, with beta[49] being the last element.

4 0
3 years ago
Other questions:
  • Alex has started a Google Search campaign designed to promote his online motorcycle accessories store. His store focuses on cust
    6·1 answer
  • If you were asked to subnet a network in such a way as to arrive at 6 network ids you would need to borrow 2 bits.
    7·1 answer
  • A customer has a system with a Gigabyte B450 Aorus Pro motherboard. He wants to upgrade the processor from the AMD Athlon X4 950
    8·2 answers
  • A small graphic that you click on to perform a function in a software program is called a _____.
    15·1 answer
  • Data are sent through a network on bundles called ____packets____. select one:
    14·2 answers
  • At Chicago Cubs games, residents across the street from Wrigley Field can watch the game from their apartment windows. Many of t
    14·1 answer
  • You receive an email from a woman claiming her father was poisoned by business associates, but before his passing placed 12 mill
    12·2 answers
  • What three actions happen when you cloak a folder or file?
    6·1 answer
  • How to find the next instance of text formatted in bold
    15·1 answer
  • Consider the following code and its output:
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!