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
Step2247 [10]
2 years ago
13

In C++ write a program that prints out PI as a type double and a type float EXACTLY as shown below. Your program should have ONE

cout statement within a loop which alters the width and precision each time through the loop. Do not write 10 separate cout statements for this problem. Show the output in a table that increases the precision from 1 to 10 as shown below. Use dash ('-') as the fill character. Note the differences as the precision gets larger.
Use the following two variables for PI.

double PI_D = 3.14159256359;
float PI_F = 3.14159256359;
Computers and Technology
1 answer:
victus00 [196]2 years ago
3 0

Answer:

#include<iostream>

#include<iomanip>

using namespace std;

int main()

{

double PI_D = 3.14159256359;

float PI_F = 3.14159256359;

cout<<"i"<<"\t\t"<<"Float"<<"\t\t"<<"Double"<<endl;

for(int i = 1; i<=10;i++)

{

 cout<<i<<"-\t\t"<<PI_F<<setprecision(i)<<"-\t\t"<<PI_D<<setprecision(i)<<endl;

}

 return 0;

}

Explanation:

See Attachment where I used comments for explanation

Download cpp
You might be interested in
Create a new file that builds a shopping list from a user. There should be a input query that asks the user to list an item and
levacccp [35]

Answer:

Check the output

Explanation:

# -*- coding: utf-8 -*-

"""

Created on Thu Apr 12 00:39:11 2018

author:

"""

stocks ={

       "tomato soup": 20,

       "cheese": 8,

       "bread": 6,

       "milk": 8,

       "butter": 7,

       "coffee": 8,

       "ice cream": 5,

       "orange juice": 12,

       "bacon": 6,

       "tortilla chips": 14,

       "ramen": 24 }

prices ={

       "tomato soup": 1.85,

       "cheese": 3.99,

       "bread": 2.50,

       "milk": 3.59,

       "butter": 1.99,

       "coffee": 5.99,

       "ice cream": 2.99,

       "orange juice": 2.50,

       "bacon": 5.49,

       "tortilla chips": 3.00,

       "ramen": 0.99 }

def grocery_cost(item_list,quantity_list):

   totalcost = 0

   for i in range(len(item_list)):

       totalcost=totalcost+(quantity_list[i]*prices[item_list[i]])

       

   return totalcost

def stock(item):

   print("Number of itmes present in the stock:",stocks[item])

print("Welcome to the on-line grocery store!!")

print("Items that are available for purchase:")

for key in stocks.keys():

   print(key)

#chosen foods

print("Enter the item with quantity or Enter 'Q' when you are done")

item_list=[]

quantity_list=[]

while True:

   item=input('Enter the item name: ')

   if item=='Q' or item=='q':

       break

   item_list.append(item)

   while True:

       quan=int(input('Enter the number of item: '))

       if stocks[item] >=quan:

           quantity_list.append(quan)

           break

       else:

           stock(item)

           print('Your requirement is higher than stock available. Please enter again!!')

print("\nTotal cost:", "$",grocery_cost(item_list,quantity_list))

Kindly check the output in the attached image below.

7 0
3 years ago
Aurelia is designing a user interface for a new game app. Which of the following should she taken into consideration for the use
serious [3.7K]

Answer:

C

Explanation:

what types of loop will be used.

4 0
2 years ago
What qualities in an employee are highly desired by employers?
slava [35]
Flexibility and open-mindedness
being quick to adapt to technology changes
having a positive attitude
taking initiative to solve problems
5 0
3 years ago
Read 2 more answers
The elements in a string type array will be initialized to ____.?
ivanzaharov [21]
The elements in a string type array will be initialized to "Null".
7 0
3 years ago
What statement would you use to print the phrase Hello, world and then start a new line?
tangare [24]

Answer:

Statement to print phrase "Hello, world" and then start a new line in java.

System.out.println("Hello, world");

Explanation:

In java, we use "System.out.println();" statement to print any string/phrase and then start a new line.The above line will print phrase "Hello, world" and then start a new line.

Implementation in java:

// class definition

class Main

{

// main method of the class

public static void main (String[] args)

{

// statement to print phrase and start new line

      System.out.println("Hello, world");  

} }

7 0
3 years ago
Other questions:
  • Which kind of software allows users to draw pictures, shapes, and other graphical images with various on-screen tools such as a
    14·1 answer
  • A check list should be based on that apply to your industry.
    11·2 answers
  • State two functions of windows environment​
    9·1 answer
  • Matt is a senior developer for Cyber Protect, a company that helps secure management information systems. Matt's new task is to
    8·1 answer
  • Function _one(array)
    6·1 answer
  • Zara wants to create some lines of code that are ignored by the computer. What should these lines begin with?
    5·1 answer
  • Guys, please help me asap (Photo Attached) !!!!!!! HELP 25pts!!!!
    14·2 answers
  • Cybersecurity is defined as the set of techniques to protect the secrecy, integrity, and availability of computer systems and da
    7·1 answer
  • At a family reunion, your cousin takes a picture of both of you with her phone, orders a print of it, and mails it to you with a
    5·1 answer
  • What do you mean by computer ethics?​
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!