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
masha68 [24]
2 years ago
12

2.36 LAB: Warm up: Variables, input, and casting (1) Prompt the user to input an integer, a double, a character, and a string, s

toring each into separate variables. Then, output those four values on a single line separated by a space. Enter integer: 99 Enter double: 3.77 Enter character: z Enter string: Howdy 99 3.770000 z Howdy (2) Extend to also output in reverse. (1 pt) Enter integer: 99 Enter double: 3.77 Enter character: z Enter string: Howdy 99 3.770000 z Howdy Howdy z 3.770000 99 (3) Extend to cast the double to an integer, and output that integer. (2 pts) Enter integer: 99 Enter double: 3.77 Enter character: z Enter string: Howdy 99 3.770000 z Howdy Howdy z 3.770000 99 3.770000 cast to an integer is 3

Computers and Technology
1 answer:
Westkost [7]2 years ago
3 0

Answer:

The entire program is:

#include <iostream>

using namespace std;

  int main() {          

  int userInt;

  double userDouble;

  char userChar;

  string userString;  

  cout<<"Enter integer:"<<endl;

  cin>>userInt;  

  cout<<"Enter double:"<<endl;

  cin>>userDouble;  

  cout<<"Enter character:"<<endl;

  cin>>userChar;  

  cout<<"Enter string:"<<endl;

  cin>>userString;    

 cout<<userInt<<" "<<userDouble<<" "<<userChar<<" "<<userString<<endl;

 cout<<endl;  

   cout<<userInt<<" "<<userDouble<<" "<<userChar<<" "<<userString<<endl<<userString<<" "<<userChar<<" "<<userDouble<<" "<<userInt<<endl;  

cout<<endl;

cout<<userInt<<" "<<userDouble<<" "<<userChar<<" "<<userString<<endl<<userString<<" "<<userChar<<" "<<userDouble<<" "<<userInt<<endl<<userDouble<<" cast to an integer is "<<(int)userDouble;  

  return 0;  }

The program in C language:

#include <stdio.h>  

int main() {

  int userInt;  

  double userDouble;  

  char userChar;  

  char userString[50];

  printf("Enter integer: \n");  

  scanf("%d", &userInt);

  printf("Enter double: \n");  

  scanf("%lf", &userDouble);

  printf("Enter character: \n");  

  scanf(" %c", &userChar);  

  printf("Enter string: \n");  

  scanf("%s", userString);  

  printf("%d %lf %c %s\n", userInt, userDouble, userChar, userString);

  printf("\n");

  printf("%d %lf %c %s\n%s %c %lf %d \n", userInt, userDouble, userChar, userString, userString, userChar, userDouble, userInt);

  printf("\n");

  printf("%d %lf %c %s\n%s %c %lf %d\n%lf cast to an integer is %d \n", userInt, userDouble, userChar, userString, userString, userChar, userDouble, userInt, userDouble, (int)userDouble);  }

Explanation:

Lets do the program step by step:

1)  Prompt the user to input an integer, a double, a character, and a string, storing each into separate variables. Then, output those four values on a single line separated by a space:

Solution:

The program is:

#include <iostream>  //to use input output functions

