For lab 12, you need to request a date from the user, in the format "mm-dd-yyyy". This is a string but you will need to parse it into its component integers. This is how you go about doing that.
Showing posts with label source code. Show all posts
Showing posts with label source code. Show all posts
Monday, November 7, 2011
File access and user input
Usually you don't want to hard-code filenames into your projects: you want to let the user decide what the filenames should be. Here is an easy way to do just that.
Wednesday, October 26, 2011
Exam #1 source code
These are solutions to the programming problems from this week's exam. Please note that the methods presented are not the only way to solve the problems assigned. If you used a different approach and your code generated a valid answer, you could still earn full credit.Exam #1 short answers
I am still in the process of grading the exams from Monday night. In the meanwhile, you might like to review the following solutions to the short answer section of the exam. I am planning to also post some source code solutions to the programming problems presented on the test.Sunday, October 23, 2011
Whitespace... it's free!
I was reviewing today's batch of source code submissions and I noticed that an awful lot of people were not making good use of their whitespace. Please observe the following rules in your code:Wednesday, October 19, 2011
Exam #1 pretest comments -
part the first
Quite a few students seemed to have difficulty with the questions requiring code to be written, whether on paper or in the computer. Instead of responding to each student individually, I am providing the source code solutions to the last four problems on the pretest. Questions 8 and 9 are solved here and questions 10 and 11 are in the next post.Please be sure to review and understand all of these solutions.
Friday, October 14, 2011
Newlines
It isn't necessary to write multiple cout statements when you want a line break. This code
cout << endl;
cout << "Your random # is " << num << "." << endl;
cout << endl;
could be rewritten using the newline character, \n
cout << "\nYour random # is " << num << ".\n"
<< endl;
These two code snippets generate the same output:
cout << endl;
cout << "Your random # is " << num << "." << endl;
cout << endl;
could be rewritten using the newline character, \n
cout << "\nYour random # is " << num << ".\n"
<< endl;
These two code snippets generate the same output:
Monday, October 10, 2011
Enhanced telephone digits
Example 5-5 in the textbook (pp 241-242) asks the user to enter an uppercase character and returns the corresponding number from the telephone keypad. If you would prefer to make the code case-insensitive, you could add the following to the program in the book.
rand() and srand()
Sometimes you need to generate a random number. In C++, the easiest way to do this is to invoke the rand() function from the cmath library. This method returns a value from [0 - 32767] but you can use a little mathematical
Here are some examples and what they return:
Here are some examples and what they return:
Subscribe to:
Posts (Atom)