Quiz – Week 6

Resources on the Web

Go check out the C/C++ PROGRAMMING EXERCISES page and do the first five questions.

You should continue to look for more options of exercises to practice your programming. Some of these resources also show solutions but try to do the exercise yourself before looking at the solution. When you do find a solution, compare your solution to those of “the answer” as well as those of your classmates.

Notes

C++ keeps changing and runs different on different machines. For the first question you may want to use printf instead of cout to format the printing, check out the printf reference here.

Note that you will also need to include <stdio.h>

printf will also complain that you are not passing an int to the %d so perhaps you want to cast the sizeof value to an int like this:

int(sizeof(c)*8)

What to Do

Publish your answers on your blog post and perhaps in your repository on GitHub for the course.

Feature Image Credit

<a title="Exercise" href="https://flickr.com/photos/sanchom/2963072255">Exercise</a> flickr photo by <a href="https://flickr.com/people/sanchom">sanchom</a> shared under a <a href="https://creativecommons.org/licenses/by/2.0/">Creative Commons (BY) license</a> </small>
Exercise flickr photo by sanchom shared under a Creative Commons (BY) license

WSQ07 – Lists

What to Do

creative commons licensed (BY-NC-SA) flickr photo by Mark Morgan Trinidad A: http://flickr.com/photos/mmorgan8186/5946796450
creative commons licensed (BY-NC-SA) flickr photo by Mark Morgan Trinidad A: http://flickr.com/photos/mmorgan8186/5946796450

 

 

 

Create a program that asks the user for 10 numbers  (floating point). Store those numbers in a list. Show to the user the total, average and standard deviation of those numbers.

Details

For the C++ group you can do this with arrays or Vectors, but you will need to know eventually how to do both.

Once you have this working, change it so that users keep giving you values until they signal “no more values”. How would you implement this and in particular for the C++ group, how to you deal with an unknown size to your array during compilation?

What to Submit

As usual, create a blog post explaining what you did, where you found resources (books, videos, web pages, friends) to help you solve this. Remember to put the tag #WSQ07 on your post so our blog hub picks that up.

You should include your code as a link to GitHub. You really should start using your GitHub repository now. If you need help on that, just ask Ken or your classmates.

If you have not seen my video yet about the GUI tutorial for GitHub, go check that out: http://youtu.be/YQmlksGFZWY

And of course, leave any questions here as well as asking those questions on Twitter with the hashtag #TC1017 so we all see your question posted there.

WSQ06 – Factorial Calculator

What to Do

creative commons licensed (BY-SA) flickr photo by ▓▒░ TORLEY ░▒▓: http://flickr.com/photos/torley/3505324528
creative commons licensed (BY-SA) flickr photo by ▓▒░ TORLEY ░▒▓: http://flickr.com/photos/torley/3505324528

 

 

 

 

 

 

Create a program that asks the user for a non-negative integer (let’s call that number n) and display for them the value of n! (n factorial).

After showing them the answer, ask them if they would like to try another number (with a simple y/n response) and either ask again (for y) or quit the program and wish them a nice day (if they answered n).

Details

There are two basic approaches: a loop with an accumulator of the multiplication and a recursive solution. Choose one and implement that. Once that is done, try the other way.

If you used a while loop for the solution with a loop, try structuring this with a for loop (or vice-versa).

What to Submit

As usual, create a blog post explaining what you did, where you found resources (books, videos, web pages, friends) to help you solve this. Remember to put the tag #WSQ06 on your post so our blog hub picks that up.

You should include your code as a link to GitHub. You really should start using your GitHub repository now. If you need help on that, just ask Ken or your classmates.

If you have not seen my video yet about the GUI tutorial for GitHub, go check that out: http://youtu.be/YQmlksGFZWY

And of course, leave any questions here as well as asking those questions on Twitter with the hashtag #TC1017 so we all see your question posted there.

WSQ05 – On To Functions

What to Do

creative commons licensed (BY) flickr photo by kevin dooley: http://flickr.com/photos/pagedooley/8435953365
creative commons licensed (BY) flickr photo by kevin dooley: http://flickr.com/photos/pagedooley/8435953365

 

 

 

 

 

 

You will go back and do WSQ01 – Fun with Numbers again.

But this time, write a function for each calculation. Each function should define two parameters (in this example of type int) and return the correct value as an integer as well.

You main program needs to ask the user for the input and then call each function to calculate the answer for each of the parts.

What to Submit

As usual, create a blog post explaining what you did, where you found resources (books, videos, web pages, friends) to help you solve this. Remember to put the tag #WSQ05 on your post so our blog hub picks that up.

You should include your code either inline in the blog post (best option) and/or a link to your actual code on Dropbox/Google Drive/GitHub.

If you have not seen my video yet about the GUI tutorial for GitHub, go check that out: http://youtu.be/YQmlksGFZWY

And of course, leave any questions here as well as asking those questions on Twitter with the hashtag #TC1017 so we all see your question posted there.

Quiz Week 4

Minimum and Squares

For this quiz I want you to (in class) create a program with two functions:

  • int minimumThree(int x, int y, int z){ }  // returns the value that is smallest of x, y and z
  • int sumSquares(int x, int y, int z) {}  // returns the value of the sum of squares of x, y, z

What to Do

You implement these function in your own program in a file quiz4.cpp.

You should make a main routine that asks the user for three numbers and then calls your functions to which should *RETURN* the value and you print in the main program.

