answer.
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
s2008m [1.1K]
1 year ago
10

Write a fragment of code that reads in strings from standard input, until end-of-file and prints to standard output the largest

value. You may assume there is at least one value. (cascading/streaming logic, basic string processing)
Computers and Technology
1 answer:
Nady [450]1 year ago
8 0

Answer:

Explanation:

Sample input file: numbers.txt

8 9 7 67 78 45 67 99 1001

Sample Output:

The largest value is:1001

Code to Copy:

// include stdafx, if using visual studio.

#include "stdafx.h"

// declare the necessary header files.

#include <iostream>

#include <string>

#include <fstream>

using namespace std;

// Start the main function

int main()

{

// create the object of ifstream.

ifstream in_file;

// Open the file

in_file.open("numbers.txt");

// Declare the string variable

string str;

// Declare the integer variables.

int maximum = 0;

int num;

// Check whether the file open

if (in_file.is_open())

{

// Traverse the file till the end.

while (!in_file.eof())

{

// traversing the value.

in_file >> str;

// convert the string into integer.

num = stoi(str);

// Check whether value is max or not.

if (maximum < num)

{

// Update the value of maximum.

maximum = num;

}

}

}

// Display the statement on console.

cout << "The largest value is:" << maximum << endl;

// Close the file.

in_file.close();

system("pause");

return 0;

}

You might be interested in
vertical exchanges are typically used only to buy and sell materials required for an organization's support activities ( True or
torisob [31]

Answer:

Vertical exchanges are typically used only to buy and sell materials required for an organization's support activities- False

7 0
1 year ago
Read 2 more answers
Define a function PyramidVolume with double parameters baseLength, baseWidth, and pyramidHeight, that returns as a double the vo
posledela

Answer:

The Program to this question can be given as:

Program:

#include <iostream> //header file.

using namespace std;

double PyramidVolume(double baseLength, double baseWidth, double pyramidHeight)  //define a method PyramidVolume

{

   double baseArea,Volume; //declare variable.

   baseArea= baseLength * baseWidth;  //calculate baseArea

   Volume = ((baseArea * pyramidHeight) * 1/3);  //calculate Volume

   return Volume; //return Volume

}

int main() //define main method.

{

double x,baseLength,baseWidth,pyramidHeight; //define variable.

cout<<"Enter baseLength :"; //message.

cin>>baseLength; //input value.

cout<<"Enter baseWidth :";//message.

cin>>baseWidth;  //input value.

cout<<"Enter pyramidHeight :";//message.

cin>>pyramidHeight;  //input value.

x=PyramidVolume(baseLength,baseWidth,pyramidHeight); //calling

cout << "Volume of given value is :"<<x; //print value.

return 0;

}

Output:

Enter baseLength :1.0

Enter baseWidth :1.0

Enter pyramidHeight :1.0

Volume of given value is :0.333333

Explanation:

The description of the above program can be given as:

  • In the above c++ language program firstly we include the header file. Then we define a function that is " PyramidVolume". The return type of this function is double because it return value and in this function, we pass three-parameter that is baseLength, baseWidth, and pyramidHeight. The data type of this variable is double.
  • In this function, we define two variable that is "baseArea and Volume" that is used for holding the calculated value. The variable baseArea holds the area of the pyramid and the volume variable holds the volume of the pyramid.
  • Then we define a main function. In this function, we define four variables that is "x, baseLength, baseWidth, and pyramidHeight". The baseLength, baseWidth, and pyramidHeight variable are used to take input from the user and pass into the function. The variable x is used to hold the return value of the function and we print this variable.

8 0
2 years ago
Read 2 more answers
A bank in your town updates its customers’ accounts at the end of each month. The bank offers two types of accounts: savings and
Lerok [7]

Answer:

This is your corrected code and the output of each test example. I have also added comments with the provided code to make the code understandable. I have also changed itype variable to from int to String in order to print the account type (Savings or Checking) in output.

import java.util.*;

