Answer:
//check which string is greater
if(strcmp(name1,name2)>0)
//assign name1 to first, if the
//name1 is greater than name2
first=name1;
else
//assign name2 to first, if the
//name2 is greater than name1
first=name2;
5)
//compare name1 and name2
if(strcmp(name1,name2)>0)
//compare name1 and name3
if(strcmp(name1,name3)>0)
//assign name1 to max, becuase
//name1 is greater than name2 and name3
max=name1;
Explanation:
Answer:
The complete Matlab code along with step by step explanation is provided below.
Matlab Code:
function Req=ParallelR(Number)
Number=input('Please enter the number of resistors: ');
if Number>10 | Number<=0
disp('Invalid input')
return
end
R=0;
for i=1:Number
r=input('Please enter the value of resistor: ');
R=R+1/r;
end
Req=1/R;
end
Explanation:
Parallel resistance is given by
First we get the input from the user for how many parallel resistors he want to calculate the resistance.
Then we check whether the user has entered correct number of resistors or not that is from 1 to 10 inclusive.
Then we run a for loop to get the resistance values of individual resistors.
Then we calculated the parallel resistance and keep on adding the resistance for N number of resistors.
Output:
Test 1:
Please enter the number of resistors: 3
Please enter the value of resistor: 10
Please enter the value of resistor: 20
Please enter the value of resistor: 30
ans = 60/11
Test 2:
Please enter the number of resistors: 11
Invalid input
Test 3:
Please enter the number of resistors: 0
Invalid input
Answer:
All are True
Explanation:
a. A constructor must have the same name as that of a class. For example
public class MyFirstClass{ // this is the class name
public MyFirstClass() } // the constructor having the same name as class.
b. Constructors never have a return type not even void because it is only used to initialize the values of data members of the class when the object of the class is created so constructors are not directly called hence they do not need to have a return type.
c. Constructors are invoked using the new operator.
When the new object is created the constructor is invoked in order to initialize the variables of a class. The memory is allocated to the object and then the constructive is invoked for the purpose to initialize the object.