Professional Documents
Culture Documents
program 1
Create a program that calculates the volume of a triangular prism
and the area of a cross- section of the same prism. Your program
should ask the user to enter the length of the prism and the height
and base of the triangular cross-section of the prism. Ourput your
results using printf() instead of cout.
program 2 When you borrow money to buy a house, a car, or for some other purposes, then
you typically repay it by making periodic payments. Suppose that the loan amount
is L, r is the interest rate per year, m is the number of payments in a year, and the
loan is for t years. Suppose that i = (r / m) and r is in decimal. Then the periodic
payment is:
You can also calculate the unpaid loan balance after making certain payments. For
example, the unpaid balance after making k payments is:
where R is the periodic payment. (Note that if the payments are monthly, then m =
12.) Write a program that prompts the user to input the values of L, r, m, t, and k.
The program then outputs the appropriate values. Your program must contain at
least two functions, with appropriate parameters, to calculate the periodic
payments and the unpaid balance after certain payments. Make the program
menu driven and use a loop so that the user can repeat the program for different
values.
program 3 Design and implement a class dayType that implements the day of the week in a
program. The class dayType should store the day, such as Sun for Sunday. The
program should be able to perform the following operations on an object of type
dayType:
Set the day.
Print the day.
Return the day.
Return the next day.
Return the previous day.
Calculate and return the day by adding certain days to the current day. For example,
if the current day is Monday and we add 4 days, the day to be returned is Friday.
Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday.
Add the appropriate constructors.
Program 5 Write a program that converts a number entered in Roman numerals to decimal.
Your program should consist of a class, say, romanType. An object of type
romanType should do the following:
Store the number as a Roman numeral.
Convert and store the number into decimal form.
Print the number as a Roman numeral or decimal number as requested by the user.
The decimal values of the Roman numerals are:
M 1000
D 500
C 100
L 50
X 10
V 5
I 1
Test your program using the following Roman numerals: MCXIV, CCCLIX,
MDCLXVI.
return -1;
}
int romanToDecimal(string& str)
{
int res = 0;
for (int i = 0; i < str.length(); i++)
{
int s1 = value(str[i]);
if (i + 1 < str.length())
{
int s2 = value(str[i + 1]);
if (s1 >= s2)
{
res = res + s1;
}
else
{
res = res + s2 - s1;
i++;
}
}
else
{
res = res + s1;
}
}
return res;
}
int main()
{
string str;
bool i;
cout<<"Enter the Roman Numeral : ";
cin>>str;
cout<<"0 for roman number "
<<"and 1 for integer form : ";
cin>>i;
if(i == 1)
{
cout << "Integer form of Roman Numeral is "
<< romanToDecimal(str);
}
else
{
cout << "Roman Number you entered is : "
<< str;
}
return 0;
}
output