Publish your code on your own blog today (during class time is best) and use the tag #Quiz04 so it shows up nicely in our tag cloud.

Feature Image Credit

<a title="squares" href="https://flickr.com/photos/inthe-arena/7216039450">squares</a> flickr photo by <a href="https://flickr.com/people/inthe-arena">amseaman</a> shared under a <a href="https://creativecommons.org/licenses/by-nc-nd/2.0/">Creative Commons (BY-NC-ND) license</a> </small>
squares flickr photo by amseaman shared under a Creative Commons (BY-NC-ND) license

Quiz Week 3

Functions

For this quiz I want you to (in class) create a program with two functions:

  • double square_root(double x) {}  // returns the square root of x
  • double cube_root(double x) {} // returns the cube root of x

What to Do

You implement this function in your own program in a file quiz3.cpp.

You should make a main routine that asks the user for a number and then calls your functions to calculate the square and cube roots of that number and prints them out.

What should you do if the user enters a negative number?

Publish your code on your own blog today (during class time is best) and use the tag #Quiz03 so it shows up nicely in our tag cloud.

Feature Image Credit

<a title="Square roots" href="https://flickr.com/photos/ronaldc5/14927947186">Square roots</a> flickr photo by <a href="https://flickr.com/people/ronaldc5">Ronaldc5</a> shared under a <a href="https://creativecommons.org/licenses/by/2.0/">Creative Commons (BY) license</a> </small>
Square roots flickr photo by Ronaldc5 shared under a Creative Commons (BY) license

WSQ04 – Sum of Numbers (Week 05)

What to Do

https://www.flickr.com/photos/wisamallami/2478134485/

https://www.flickr.com/photos/wisamallami/2478134485/

Write a program that asks for a range of integers and then prints the sum of the numbers in that range (inclusive).

You can use a formula to calculate this of course but what we want you to do here is practice using a loop to do repetitive work.

For example, the sum from 6 to 10 would be 0 + 6 + 7 + 8 + 9 + 10.

Notice our sum starts with zero (why?) and then we add each number in the range provided by the user. Just for fun, what is the mathematical formula to do this calculation?

Example Run

We will calculate the sum of integers in the range you provide.
Please give us the lower bound:  1
Please give us the upper bound: 10
The sum from 1 to 10 (inclusive) is: 55

Thoughts

How would you change your program to handle the user giving you the upper and lower bound in the wrong order? Or perhaps some other “user input error”?

What to Submit

As usual, create a blog post explaining what you did, where you found resources (books, videos, web pages, friends) to help you solve this. Remember to put the tag #WSQ04 on your post so our blog hub picks that up.

You should include your code either inline in the blog post (best option) and/or a link to your actual code on Dropbox/Google Drive/GitHub.

You may want to check how to get started on GitHub now, here is a good article to start with: http://readwrite.com/2013/09/30/understanding-github-a-journey-for-beginners-part-1

And of course, leave any questions here as well as asking those questions on Twitter with the hashtag #TC1017 and #WSQ04 so we all see your question posted there.

WSQ 03 – Pick a Number (Week 04)

What to Do

https://www.flickr.com/photos/dasprid/8147975983/

GitHub Office

Write a program that picks a random integer in the range of 1 to 100.

There are different ways to make that happen, you choose which one works best for you.

It then prompts the user for a guess of the value, with hints of ’too high’ or ’too low’ from the program.

The program continues to run until the user guesses the integer. You could do something extra here including telling there user how many guesses they had to make to get the right answer.

You might want to check that your program doesn’t always use the same random number is chosen and you should also split your problem solving into parts. Perhaps only generate the random number and print that as a first step.

 

Example Run

I have a number chosen between 1 and 100.
Please guess a number between 1 and 100:  50
I’m sorry but 50 is too high, try again: 25
I’m sorry but 25 is too low, try again: 42
You got it! The right answer is indeed 42.
You made 3 guesses to get the right number.

What to Submit

As usual, create a blog post explaining what you did, where you found resources (books, videos, web pages, friends) to help you solve this. Remember to put the tag #WSQ03 on your post so our blog hub picks that up.

You should include your code either inline in the blog post (best option) and/or a link to your actual code on Dropbox/Google Drive/GitHub.

You may want to check how to get started on GitHub now, here is a good article to start with: http://readwrite.com/2013/09/30/understanding-github-a-journey-for-beginners-part-1

And of course, leave any questions here as well as asking those questions on Twitter with the hashtag #TC1014 so we all see your question posted there.

WSQ 02- Temperature (Week 03)

What to Do

20067959_8b60909051_oWrite a program that will prompt the user for a temperature in Fahrenheit and then convert it to Celsius. You may recall that the formula is C = 5 ∗ (F − 32)/9.

Modify the program to state whether or not water would boil at the temperature given. Your output might look like the following

Example Run

What is the temperature in Fahrenheit? 100

A temperature of 100 degrees Fahrenheit is 37 in Celsius

Water does not boil at this temperature (under typical conditions).

What to Submit

As usual, create a blog post explaining what you did, where you found resources (books, videos, web pages, friends) to help you solve this. Remember to put the tag #WSQ02 on your post so our blog hub picks that up.

You should include your code either inline in the blog post (best option) and/or a link to your actual code on Dropbox/Google Drive/GitHub.

And of course, leave any questions here as well as asking those questions on Twitter with the hashtag #TC1017 so we all see your question posted there.