C++ Problems - 2.00 paypal cash per problem

All forums need a place for all the posts for people in the community to rant about things not relating to what the forum is about. This is that forum.

Moderator: MacroQuest Developers

Unfetered

C++ Problems - 2.00 paypal cash per problem

Post by Unfetered » Mon Apr 26, 2004 8:32 pm

I have a couple problems I have to crank out, and I, not being the quickest writer of C++ am probaly not going to get them done in the next 2 hours. If someone can write C++ well write out these problems, state the e-mail address you want 3.00 per problem sent to and post it here. First submitted gets the cash, and answers to the same problem will not be valid for cash. This is good till 8:00pm pst Monday April 26th.

Thanks Much

Here are the descriptions:

1. Create a C++ program to display the ASCII character set from 32 to 255. Show the decimal value, the character equivalent and the hex and octal values. Your output should look similar to the following:

Dec Char Hex Oct
==============
32 20 40
33 ! 21 41
34 " 22 42
35 # 23 43
36 $ 24 44

and so on till 55

2. Write a C++ program that forces an overflow condition of a short integer variable on your computer. Keep in mind that some compilers and computer combinations use 1-byte short integers while others use 2-byte integers. You need to determine the size of a short integer on your machine. Document your code with plenty of C++ comments.

3. Write a C++ program that prints a pattern similar to the following pattern. Start at 1 and end with 26, however. The middle row os asterisks should be 26 document your code with comments.

*
**
***
****
*****
******
*******
********
*******
******
*****
****
***
**
*

4. Write a C++ program that loops and prints a table of simple interest calculations. Prompt the user for the principal (p), interest rate (r) and time (t) in years. Use a loop from 1 to years and calculate interest rate compounded annually for the years selected. Hint: i=prt is the simple interest formula, where time(t) is held to 1 year foe each iteration. Hence, the output should look very close to the following: (Do not worry about commas and dollar signs in the output)

Enter original deposit amount: 50000
Enter annual interest rate (10% as 10): 7
Enter years to save this deposit amount: 18

Year Rate Amount Interest New Amt
================================
1 0.07 50000.00 3500.00 53500.00
2 0.07 53500.00 3745.00 57245.00
3 0.07 57245.00 4007.15 61252.15
4 0.07 61252.15 4287.65 65539.80
5 0.07 65539.80 4587.79 70127.59
6 0.07 70127.59 4908.93 75036.52
7
8
9
10
11
12
13
14
15
16
17
18

Interest gained over 18 years is 118996.61
Mean interest per year is 6610.92

Show the total interest paid for the life of the loan and show the average interest gained per year.



5. Write a C++ program that computes the factorial of a number that is input from the keyboard. A factorial is the product of all the numbers up to the number entered. For example, 6-factorial is 720 because 6*5*4*3*2*1 is 720. Six-factorial is written "6!" Prompt the user for the numeric input. Keep prompting for values until a zero value is entered. Document your code with plenty of comments.

Unfetered

Post by Unfetered » Mon Apr 26, 2004 8:35 pm

I Incorrectly stated 2.00 in the topic of this post, 3.00 per completed problem is what I am paying

smelly wang
a lesser mummy
a lesser mummy
Posts: 54
Joined: Mon Jan 19, 2004 6:04 pm

Post by smelly wang » Mon Apr 26, 2004 9:25 pm

Code: Select all

#include <stdio.h>
#include <iostream>
using namespace std;

void main() {
	// first one
	unsigned char tmp; for (tmp=32;tmp<255;tmp++) { printf("%d %c %x %o\n",tmp,tmp,tmp,tmp); }

	// third one
	for (int i=0;i<26;i++) {
		for (int j=0;j<i;j++) {
			printf("*");
		}
		printf("\n");
	}
	for (int i=26;i>0;i--) {
		for (int j=0;j<i;j++) {
			printf("*");
		}
		printf("\n");
	}

	// 5th one
	int num;
	int out;
	cin >> num;
	out = num;
	for (int i=num-1;i>0;i--) {
		out*=i;
	}
	printf("%d\n",out);

	// 4th one

	float orig = 0;
	float interest = 0;
	float newamt = 0;
	float rate = 0;
	float years = 0;
	float avg = 0;

	printf("Enter original deposit: ");
	cin >> orig;
	printf("Enter interest rate: ");
	cin >> rate;
	printf("Enter years: ");
	cin >> years;

	rate/=100;
	newamt = orig;
	for (int i=0;i<years;i++) {
		interest = orig*rate;
		newamt=orig+interest;
		printf("%d\t%3.2f\t%3.2f\t%3.2f\n",i,orig,interest,newamt);
		avg+=interest;
		orig=newamt;
	}
	printf("Mean interest: %3.2f\n",avg/years);
	printf("Interest gained over %3.0f years: %3.2f\n",years,avg);
}