Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Methods with 1+ parameter- 0 returns (careful with parameter types); Ex: A me

ID: 644093 • Letter: 1

Question

1) Methods with 1+ parameter- 0 returns (careful with parameter types); Ex: A method that prints your first and last name (receive names as parameter) Public static void printName(){ //receives 2 Strings for names // join names together seperated by a space and print name a) A method that prints a title to a song and the 1st 3 lines of lyrics (receive name & lyrics) b) A method that adds two numbers together and prints the result (receive numbers) c) A method that turns feet and inches into just inches (receives feet & inches) 2) Methods with 1+ parameter, 1 returns (careful with parameter var tvoes1; Example: A method that received your first and last name and returns your full name (receive names) Public static String returnName(String fName, String IName){ //receive first and last name as String parameters // joins first and last name with space between and returns the resulting string a) A method that receives 2 numbers and returns the total (receive numbers) b) A method that returns fahrenheit when given celcius (receive celcius as parameter)

Explanation / Answer

Answer:

1)

a. Method to add two numbers together and print the result:

# define a function called addtwo with two parameters
def addtwo(a, b)
a + b; # return a + b
end
print "Please enter number 1 : ";
# get the input from the console,
val1 = gets;
print "Please enter number 2 : ";
val2 = gets;
# convert the string console inputs to_i (to_integers) and add together
print "Answer : " , (val1.to_i + val2.to_i), " ";

b. Method that turn inches and feet to inches:

double sidealength;
int feet, inches;
cout >> " Please enter the length of side a in feet and inches: ";
cin >> feet >> inches;
//user enters 2 4 here//
sidealength = feet * 12 + inches;
cout << sidealength << "inches total. ";

2)

a. Method that receive two numbers and returns the total :

void main()
{
float a,b;
cout<<"Enter 2 Numbers:"<<endl;
cin>>a>>b;
cout<<"total= "<<a+b<<endl;
}

b. Method that returns Fahrenheit when given celcius:

int main()
{
float fahrenheit, celsius;

cout << "Enter the temperature in Celsius : ";
cin >> celsius;
fahrenheit = (celsius * 9.0) / 5.0 + 32;
cout << "The temperature in Celsius : " << celsius << endl;
cout << "The temperature in Fahrenheit : " << fahrenheit << endl;
return 0;
}