Answer:
// program in C++.
#include <bits/stdc++.h>
using namespace std;
// function to calculate Distance
void CalcPrintDistance(double velo,double mint)
{
// calculate Distance traveled
double dist=(velo*mint)/60;
// print the Distance
cout<<fixed<<setprecision(2)<<"Distance traveled by vehicle is:"<< dist<<" miles"<<endl;
}
// driver function
int main() {
// variables
double speed,trv_time;
cout<<"Enter the velocity (miles per hour):";
// read speed of the vehicle
cin>>speed;
cout<<"Enter the time traveled(in minutes):";
// read the time traveled
cin>>trv_time;
// call the function
CalcPrintDistance(speed,trv_time);
return 0;
}
Explanation:
Read the velocity of vehicle and assign it to variable "speed".Read the time traveled by the vehicle and assign it to variable "trv_time".Call the function CalcPrintDistance() with parameter "speed" and "trv_time".This function will calculate the distance traveled and print it.
Output:
Enter the velocity (miles per hour):68.2
Enter the time traveled(in minutes):34.6
Distance traveled by vehicle is:39.33 miles
Answer:
It is definitely not used for locating the options in the menu. its the new feature available which is available from the Tell Me text box which you can find immediately right of the very last cmd tab which is above the ribbon. And as you add any help topic to this into textbox, the excel shows all Excel command list , command which are related to the help topic in a drop down.
Explanation:
The answer is self explanatory.
Answer:
The code to this question can be given as:
code:
if(a == 0) //check condition (a is equal to 0 )
{
System.out.print("no solution for a=0");
}
Explanation:
As we know that a method is already given. That takes three parameters from the user and its data type is double. In this, we will check that if the value of a is equal to 0 then it will print no solution for a. To check this condition we used the if block because this block executes true condition only. The syntax for if block can be given as:
Syntax:
if(condition)
{
//code to be executed.
}
In the above syntax if we will pass the value that is given in the code part. So it will give the correct output.
Answer:
- public class Main {
- public static void main(String[] args) {
- System.out.println(firstDigit(1729));
- System.out.println(lastDigit(1729));
- System.out.println(digits(1729));
- }
-
- public static int firstDigit(int n){
- String n_str = Integer.toString(n);
- char firstChar = n_str.charAt(0);
- String firstDigit = Character.toString(firstChar);
- return Integer.parseInt(firstDigit);
- }
-
- public static int lastDigit(int n){
- String n_str = Integer.toString(n);
- char lastChar = n_str.charAt(n_str.length() - 1);
- String lastDigit = Character.toString(lastChar);
- return Integer.parseInt(lastDigit);
- }
-
- public static int digits(int n){
- String n_str = Integer.toString(n);
- return n_str.length();
- }
- }
Explanation:
Firstly we create a method firstDigit that will return the first digit of the input number (Line 8 - 13). This method will convert the input number, n, to string using Integer toString method (Line 9) and assign it to n_stry variable. Next, use charAt method with 0 index to get the first character from n_str and assign it to firstChar variable (Line 10). Next, use Character toString method to convert the firstChar to string type (Line 11) because the parseInt method which is used in Line 12 will only work on String type but not char type. The function return the firstDigit with integer type (Line 12). The parseInt method has converted the string type firstDigit to integer.
The logical steps defined for lastDigit method are similar to firstDigit except that we need to use .length() method to get the length of the digit string and calculate the last index to get the last digit (Line 17).
The digits method (Line 22 -25) will convert the input number to string and then use .length() method to return the length of the number string which is equivalent of number of digit as output.