Question:
c++ programming questions?
~V3N0M~
2012-02-21 11:42:05 UTC
1)Write a program that prompts the user to enter an integer (0-999), and then outputs each digit separately.

The user should be able to enter integers and see the digits as many times as they want, a negative integer will signal the program to quit.
An input value greater than 999 should trigger the response "Invalid input: try again".

For this program, you should have at least one procedure, called find_digits: Since up to three separate items need to be extracted from the input, and since a function can only return a single value through a return statement, you will instead have to use pass-by-reference parameters to "pass back" the digits.

So your procedure should have a return type of void and take 4 parameters: the number itself (should be a value parameter), and a reference parameter for each digit of the number.

2)Write a program that allows a user to randomly draw two cards and see if they win a prize.

Each card's value (2-10, Jack, Queen, King, and Ace) and suit (hearts, diamonds, spades, and clubs) will be randomly chosen.
You will need to use integer values as codes for those things that are not integers (Jack, Queen, hearts, diamonds, etc.). This will allow you to use the rand() function which only generates integers.
However, when printing the two cards, you should translate the integers into what they are representing. For example, you should output, "You drew a 3 of Hearts.", or "You drew a Jack of spades." Do not output, "You drew a 12 of suit type 2".
Lastly, output whether they win.
A pair (two of the same value (suit doesn't matter)) wins a large prize.
Drawing a Jack (of any suit) wins a small prize.
You should use the library's rand() function from the previous experience to generate your card value (2-10, Jack, Queen, King, Ace) and your suit. You must also write the following functions: translate_card_num, translate_card_type and print_winnings. You may write additional functions if you wish.

3)Write a predicate function that tests whether a year is a leap year

bool leap_year( int year )
A leap year is: a year with 366 days. Leap years are necessary to keep the calendar synchronized with the sun because the earth revolves around the sun once every 365.25 days. Actually, that figure is not entirely precise, and for all dates after 1582 the Gregorian correction applies. Leap years follow some basic rules:

Usually years that are divisible by 4 are leap years, for example 1996.
However, years that are divisible by 100 (for example, 1900) are not leap years.
But years that are divisible by 400 are leap years (for example, 2000).
For more of a challenge, write this function as a single return statement (no if statement(s)).
Four answers:
roger
2012-02-22 11:00:31 UTC
for the first one

int num;

hundreds=(num/100)%10;

tens=(num/10)%10;

ones=num%10;



you can do the rest



for leap year



bool isLeap(int year){

return year%400==0 ||( year %100 && year %4==0);

}
levick
2016-11-08 09:27:49 UTC
NeilLinux2010:~$ vi maxminnumbers.cpp NeilLinux2010:~$ g++ -g -O2 maxminnumbers.cpp -o maxminnumbers NeilLinux2010:~$ ./maxminnumbers 3 8 22 19 a million EOF detected--dumping consequences max=22 min=a million NeilLinux2010:~$ right here's the code: /* maxminnumbers.cpp objective: study the classic enter for integers, record the optimum and minimum values, then record them on the best at the same time as end of stdin is reached. 2010-02-01 */ #include iostream // for cin, cout #include cstdio // for feof, stdin using namespace std; int major(int argc, char **argv) { int cmax, cmin, num; // decl of vars cin >> num; // get the first variety to initialize each and each and every of the others. cmax = cmin = num; // init all different vars to same cost at the same time as (!feof(stdin)) { cin >> num; // get different numbers till end of record (feof()) if (num>cmax) { cmax = num; // a sparkling optimum changed into detected. } else if (num
sleepy
2012-02-21 11:49:37 UTC
Did you attempt to do any of these programs? I see no incentive for me or anyone else to do them for you, just so you can take credit and receive a grade for it.
(~.'.~)
2012-02-21 12:01:39 UTC
Not here to do your homework. Attempt the questions, then if you have any problems, post the code so we can help you.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...