Question

Write a C++ program to read in 4 different types of data values using cin, cout,...

Write a C++ program to read in 4 different types of data values using cin, cout, and the getline() function and display the values in the same order to the screen. Use cin to read in the first value and getline() to read in the remaining characters. Note that the 4 data items are entered on 1 line. The following shows a sample run of the program.

Enter 4 data values: 45 abc 12.34 d

The 4 data values entered are 45 abc 12.34 d

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Cpp program that reads a number and three other values
//and print the values on console
#include<iostream>
#include<string>
using namespace std;
int main()
{
   //set line length
   const int LINE_LENGTH=40;
   //integer value to read
   int number;
   //character a character array
   char line[LINE_LENGTH];

   //read a number
   cout<<"Enter 4 data values:";// 45 abc 12.34 d
   cin>>number;

   //read a line of three other data types in a line character array
   cin.getline(line,80);
   //print number and line
   cout<<"The 4 data values entered are "<<number<<line;   

   system("pause");
   return 0;
}

--------------------------------------------------------------------------------------------------------------------

Sample output:

flvsstudio-2005lcustomeridebuglCustomer.exe nter 4 data values:45 abc 12.34 d he 4 data values entered are 45 abc 12.34 dPres

Hope this helps you

Add a comment
Know the answer?
Add Answer to:
Write a C++ program to read in 4 different types of data values using cin, cout,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please i want correct answers object enables a program to read data from the user. The A. std::cout. std::cin. C. st...

    please i want correct answers object enables a program to read data from the user. The A. std::cout. std::cin. C. std::cread. D. std:cget. QUESTION 9 Which is the output of the following statements? "Hello" std:cout std::cout "World"; A. HelloWorld B.World Hello C.World D.Hello Click Save and Submit to save and subu object enables a program to read data from the user. The A. std::cout. std::cin. C. std::cread. D. std:cget. QUESTION 9 Which is the output of the following statements? "Hello"...

  • In C++ 1. Write a program that allows a user to enter 10 integer values from...

    In C++ 1. Write a program that allows a user to enter 10 integer values from the keyboard. The values should be stored in an array. 2. The program should then ask the user for a number to search for in the array: The program should use a binary search to determine if the number exists in a list of values that are stored in an array (from Step #1). If the user enters a number that is in the...

  • In C++ write a program that will read three strings from the user, a phrase, a...

    In C++ write a program that will read three strings from the user, a phrase, a letter to replace, and a replacement letter. The program will change the phrase by replacing each occurrence of a letter with a replacement letter. For example, if the phrase is Mississippi and the letter to replace is 's' the new phrase will be "miizzizzippi". in the function, replace the first parameter is a modifiable string, the second parameter is the occurrence of a letter...

  • Update the program in the bottom using C++ to fit the requirements specified in the assignment....

    Update the program in the bottom using C++ to fit the requirements specified in the assignment. Description For this assignment, you will be writing a single program that enters a loop in which each iteration prompts the user for two, single-line inputs. If the text of either one of the inputs is “quit”, the program should immediately exit. If “quit” is not found, each of these lines of input will be treated as a command line to be executed. These...

  • This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to...

    This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...

  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

  • Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director,...

    Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director, Genre, Year Released, Running Time) into a vector of structures and perform the following operations: Search for a specific title Search for movies by a specific director Search for movies by a specific genre Search for movies released in a certain time period Search for movies within a range for running time Display the movies on the screen in a nice, easy to read...

  • Write a program in C to generate random numbers. The program recieves 4 items on activation...

    Write a program in C to generate random numbers. The program recieves 4 items on activation through argv: 1. Name of the data file 2. Number of items for program to generate 3. Range of numbers 4. Seed of the random number generator Example run: ./rand datafile.txt 20 1000 3127 Program must convert all numbers to ints using atoi(), must save all parameters into variables, opens the data file to write the random numbers into it, program loops to generate...

  • I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7:...

    I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7: Customer Accounts Write a program that uses a structure to store the following data about a customer account:      Customer name      Customer address      City      State      ZIP code      Telephone      Account balance      Date of last payment The program should use an array of at least 20 structures. It should let the user enter data into the array, change the contents of any element, and display all the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT