a. Write a program that reads two numbers from the keyboard representing, respec
ID: 3722749 • Letter: A
Question
a. Write a program that reads two numbers from the keyboard representing, respectively, an investment and an interest rate (you will expect the user to enter a number such as .065 for the interest rate, representing 6.5% interest rate). Your program should calculate and output (in $ notation) the future value of the investment in 5, 10 and 20 years using the following formula
future value = investment*(1 + interest rate)^year
You will assume that the interest rate is an annual rate and is compounded annually.
b. Write a program that reads a commercial website URL, from the keyboard, you should expect that the URL starts with www. and ends with .com. Retrieve the name of the list and output it. For instance, if the user inputs www.yahoo.com, you should output yahoo.
Explanation / Answer
a:
As you have not mentioned any language, So here I am giving you solution in c++;
Please have a look at very simple code:
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
float investment , interest_rate , future_value;
cout<<"Please enter investment and interest rate(If you have interest rate 4% then enter like .04)"<<endl;
cin>>investment>>interest_rate;
//After 5 years
future_value = investment*pow(1+interest_rate , 5);
cout<<"Future value after 5 years : "<<future_value<<endl;
//After 10 years
future_value = investment*pow(1+interest_rate , 10);
cout<<"Future value after 10 years : "<<future_value<<endl;
//After 15 years
future_value = investment*pow(1+interest_rate , 15);
cout<<"Future value after 15 years : "<<future_value<<endl;
return 0;
}
Iinput:
123
0.68
Output:
Future value after 5 years : 1646.08
Future value after 10 years : 22029.2
Future value after 15 years : 294812
b:
We first find the indexes of first and last occurances of ‘.’ in Url.Then we simply print the string between these two dots.
I have used strchr, that gives first occurance and strrchr gives last occurance.
Have a look at code:
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
char url[100];
cout<<"Please enter a commercial website :"<<endl;
gets(url);
char *p;
int start , end;
//First occurance of '.'
p = strchr(url,'.');
//Starting index
start = p - url +1;
//last occurance of '.'
p = strrchr(url,'.');
//Ending Index
end = p - url;
for(int i = start ; i < end; i++)
cout<<url[i];
cout<<endl;
}
Input: www.yahoo.com
Output: yahoo
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.