public class bank{  //class name

public static void main (String [] args)  //start of main function body

{int num,error=1; //declare variables

String itype=" "; //stores Checking or Savings account type

char type =0;  //type variable which is one of savings S or checking C

double min,cur =0,balance =0,rate=0;

//declare variables for minimum balance, current balance, interest rate

Scanner in=new Scanner(System.in);

System.out.println("Enter account number: ");  //prompts user to enter acc no

num=in.nextInt();  //reads input account number

while(error==1) {  

//asks user to enter account type C or S

System.out.println("Enter account type(s-savings or c-checking):");

type=in.next().charAt(0);  //reads the input character of account type

if(type=='c'||type=='C')  //if user inputs c or C

{itype= "Checking";  //set itype to Checking when user input c or C

error=0;  //set value of error to 0 means user entered valid type input

rate=3/100.; }  // Savings accounts receives  3% interest

else if(type=='s'||type=='S')  //if user enters S or s that shows Savings account

{itype= "Savings";  //set itype to Savings when user input s or S

error=0;  //set error to 0 means there is no error

rate=4/100.; }  //Savings accounts receives 4% interest

if(error==1)  //in case of error in giving input

System.out.println("Invalid type-re enter"); }  //asks user to input again

System.out.println("Enter minimum balance: ");  //asks user to enter min bal

min=in.nextDouble();  //reads value of input minimum balance

System.out.println("Enter current balance: ");

// reads value of input current balance

cur=in.nextDouble();

balance = cur;  

if(itype=="Checking") //if the account type is checking

{ if(cur>min+5000) //Checking accounts interest is 5%

{rate=5/100.;

cur=cur+rate*cur; //computes new balance

System.out.printf("New balance: $%.2f\n", cur);} //returns new balance value

/*If a customer’s balance falls below the minimum balance, there is a service charge of $25.00 for checking accounts */

else if(cur<min)

{cur-=25;

System.out.printf("New balance: $%.2f\n", cur);} returns the value of new

}

if(itype=="Savings"){ //if account type is Savings

/*If a customer’s balance falls below the minimum balance, there is a service charge of $10.00 for savings accounts */

if(cur<min)

{cur-=10;

System.out.printf("New balance: $%.2f\n", cur);}

else

//Savings accounts receive 4% interest

{cur=cur+rate*cur;

System.out.printf("New balance: $%.2f\n", cur);}}

/* as the program should output account number, account type, current balance, and new balance so i have commented out the extra print statements below */

//System.out.printf("After interest and fees your balance is = $%.2f\n",cur);

System.out.println("Account Number: " + num);

System.out.println("Account type: " + itype);

System.out.printf("Current balance: $%.2f\n ", balance);  //the result is //displayed up to 2 decimal place .2f   } }

Explanation:

Following is the output of each test example:

46728 S 1000 2700

Account Number: 46728                                            

Account type: Savings                                                                                          

Current balance: $2700.00                                                                                

New balance: $2808.00

87324 C 1500 7689

Account Number: 87324                                                                                      

Account type: Checking                                                                                        

Current balance: $7689.00                                                                                  

New balance: $8073.45

79873 S 1000 800

Account Number: 79873                                                                                    

Account type: Savings                                                                                        

Current balance: $800.00  

New balance: $790

89832 C 2000 3000

Account Number: 89832                                                                                      

Account type: Checking                                                                                        

Current balance: $3000.00                                                                                  

New balance: $3090.00

98322 C 1000 750  

Account Number: 98322

Account Type: Checking  

Current balance: $1000.00

New Balance: $725.00

7 0
2 years ago
Which method allows a computer to react accordingly when it requests data from a server and the server takes too long to respond
Rina8888 [55]

Answer:

A. Request timeout.

Explanation:

The end devices like the computer systems in a network seeks to share resources with one another and/ or request resources from central server.

With this, there are two ways computers in a network can communicate. They are peer to peer network communication and client-server network communication.

The client-server communication requires a dedicated central server where computers in the network require data. Peer to peer describes a network where computers serve as both client and server to each other.

Request timeout is a message sent to a source when the time to live period (TTL) of a packet expires.

6 0
1 year ago
You would use the _______ conditional formatting options when analyzing a worksheet in which you want to highlight the highest o
nirvana33 [79]

Answer:

Top/bottom conditional formatting

Explanation:

The top/bottom conditional formatting automatically carries out the task of finding the highest, lowest and even average values.

Conditional formatting formatting gives one the opportunity to enhance reports and dashboards as they work on excel.

You use the too/bottom formatting to highlight cells whose values of highest in a dataset and lowest in a dataset

4 0
1 year ago
Other questions:
  • python Consider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8". Any value that is the same as the immediately preceding value i
    7·1 answer
  • Copy the 10 statements as they appear below into your journal.
    6·2 answers
  • Which of the following is an Internet supervisory protocol? O DNS IP O both A and B O neither A nor B
    12·1 answer
  • If you are viewing a webpage with customized or regenerated content, such as updated stock quotes, what type of webpage are you
    5·1 answer
  • Insert the missing code in the following code fragment. This fragment is intended to call the Vehicle class's method. public cla
    14·1 answer
  • Alex is nearing graduation. His counselor showed him this information. Alex's College Costs &amp; Payment Options per Year Costs
    5·2 answers
  • What is the Gain (dB) of a transmission if the Maximum Data Rate is 1 Gbps and the Bandwidth =7000 MHz? Group of answer choices
    6·1 answer
  • If byte stuffing is used to transmit Data, what is the byte sequence of the frame (including framing characters)? Format answer
    6·1 answer
  • How does Accenture help companies harness the power of data to achieve optimal business outcomes?
    9·2 answers
  • In a particular field, there are trees in a l single row from left to right. Each tree has a value V You cut trees from left to
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!