program help

I am in grade 10 and in a computer science class, I am having a lot of troble understanding the C++ materal. these are my current assignments that I don't understand any help would be appresiated.(you may notice some wierd jokes, my teachers a bit odd)

) You are to write a function called power that uses two positive, int global variables: the base and the exponent. This function should return the answer of base raised to the power of exponent. For example, when base is 2 and exponent is 3, power() should return 8, and when base is 1 and exponent is 10, power() should return 1. In order to test your function, your main program should have two sections: The first should be a loop that executes 3 times, each time asking you for a power and a base and then printing out the result each time. The second part of your program should then ask the person for 2 sets of base/exponents, and then calculating the value of the expression

Base1Power1 + Base2Power2

2) Youre a real Card - You should be Dealt with! Write a C++ program that generates and prints a random card. To do this, you will call three functions: function get_card will return what the card is (a number from 1-13 that represents a card from 2, 3, 4,....10, Jack, Queen, King, or Ace) , function get_suit will return the suit (a number from 1-4 that represents Hearts, Spades, Clubs, or Diamonds!), and function printcard will use 2 global variables: card and suit, and then print out a nice-looking card! Write a program that generates and prints 3 cards! And because I am such a caring person, Im going to write the main program for you - YOU DO NOT NEED TO ADD ANYTHING TO THIS PART - only write the functions and add comments!! The mainline of this program is:
{int cardnum; /* include seed and i here, too! */
/* insert your 4 lines of random number code here! */
for (cardnum=1; cardnum <= 3; cardnum++)
{card = get_card();
suit = get_suit();

3) A Fun Number is one where all the factors of a number (other than the number itself) add up to the number. For example, 6 is a Fun number, since 6 = 1 + 2 + 3, but 8 is not a fun number, since 8  1 + 2 + 4. You are to write a function that looks as follows:
int is_fun_number() which will return a 1 if the number is a fun number or a 0 if the number is not a fun number. To do this, you will need a global variable, number.(The logic will be very similar to the Prime Program, except instead of keeping track of how many factors, you will need to keep a sum of the factors - Hint, Hint, Hint, Hint, Hint!) To test your function, your mainline should have two sections: first, in a loop that executes 3 times, ask the user to enter a number and then print whether or not each number entered is a fun number or not. Second, write a loop that tests all numbers between 2 and 100 000 and only prints out those numbers that are fun numbers! You can see why theyre called fun, eh?!

4)Forget gambling - its time for the DAKOTA BASKETBALL SIMULATOR!! The game will work the following way: For each quarter, each team will get the ball 15 times. Each time the team gets the ball, they can score either 0 points, 1 point, 2 points, or 3 points (This will basically be a randomly generated value from 0 through 3). After each teams turn, the scoreboard will be updated. As well, there will be an option given to the user at the beginning of the game: either they will play Scoreboard Only - where the only output is the scoreboard, or they will play Full Play-By-Play, which will print out each play as it happens (see in-class discussion for the difference!) To write this program, you will need int global variables playbyplay, Team1Score, and Team2Score, and several functions, such as:
int Team1Result();
int Team2Result();
void PrintScoreboard();
At the end of the game, you should print a message indicating which team won (assume there wont be a tie - unless you want to write more code to deal with it!)

5) Lets face it - basketball is fun, but you folks live for Math! Your mainline should begin by asking how many numbers will be entered, and then for each number, the following data should be printed:
1) Whether the number is prime or composite
2) Whether its a fun number or not (you get to steal from your own program above!)
3) Whether or not the number is a perfect square
4) Whether or not the number is a perfect cube
5) What the sum of the digits of the number is (for example the sum of 24 = 6 (2+4)) - note that your numbers will have different numbers of digits - you may assume the largest number will be 9999, though.
Of course, since this is the FUNctions assignment, you will need to write a separate function to find each of the 5 answers listed above! (Its questions like this that really do put the FUN in functions!)

6) A written one (for once)!!! Global Warming and Local Variables. Given the program:
int a;
int main()
{int a,b;
char x;
float c;...(Body of main)
float func_test();
{int b;
float d;....(Body of func_test);

A) Construct a chart showing each separate variable, whether it is local or global, and its scope (where it can be seen)
B) True / False Questions - If False, explain why!!
1) c = 2.3; would be ok in the body of func_test.
2) a = 5; would be ok in the body of func_test.
3) The line x = func_test(); would be ok in the body of main.
4) The line c = func_test(); would be ok in the body of main.
5) The b in main and the b in func_test refer to 2 different variables.
6) The line x = a; would be ok in the body of func_test.
7) The line return d; would be ok in the body of func_test.


  • We will not do your homework for you. Please ask a more specific question or post the code you are having trouble with.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion