Define a function ComputeGasVolume that returns the volume of a gas given parameters pressure, temperature, and moles. Use the gas equation PV = nRT, where P is pressure in Pascals, V is volume in cubic meters, n is number of moles, R is the gas constant 8.3144621 ( J / (mol*K)), and T is temperature in Kelvin.Sample program:#include const double GAS_CONST = 8.3144621;int main(void) { double gasPressure = 0.0; double gasMoles = 0.0; double gasTemperature = 0.0; double gasVolume = 0.0; gasPressure = 100; gasMoles = 1 ; gasTemperature = 273; gasVolume = ComputeGasVolume(gasPressure, gasTemperature, gasMoles); printf("Gas volume: %lf m^3\n", gasVolume); return 0;}

Answers

Answer 1

Answer:

double ComputeGasVolume(double pressure, double temperature, double moles){

   double volume = moles*GAS_CONST*temperature/pressure;

    return volume;        

}

Explanation:

You may insert this function just before your main function.

Create a function called ComputeGasVolume that takes three parameters, pressure, temperature, and moles

Using the given formula, PV = nRT, calculate the volume (V = nRT/P), and return it.


Related Questions

4. Discuss the advantages and disadvantages of using the same system call interface for both files and devices. Why do you think operating system designers would use the same interface for both

Answers

Answer:

According to the principles of design, Repetition refers to the recurrence of elements of the design

One of the advantages of this is that it affords uniformity. Another is that it keeps the user of such a system familiar or with the interface of the operating system.

One major drawback of this principle especially as used in the question is that it creates a familiar route for hackers.

Another drawback is that creates what is called "repetition blindness". This normally occurs with perceptual identification tasks.

The  phenomenon may be  due to a failure in sensory analysis to process the same shape, figures or objects.

Cheers!

Modify the DemoSalesperson application so each Salesperson has a successive ID number from 111 through 120 and a sales value that ranges from $25,000 to $70,000, increasing by $5,000 for each successive Salesperson. Save the file as DemoSalesperson2.java.

Answers

Answer:

Here is the modified DemoSalesperson2

public class DemoSalesperson2{ // class DemoSalesperson2

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

SalesPerson[] sp = new SalesPerson[10]; // creates an array of SalesPerson object named sp

int start_id =111; // assign 111 to starting id number

double start_sal=25000; //assign 25000 to starting salary means salary will start from amount 25000

 for (int i =0; i<sp.length; i++) { //loop iterates until the value of loop variable i remains less then length of the array object sp

  sp[i] =new SalesPerson(start_id+i,start_sal+5000*(i)); /*at each iteration  ID number from 111 through 120 and a sales value that ranges from $25,000 to $70,000, increasing by $5,000 for each successive is displayed using object array sp[] which calls the SalesPerson constructor to access id and sales */

 System.out.println(sp[i].getId()+"   "+sp[i].getAnnualSales() );  } } } /*uses object sp of class SalesPerson to access the methods getId which returns the id and getAnnualSales method which returns the annual sales, to display id and annual sales */

Explanation:

The question first requires a SalesPerson class with these requisites:

Class name: Salesperson.

Data fields for Salesperson: int ID number , double annual sales amount.

Methods: constructor SalesPerson() that requires values for both data fields, as well as get and set methods for each of the data fields.

So according to the complete question's requirement, I have implemented SalesPerson class:

public class SalesPerson {   // class name

//data members: integer type id variable and double type sales variable

   private int id;  

   private double sales;  

   public SalesPerson(int id_no, double annual_sales) {   //constructor that requires values for id and sales

       id = id_no;  

       sales = annual_sales;     }  

   public int getId() {   //accessor getId() method to get or access the value of id data field

       return id;     }  

   public void setId(int id_no) {   //mutator setId to set the value of id data field

       id = id_no;     }  

   public double getAnnualSales() {   //accessor getAnnualSales() method to get or access the value of sales data field

       return sales;     }  

   public void setAnnualSales(double annual_sales) { //mutator setAnnualSales to set the value of sales data field

       sales = annual_sales;     }  }

However you can use my DemoSalesperson2 application for your own SalesPerson class.

Now I will explain the working of for loop used in DemoSalesperson2

Iteration 1:

i=0

i<sp.length is true because length of sp[] is 10 so i<10

This means the body of for loop will execute.

The statement inside the body of for loop is :

 sp[i] =new SalesPerson(start_id+i,start_sal+5000*(i));

class SalesPerson constructor is used to access the data members of SalesPerson class

start_id = 111

start_sal=25000

start_id+i = 111 + 0 = 111

start_sal+5000*(i) = 25000 + 5000 (0) = 25000

The values 111 and 25000 are stored to sp[0] means at the first index of the sp array.

