Translate high-level instructions to C++ statements */ //include statement(s) //using namespace statement int main() {     //variable declaration     //executable statements     //return statement }   Replace the commented statements in the above skeleton with the instructions below: Write a C++ statement that includes the header file iostream. • Write a C++ statement that allows you to use cin, cout, and endlwithout the prefix std::. • Write C++ statement(s) that declare the following variables: num1, num2, num3, and averageof type int. • Write C++ statements that store 125into num1, 28 into num2, and -25 into num3. • Write a C++ statement that stores the average of num1, num2, and num3 into average. • Write C++ statement(s) that output the values of num1, num2, num3, and average. • Compile and run your program. Attach the output screen of a successful execution of your program below (Hint:Use the snipping tool to take screenshots):

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 1TF
icon
Related questions
Question
Write a program to solve the program exercise in chapter 2 #3. Consider the following program skeleton:
/*
Author(s): ..... *
Date: *
Title: Lab assignment 2b -- Standard IO *
Specification: *
Translate high-level instructions to C++ statements
*/
//include statement(s)
//using namespace statement
int main() {
    //variable declaration
    //executable statements
    //return statement
}
 
Replace the commented statements in the above skeleton with the instructions below:
Write a C++ statement that includes the header file iostream.
• Write a C++ statement that allows you to use cin, cout, and endlwithout the prefix std::.
• Write C++ statement(s) that declare the following variables: num1, num2, num3, and averageof type int.
• Write C++ statements that store 125into num1, 28 into num2, and -25 into num3.
• Write a C++ statement that stores the average of num1, num2, and num3 into average.
• Write C++ statement(s) that output the values of num1, num2, num3, and average.
• Compile and run your program.
Attach the output screen of a successful execution of your program below (Hint:Use the snipping tool to take screenshots):
 
Part 2 : Formatting Output
Consider the following program skeleton.
 
/* Author(s): .....
* Date:
* Title: Lab assignment 2a -- C++ Basics Lab assignment 2 
* Specification:
* This program will bring in two prices and two quantities of items from the keyboard and
* print those numbers in a formatted chart. */
#include ,iostream>
// Fill in the code to bring in the library for formatted output.
using namespace std;
int main() {
    f loat price1, price2;           // The price of 2 items
    int quantity1, quantity2;     // The quantity of 2 items
    cout << setprecision(2) << fixed << showpoint;
    cout << "Please input the price and quantity of the first item" << endl;
    // Fill in the input statement that reads in price1 and quantity1 from the keyboard.
    // Fill in the prompt for the second price and quantity.
    // Fill in the input statement that reads in price2 and quantity2 from the keyboard.
    cout << setw(15) << "PRICE" << setw(12) << "QUANTITY\n\n";
    // Fill in the output statement that prints the first price and quantity. Be sure to use // setw() statements.
    // Fill in the output statement that prints the second price and quantity.
    return 0;
}
Finish the code above by filling in the blanks and the instructions necessary to execute the following sample run. Note that two or more data items can be input at one time by having at least one blank space between them before hitting the enter key.
• Attach the output screen of a successful execution of your program below (Hint:Use the snipping tool to take screenshots)
 
Part 3: Understanding input failure
Input the code implemented below:
/* Author(s): .....
* Date: 
* Title: Lab assignment 2b -- Input failure
* Specification:
* Input Failure program */
#include<iostream> 
using namespace std;
int main() {
    int a = 10; //Line 1
    int b = 20; //Line 2
    int c = 30; //Line 3
    int d = 40; //Line 4
    cout << "Line 5: Enter four integers: "; //Line 5
    cin >> a >> b >> c >> d; //Line 6
    cout << endl; //Line 7
    cout << "Line 8: The numbers you entered are:" << endl; //Line 8
    cout << "Line 9: a = " << a << ", b = " << b << ", c = " << c << ", d = " << d << endl; / /Line 9
    cout << "Line 10: cin.fail() returns " << cin.fail() << endl; //Line 10
    cout << "Line 11: Now we will use cin.clear()." << endl; //Line 11
    cin.clear(); //Line 12
    cout << "Line 12: cin.fail() returns " << cin.fail(); //Line 13
    return 0;
}
1. Execute the program using the following input values:
34 K 67 28
Attach the output screen of a successful execution of your program below (Hint:Use the snipping tool to take screenshots):
 
 
2. Analyze the output of the program and explain how the input stream statements to explain how the clearand failfunctions work.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage