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]
3 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]3 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
A file that is 242 megabytes is being downloaded. if the download is 15.4% complete, how many megabytes have been downloaded? ro
Lunna [17]
37.26 megabytes have been downloaded
5 0
3 years ago
You need to fax a portion of a map from a large hard-cover atlas to a client from an internal fax-modem. To fax the map, the bes
Kay [80]
The fax modem is used to send and receive fax messages by only having phone line (fax machine is not required). The scanned documents should be saved as digital file (image or PDF format) in order to be sent. So, in order to send a portion of a map you should first convert the map into digital file and than simply send it through the fax modem. The best way to convert it to a digital file is to use an optical character recognition (OCR). 
6 0
3 years ago
What is the purpose of the SMTP command "HELO"
sergij07 [2.7K]
If a client initiates the SMTP communication using an EHLO (Extended Hello) command instead of the HELO command some additional SMTP commands are often available. They are often referred to as Extended SMTP (ESMTP) commands or SMTP service extensions. Every server can have its own set of extended SMTP commands.
4 0
3 years ago
How many wires are in a standard Cat 6 cable?
Lynna [10]
I believe it is 8

Hope this helps
5 0
2 years ago
Read 2 more answers
A ____ dynamic volume can only be created with three or more dynamic disks. raid 1 raid 5 raid 5i raid 23
aev [14]
The answer is Raid 5 and 23
8 0
3 years ago
Other questions:
  • Select all that apply. To select more than one worksheet at the same time, which of the following keys on your keyboard can you
    11·1 answer
  • I'm using my PS4 dual shock controller to connect to the fire stick on the tv so I can play games with it but whenever I try to
    10·1 answer
  • The expectations I would discuss with Erica regarding the usage of the internet
    6·1 answer
  • How does technology helps save the environment?​
    6·1 answer
  • When might be the best time to start saving for retirement?
    11·2 answers
  • The term computer ________ is used to describe someone who is familiar enough with computers to understand their capabilities an
    12·1 answer
  • A major problem with alcohol adverstising is that
    15·1 answer
  • Stephanie would like to know the average number of regular hours worked by her employees. In cell B11, create a formula using th
    8·1 answer
  • Wha are the types of slide show? define​
    10·1 answer
  • The choice of database does not have any impact on the relevancy of search results?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!