using namespace std;  //to identify objects cin cout

  int main() {  //start of main method

  //declare an integer, a double, a character and a string variable  

  int userInt;  //int type variable to store integer

  double userDouble;  //double type variable to store double precision floating point number

  char userChar;  //char type variable to store character

  string userString;  //string type variable to store a string

  cout<<"Enter integer:"<<endl;  //prompts user to enter an integer

  cin>>userInt;  //reads the input integer and store it to userInt variable

  cout<<"Enter double:"<<endl;  //prompts user to enter a double type value

  cin>>userDouble;  //reads the input double value and store it to userDouble variable

  cout<<"Enter character:"<<endl;  //prompts user to enter a character

 cin>>userChar; //reads the input character and store it to userChar variable

  cout<<"Enter string:"<<endl;  //prompts user to enter a string

  cin>>userString; //reads the input string and store it to userString variable

   

cout<<userInt<<" "<<userDouble<<" "<<userChar<<" "<<userString<<endl; //output the values on a single line separated by space

So the output of the entire program is:

Enter integer:                                                                                                                                99                                                                                                                                            Enter double:                                                                                                                                 3.77                                                                                                                                          Enter character:                                                                                                                              z                                                                                                                                             Enter string:                                                                                                                                 Howdy                                                                                                                                         99 3.77 z Howdy

(2) Extend to also output in reverse.

Now the above code remains the same but add this output (cout) statement at the end:

  cout<<userString<<" "<<userChar<<" "<<userDouble<<" "<<userInt;

Now the output with the same values given as input is:

Enter integer:                                                                                                                                  99                                                                                                                                              Enter double:                                                                                                                                   3.77                                                                                                                                            Enter character:                                                                                                                                z                                                                                                                                               Enter string:                                                                                                                                   Howdy  

99 3.77 z Howdy                                                                                                                                     Howdy z 3.77 99

(3) Extend to cast the double to an integer, and output that integer.

The rest of the code remains the same but add the following output (cout) statement in the end:

cout<<userDouble<<" cast to an integer is "<<(int)userDouble;

Now the output with the same values given as input is:

Enter integer:                                                                                                                                  99                                                                                                                                              Enter double:                                                                                                                                   3.77                                                                                                                                            Enter character:                                                                                                                                z                                                                                                                                               Enter string:                                                                                                                                   Howdy                                                                                                                                           99 3.77 z Howdy                                                                                                                                 Howdy z 3.77 99                                                                                                                                 3.77 cast to an integer is 3  

You might be interested in
The replacer parameter of the stringify method accepts a/an ______________ or an array.
Elina [12.6K]

Answer:

The answer is function

Explanation:

As a function, it accepts two parameters: the value and the key being stringified.  It can be used to change the value of the entries or eliminate them. As an array, it specifies by name which entries and names of the properties in the object to include in the resulting JSON string.

7 0
3 years ago
The minimum spanning tree of an undirected graph G exists if and only if G is connected. True or False?
zlopas [31]

Answer: True

Explanation:

The definition of minimum spanning tree(MST) says that the graph must be connected and undirected to be considered for MST. It has (V-1) edges where V is the number of vertices. The minimum spanning tree is implemented using Kruskal's algorithm whereby it starts by considering the minimum weighted edge and covers all the edges upto (V-1) edges. So for MST it has to be connected

3 0
2 years ago
5.17 (Calculating Sales) An online retailer sells five products whose retail prices are as follows: Product 1, $2.98; product 2,
Dima020 [189]

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

   

    //Initialize the prices as constants

    final double PRODUCT_1_PRICE = 2.98;

    final double PRODUCT_2_PRICE = 4.50;

    final double PRODUCT_3_PRICE = 9.98;

    final double PRODUCT_4_PRICE = 4.49;

    final double PRODUCT_5_PRICE = 6.87;

   

    //Declare the other variables

    int productNumber, quantitySold;

    double total = 0.0;

   

    //Create a Scanner object to get input

    Scanner input = new Scanner(System.in);

   

    //Create a while loop

    while(true){

        //Ask the user to enter the productNumber

     System.out.print("Enter the product number or 999 to quit: ");

     productNumber = input.nextInt();

     

     // Stop the loop, if productNumber is 999(sentinel value, you may choose any value you want)

     if(productNumber == 999)

         break;

     

     //Ask the user to enter the quantitySold

     System.out.print("Enter the quantity sold: ");

     quantitySold = input.nextInt();

     

     //Create a switch statement that works depending on the productNumber entered.

     //For example, if the productNumber is 1, it multiplies the quantitySold by PRODUCT_1_PRICE

     //   and adds the result to the total. If productNumber is 2, it does the same for product 2 ...

     switch(productNumber){

         case 1:

             total += quantitySold * PRODUCT_1_PRICE;

             break;

         case 2:

             total += quantitySold * PRODUCT_2_PRICE;

             break;

         case 3:

             total += quantitySold * PRODUCT_3_PRICE;

             break;

         case 4:

             total += quantitySold * PRODUCT_4_PRICE;

             break;

         case 5:

             total += quantitySold * PRODUCT_5_PRICE;

             break;

     }

    }

 

 //Print the total (when the loop is done)

 System.out.println("The total is $" + total);

}

}

Explanation:

*The code is in Java.

You may see the explanation as comments in the code.

4 0
3 years ago
3.1.1 What type of goods are car radio and remote control.​
Nuetrik [128]

Answer:

Radio Controlled cars .

4 0
2 years ago
Which OS does NOT provide users with a GUI?
vesna_86 [32]
The answer is C ms-dos
Side note:
GUI means graphical user interface. In other words, that means it looks pretty and has cool buttons, animations and cute stuff. MS-DOS is just a black screen with words on it. Definitely not cute or cool.
3 0
3 years ago
Other questions:
  • Write a program that estimates the approximate number of times the user’s heart has beat in his/her lifetime using an average he
    12·1 answer
  • It is safe to use your bright headlights if there is a car ahead of you within 300 feet
    9·2 answers
  • When is the bond between the actin and myosin head is broken? when an ATP molecule binds to the myosin head when an ATP molecule
    6·1 answer
  • Which of the following is the correct code to link the text "Sunny Days" to the website www.sunnysunshine.com?
    15·1 answer
  • The page orientation in which the page width is greater than the page height is called
    8·1 answer
  • Design and implement an algorithm that gets a list of k integar values N1, N2,...Nk as well as a special value SUM. Your algorit
    10·1 answer
  • Careers in information technology deal with
    12·2 answers
  • Literally no one helps answer my questions so this website is pointless.... : /
    11·1 answer
  • Consider the code below. When you run this program, what is the output if the temperature is 77.3 degrees Fahrenheit?
    6·1 answer
  • which program monitors the computer by looking for known trouble makers as well as suspicious behavior​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!