Answer:
Revisiting "Build a Tower"
Recall in the last section how we made Karel make a tower of tennis balls. We told Karel to move() and turnLeft() and putBall() until we had a tower. At the end of the program, Karel was still at the top of the tower, like as in the picture below.
Stuck at top
Suppose that now we want Karel to come back down from the top of the tower. The first thing we need to do is get Karel facing in the right direction. One way to do this is to tell Karel
turnLeft();
turnLeft();
turnLeft();
And then tell Karel to
move();
move();
move();
back to the bottom of the tower.
However, telling Karel to turnLeft() three times is not very readable. That's a lot of writing when all we really want is to tell Karel to "turn right."
Explanation:
Hopefully it would help.
Answer:
import java.util.Scanner; public class Salesman2 {
public static void main(String[] args) { // TODO Auto-generated method stub double CommissionRate;
double TotalSales, Commission;
Scanner Read = new Scanner (System.in); System.out.println("Please enter total sales "); TotalSales=Read.nextDouble();
if (TotalSales<500)
CommissionRate=0.0;
else if (TotalSales>=500 && TotalSales <1000) CommissionRate=0.05;
else
CommissionRate=0.08;}
Commission = CommissionRate * TotalSales;
System.out.println("The Commision is: "+ Commission); }
}
}
Answer:
Check the explanation
Explanation:
#include <bits/stdc++.h>
using namespace std;
class Rectangle{
public:
int length;
int breadth;
Rectangle(int l,int b){
length = l;
breadth = b;
}
int area(){
return length*breadth;
}
int perimeter(){
return 2*(length+breadth);
}
bool equals(Rectangle* r){
// They have the exact same length and width.
if (r->length == length && r->breadth == breadth)
return true;
// They have the same area
if (r->area() == area())
return true;
// They have the same perimeter
if (r->perimeter() == perimeter())
return true;
// They have the same shape-that is, they are similar.
if (r->length/length == r->breadth/breadth)
return true;
return false;
}
};
int main(){
Rectangle *r_1 = new Rectangle(6,3);
Rectangle *r_2 = new Rectangle(3,6);
cout << r_1->equals(r_2) << endl;
return 0;
}
Answer:
Let the function be Node* ins(Node *root,int k)
if root node is NULL then return new node with data equal to k.
If the k <root->data
root->left=ins(root->left,k);
else if k >root->data
root->right =ins(root->right,k);
At last return root.
Explanation:
Node is always inserted at the at the leaf node.We will search k in the tree if we hit a the leaf node the new node is inserted as the child of the leaf node.
,I don't know you all about computer