System.out.println(sp[i].getId()+"   "+sp[i].getAnnualSales() );  

This statement uses sp object to get access to the getId and getAnnualSales methods to print the id number and sales amount.

So the output at 1st iteration is:

111   25000.0

Iteration 1:

The value of i is incremented to 1 so now i = 1

i<sp.length is true because length of sp[] is 10 so i<10

This means the body of for loop will execute.

The statement inside the body of for loop is :

 sp[i] =new SalesPerson(start_id+i,start_sal+5000*(i));

class SalesPerson constructor is used to access the data members of SalesPerson class

start_id = 111

start_sal=25000

start_id+i = 111 + 1 = 112

start_sal+5000*(i) = 25000 + 5000 (1) = 25000 + 5000 = 30000

The values 111 and 25000 are stored to sp[1] means at the first index of the sp array.

System.out.println(sp[i].getId()+"   "+sp[i].getAnnualSales() );  

This statement uses sp object to get access to the getId and getAnnualSales methods to print the id number and sales amount.

So the output at 1st iteration is:

112   30000.0

The loop keeps iterating and the value of id is incremented by 1 and value of sales is increased by 5000 at every iteration.

This loop continues to execute until the value of i exceeds the length of sp array i.e. 10.

The values from iteration 1 to 8 following the above explanation are:

Iteration 1:

111    25000.0

Iteration 2:

112    30000.0

Iteration 3:

113    35000.0

Iteration 4:

114   40000.0  

Iteration 5:

115   45000.0  

Iteration 6:

116   50000.0                                                          

Iteration 7:

117   55000.0                                                                                                      

Iteration 8:                                                                                      

118   60000.0      

Iteration 9:                                                                                    

119   65000.0

Iteration 10:                                                                                    

120   70000.0

At iteration 11 the for loop body will not execute as value of i at 11th iteration is i = 10 and i<sp.length evaluates to false as i = sp.length because length of sp array is 10 and now the value of i is also 10. So the loop ends. Screenshot of the program and its output is attached.

Write a sentinel-controlled while loop that accumulates a set of integer test scores input by the user until negative 99 is entered.

Answers

Answer:

Here is the sentinel-controlled while loop:

#include <iostream> //to use input output functions

using namespace std; // to identify objects like cin cout

int main(){ // start of main() function body

int test_score; // declare an integer variable for test scores

//prompts user to enter test scores and type-99 to stop entering scores

cout << "Enter the test scores (enter -99 to stop): ";

cin >> test_score; // reads test scores from user

while (test_score != -99){ // while loop keeps executing until user enters -99

cin >> test_score; } } // keeps taking and reading test scores from user

Explanation:

while loop in the above chunk of code keeps taking input scores from user until -99 is entered. Sentinel-controlled loops keep repeating until a sentinel value is entered. This sentinel value indicates the end of the data entry such as here the sentinel value is -99 which stops the while loop from iterating and taking the test score input from user.

The complete question is that the code should then report how many scores were  entered and the average of these scores. Do not count the end sentinel -99 as a score.

So the program that takes input scores and computes the number of scores entered and average of these scores is given below.

#include <iostream>  // to use input output functions

using namespace std;  // to identify objects like cin cout

int main(){  //start of main function body

double sum = 0.0;  // declares sum variable to hold the sum of test scores

int test_score,count =0;  

/* declares test_scores variable to hold the test scores entered by user and count variable to count how many test scores input by user */

cout << "Enter the test scores (or -99 to stop: ";

//prompts user to enter test scores and type-99 to stop entering scores

cin >> test_score;  // reads test scores from user

while (test_score != -99){  // while loop keeps executing until user enters -99

count++;  /* increments count variable each time a test cores is input by user to count the number of times user entered test scores */

sum = sum + test_score;  // adds the test scores

cin >> test_score;}  // reads test scores from user

if (count == 0)  // if user enters no test score displays the following message

cout << "No score entered by the user" << endl;

else  //if user enters test scores

//displays the numbers of times test scores are entered by user

cout<<"The number of test scores entered: "<<count;

/* displays average of test scores by dividing the sum of input test scores with the total number of input test scores */

cout << "\n The average of " << count << " test scores: " <<sum / count << endl;}

The program along with its output is attached.

k- Add the code to define a variable of type 'double', with the name 'cuboidVolume'. Calculate the volume of the cuboid and set this variable value.

Answers

Answer:

Here is the JAVA program to calculate volume of cuboid:

import java.util.Scanner; // Scanner class is used to take input from user

