Answer:
The code is given using Python
Explanation:
#datetime to be import
from datetime import datetime
#function convert_format to convert_format date to particular format
def convert_format():
#take date from user input
inputDate = input('Enter a date(mm/dd/yyyy): ')
#using datetime convert to format month day year
dateObject = datetime.strptime(inputDate, '%m/%d/%Y')
#print the date
print(dateObject.strftime('%B %d, %Y'))
#function call
convert_format()
Answer:
// here is code in java.
import java.util.*;
class Solution
{
// main method of class
public static void main (String[] args) throws java.lang.Exception
{
try{
// declare variable
double caffeine;
// scanner object to read input from user
Scanner scr=new Scanner(System.in);
System.out.print("Enter the initial amount of caffeine:");
// read the initial amount of caffeine
caffeine=scr.nextDouble();
// calculate amount of caffeine after 6,12,18 hours
for(int i=1;i<=3;i++)
{
System.out.println("After "+ i*6+" hours:"+(caffeine/2)+" mg");
// update the caffeine after every 6 hours
caffeine=caffeine/2;
}
}catch(Exception ex){
return;}
}
}
Explanation:
Create a variable "caffeine" to store the initial amount of caffeine given by user. Run a loop for three time, it will calculate the amount of caffeine left after every 6 hours.First it will give the amount of caffeine left after 6 hours, then caffeine left after 12 hours and in last caffeine after 18 hours.
Output:
Enter the initial amount of caffeine:100
After6 hours:50.0 mg
After12 hours:25.0 mg
After18 hours:12.5 mg
Answer:
b) f2.i is 1 f2.s is 2
Explanation:
i is an instance variable and s is static, shared by all objects of the Foo class.
Answer:
Function signature can be defined as a combined term used to refer to the function name, function return type, no of arguments , type of arguments.
Explanation:
The signature of function is seen as a combined term used to refer to the function name, function return type, number of arguments , type of arguments.
When overloaded functions is been defined, they are different in numbet of arguments or type of argument passed.
To understand this better refer to the program code below.
C++ code.
#include <iostream>
using namespace std;
int multiply(int a, int b)
{
cout << a*b <<endl;
return 0;
}
int multiply(int a, int b, int c)
{
cout << a*b*c <<endl;
return 0;
}
int main()
{
//function with two arguments passed
multiply(3, 50);
//function with three arguments passed . It is different in number of arguments passed. Thus here function signature is different
multiply(4, 20, 10);
}