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 best way to ensure the accuracy and safety of your accounts is to:
Gekata [30.6K]
Use symbols and a different password for each one

6 0
2 years ago
mapa mental con la explicación de que medios de comunicación y redes sociales intervienen en la construcción de tu identidad​
lisov135 [29]

Answer:

este presente yo cuando me pidieron eso

5 0
2 years ago
To maintain your body temperature, your body converts chemical potential energy into thermal energy T or F
PilotLPTM [1.2K]
True
This is physics btw
CPE --> TE
4 0
3 years ago
3.3 Code Practice: Question 1
Bezzdna [24]

Answer:

day=int(input(“Enter today’s day numerically: ”))

if(day ==15 or day ==30):

print(“It’s payday!”)

if(day !=15 and day !=30):

print(“Sorry, not a payday.”)

Explanation:Good luck!

6 0
3 years ago
Ten(10) examples of wearables or wearable technologies?​
Semmy [17]

Answer:read

Explanation:

airpods

headphones

earbuds

AirPods  pro

watch

fitbit (type of watch that counts your miles) &you can say workout watch&

VR set

technology bracelet

smart glasses

Smart ring

7 0
3 years ago
Other questions:
  • Mention 3 wast water draining system on home​
    7·1 answer
  • Which audio editing effect uses the option ""Get Profile"" to execute its function?
    6·1 answer
  • Assume that the array monthSales of integers has already been declared and that its elements contain sales data for the 12 month
    13·1 answer
  • Access Control can be defined as putting controls (or countermeasures) in place to help achieve information security goals. Whic
    13·2 answers
  • Define a method pyramidVolume with double parameters baseLength, baseWidth, and pyramidHeight, that returns as a double the volu
    11·2 answers
  • Pomógłbymi ktoś z takim zadaniem? C++
    8·1 answer
  • How do i do a class in java??
    5·1 answer
  • According to the stage-gate process developed by Robert G. Cooper, _____ are the results of the previous stage and are the input
    15·1 answer
  • URGENT!!! Steve wants to change shooting and exposure settings while on his photo shoot. Which camera part will allow him to do
    12·2 answers
  • Write a 3-4 page paper (500-800 words) about your project that explains your project, the type of conditioning you used, and the
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!