(Write C++ Statements) Write a statement for each of the following:
- Print integer 40000 left justified in a 15-digit field.
- Read a string into character array variable state.
- Print 200 with and without a sign.
- Print the decimal value 100 in hexadecimal form preceded by 0x.
- Read characters into array charArray until the character ‘p’ is encountered, up to a limit of 10 characters (including the terminating null character). Extract the delimiter from the input stream, and discard it.
- Print 1.234 in a 9-digit field with preceding zeros.
a.
To print integer 4000 left justified in a 15-digit field.
Explanation of Solution
The function setw() is used in C++ to adjust the field width for output.
intleftalign=4000;
cout<<setw(15)<<leftalign;
b.
To read a string into character array variable state.
Explanation of Solution
Following statement will read as string into character array variable state.
cin>>state;
c.
To print 200 with and without a sign.
Explanation of Solution
Following statement will print the number 200 with sign
cout<< “+200”;
Following statement will print the number 200 without sign
cout<< “200”;
d.
To print the decimal value 100 in hexadecimal form preceded by 0x.
Explanation of Solution
Following set of statement will print the decimal value 100 as specified.
cout<<”Print the value decimal value 100 in hexadecimal format”;
inttoHex = 100;
cout<<”The decimal number 100 converted to hexadecimal =”;
e.
To read the characters into array charArray until the character ‘p’ is encountered, upto a limit of 10 characters (including the terminating null character). To extract the delimiter from the input stream and discard it.
Explanation of Solution
char array[10]; for( int i=0;i<10; i++) { if(array[i]!=‘p’) { cout<<array[i]; } else break; } array[--i] = “”;
f.
To print 1.234 in a 9-digit field with preceding zeros.
Explanation of Solution
Following statement will print 1.234 with 9 digit field with preceding zeros.
cout<<setfill('0')<<setw(9)<<1.234;
Want to see more full solutions like this?
Chapter 21 Solutions
C How to Program (8th Edition)
Additional Engineering Textbook Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Database Concepts (8th Edition)
Java How To Program (Early Objects)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
- (Airplane Seating Assignment) | Write a program that can be used to assign seats for a commercial airplane. The airplane has 13 rows, with six seats in each row. Rows 1 and 2 are first class, rows 3 through 7 are business class, and rows 8 through 13 are economy class. Use two parallel arrays: a one-dimensional array to store the row number of the seats (Row #) a two-dimensional array of 13 rows and 6 columns to store the seat assignments (*) and seat letters (A-F) Your program must prompt the user to enter the following information: Reserve a seat (Yes (Y/y) or No (N/n)) Assign ticket type (first class (F/f), business class (B/b), or economy class (E/e)) Select desired seat (1-13 and A-F) Your program must contain at least the following functions: a function to initialize the seat plan. a function to show the seat assignments. a function to show the menu to assign a seat. a function to assign and select your desired seat. a function for each ticket type that determines if a seat…arrow_forward(Airplane Seating Assignment) | Write a program that can be used to assign seats for a commercial airplane. The airplane has 13 rows, with six seats in each row. Rows 1 and 2 are first class, rows 3 through 7 are business class, and rows 8 through 13 are economy class. Use two parallel arrays: a one-dimensional array to store the row number of the seats (Row #) a two-dimensional array of 13 rows and 6 columns to store the seat assignments (*) and seat letters (A-F) Your program must prompt the user to enter the following information: Reserve a seat (Yes (Y/y) or No (N/n)) Assign ticket type (first class (F/f), business class (B/b), or economy class (E/e)) Select desired seat (1-13 and A-F) Your program must contain at least the following functions: a function to initialize the seat plan. a function to show the seat assignments. a function to show the menu to assign a seat. a function to assign and select your desired seat. a function for each ticket type that determines if a seat…arrow_forward(Check test scores) The answers to a true-false test are as follows: T T F F T. Given a two-dimensional answer array, in which each row corresponds to the answers provided on one test, write a function that accepts the two-dimensional array and number of tests as parameters and returns a one-dimensional array containing the grades for each test. (Each question is worth 5 points so that the maximum possible grade is 25.) Test your function with the following data: int score = 0;arrow_forward
- . (True/False): A segment selector points to an entry in a segment descriptor tablearrow_forwardCorrect my mistake in my C++ code please! Here is the questin and my code is below as well. (Duplicate Elimination with array) Use a one-dimensional array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, validate it and store it in the array only if it isn't a duplicate of a number already read. After reading all the values, display only the unique values that the user entered. Provide for the 'worst case' in which all 20 numbers are different. Use the smallest possible array to solve this problem. Code; #include <iostream> using namespace std; int main(){ int arr[100]={0};int temp,i;for( i=0;i<20;i++){ cout<<"Enter an Integer : "; cin>>temp; arr[temp]++;}for( i=0;i<100;i++) if(arr[i]==1) cout<<i<<" "; return 0;}arrow_forwardusing c++ programming ::::: 16. (Pick 5 Lotto) Write a program to simulate a pick-5 lottery game. Your program should generate and store 5 distinct numbers between 1 and 9 (inclusive) into an array. The program prompts the user to enter five distinctbetween 1 and 9 and stores the number into another array. The programthen compares and determines whether the two arrays are identical. If thetwo arrays are identical, then the user wins the game; otherwise the program outputs the number of matching digits and their position in the array.Your program must contain a function that randomly generates thepick-5 lottery numbers. Also, in your program, include the functionsequential search to determine if a lottery number generated hasalready been generated.arrow_forward
- Write C++ statements to do the following:i.Declare an empty array DATA to hold 7 double floating values.ii.Assign value 5.7 to the last element in the array.iii.Display the sum of the first two elements without using extra memory variable.iv.Write a while-loop that computes the sum of all elements in the array.v.Write a while-loop that finds the minimum element in the array.vi.Randomly generate an index and display the element at this (randomly generated) index in the array.vii.Use an array initializer to declare another array with initial values 5.78, 12.69, 10.45, and19.0arrow_forwardUSE C++ (Display matrix of 0s and 1s) Write a function that displays an n-by-n matrix using the following header: void printMatrix(int n) Each element is 0 or 1, which is generated randomly. Write a test program that prompts the user to enter n and displays an n-by-n matrix. Here is a sample run:arrow_forwardCorrect my mistake in my C++ code please! Here is the question and my code is below as well. (Duplicate Elimination with array) Use a one-dimensional array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, validate it and store it in the array only if it isn't a duplicate of a number already read. After reading all the values, display only the unique values that the user entered. Provide for the 'worst case' in which all 20 numbers are different. Use the smallest possible array to solve this problem. Code; #include <iostream> using namespace std; int main(){ int arr[100]={0};int temp,i;for( i=0;i<20;i++){ cout<<"Enter an Integer : "; cin>>temp; arr[temp]++;}for( i=0;i<100;i++) if(arr[i]==1) cout<<i<<" "; return 0;}arrow_forward
- Q2: Write a C++ function (call it index_max) that finds the maximum number in the array, that is passed to the function, and returns the max number and its index. For example, if you pass [5,6,8,9,5,2] to the function, you obtain 9 and 3. Write a C++ program and test your function. Take the following notes into consideration when writing your program: 1- Your function should work with any data type. 2- The function should prevent changing the elements of the passed array. 3- You are not allowed to use materials that are not covered in our lectures.arrow_forward(True/False): A segment descriptor does not contain segment size informationarrow_forwardI want this in c++ programming language sir.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education