public class CuboidVol { // class to calculate volume of cuboid

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

Scanner input= new Scanner(System.in); //create Scanner class object

// prompts user to enter length of cuboid

System.out.println("Enter the cuboid length:");

double length=input.nextDouble(); //reads the input length value from user

// prompts user to enter width of cuboid

System.out.println("Enter the cuboid width:");

double width=input.nextDouble(); //reads the input width from user

// prompts user to enter height of cuboid

System.out.println("Enter the cuboid height:");

double height=input.nextDouble(); //reads the input height from user

/* the following formula is to calculate volume of a cuboid by multiplying its length width and height and a double type variable cuboidVolume is defined to store the value of the resultant volume to it */

double  cuboidVolume= length*width*height; //calculates cuboid volume

//displays volume of cuboid and result is displayed up to 2 decimal places

System.out.printf("Volume of the cuboid (length " + length + "/ height " + height + "/ width" +width +" is: " + "%.2f",cuboidVolume);   } }

Explanation:

The formula for the volume of a cuboid is as following:

Volume = Length × Width ×  Height

So in order to calculate the volume of cuboid three variable are required for length, width and height and one more variable cuboidVolume to hold the resultant volume of the cuboid.

The program is well explained in the comments added to each statement of the program. The program prompts the user to enter the value of height width and length of cuboid and the nextDouble() method is used to take the double type input values of height length and width. Then the program declares a double type variable cuboidVolume to hold the result of the volume of cuboid. Then the last printf statement is used to display the volume of cuboid in the format format "Volume of the cuboid (length  / height  / width ) is" and the result is displayed up to 2 decimal places.

The screenshot of the program along with its output is attached.

Other Questions
Find the length of UC based on the passage and what u have learned in the lesson, write three to four sentences explaining whether dipping letters in vinegar to prevent the spread of yellow fever was a good conclusion What is an incumbent? 1) A grocer sold 5 kg of wheat flour at Rs 30 per kg and gained 20%. If he had soldit at Rs 27 per kg, what would be his gain or loss percent? A survey was taken of students in math classes to findout how many hours per day students spend on socialmedia. The survey results for the first-, second-, andthird-period classes are as follows:First period: 2, 4, 3, 1, 0, 2, 1, 3, 1, 4, 9, 2, 4, 3,0Second period: 3, 2, 3, 1, 3, 4, 2, 4, 3, 1, 0, 2, 3, 1, 2Third period: 4, 5, 3, 4, 2, 3, 4, 1, 8, 2, 3, 1, 0, 2, 1, 3Which is the best measure of center for second periodand why? help me solve this please expand the linear expression 4(10x -4) At the Arctic weather station, a warning light turns on if the outside temperature is below -25 degrees Fahrenheit. Which inequality models this situation? Please please please please help me. i will do anything, anything!! please what is a other name for the set of all x-values Suppose Stark Ltd. just issued a dividend of $2.33 per share on its common stock. The company paid dividends of $2.00, $2.08, $2.15, and $2.26 per share in the last four years. If the stock currently sells for $55, what is your best estimate of the company's cost of equity capital using the arithmetic average growth rate in dividends?What if you use the geometric average growth rate? Based on this passage, which statements are true about air bags? Check all that apply.A driver who is not wearing a seat belt may be injured by an air bag.Air bags protect front-seat occupants in head-on crashes.Air bags expand slowly from the steering wheel or dashboard.Air bags are most effective when passengers sit as close to the dashboard as possible.Air bags are meant to work with seat belts, not to replace them. How many multiples of 4, that are smaller than 1,000, do not contain any of the digits 6, 7, 8, 9 or 0? PLEASE HELP!!Which is an example of plagiarism? Select three options.Abdul has paraphrased the text.Amy has quoted the writer and included the source.Ron has copied the quote but changed the verb tense.Henry has copied the quote over from a textbookStephen has paraphrased the idea and included the source in the reference list. when a 0.622kg basketbll hits the floor its velocit changes from 4.23m/s down to 3.85m/s up. if the averge force was 72.9N how much time was it in contact with the floor? I will mark brainiest if correct Let f(x)=5x7 and g(x)=x+3. Find f(g(x)) and g(f(x)). Gerard, a job applicant, was asked to appear for an interview by an organization. Gerard spent the first 15 minutes of the job interview relating details about his education and work experience to the interviewer. This is a _____ interview. Consider preparing ammonia gas by the following reaction:N2(g) + 3H2(g)===>2NH3(g)If you have 28.02 g of N2 and excess H2, how many grams of NH3(g) can be produced.6.06 g14.01 g34.08 g68.16 g28.02 g helpppDetermine the x-intercept of the line whose equation is given:y = StartFraction x Over 2 EndFraction minus 3a.(6, 0)b.(negative 6, 0)c.(0, three-halves)d.(Negative three-halves, 0) What two examples of patterns and repetition?