1) Using functions you write yourself,
draw an American flag on the screen. Don't worry about setting the colors, although I will update with instructions of how to change the colors.
2) Write a function which will take a number and print out all the factors of that number.
3) Write a function factorial, which will take a number n and *return* n factorial. Hint: use a for loop for this, with an accumulator.
Wednesday, March 24, 2010
Monday, March 22, 2010
quiz 3
1) What will be the output of the following code? Explain.
for(int i=0; i<10; i++);
cout << "i";
2) What will be the output of the following code? Explain.
for(int i=0; i<10; i++);
cout << i;
3) What will be the output of the following code? Explain.
for(int i=10; i>0; i--)
cout << i;
4) Given the following function:
int foo(int bar) { return bar+bar*2; }
How would you call this function from main?
main() {
___________________________;
}
for(int i=0; i<10; i++);
cout << "i";
2) What will be the output of the following code? Explain.
for(int i=0; i<10; i++);
cout << i;
3) What will be the output of the following code? Explain.
for(int i=10; i>0; i--)
cout << i;
4) Given the following function:
int foo(int bar) { return bar+bar*2; }
How would you call this function from main?
main() {
___________________________;
}
lab 10
1) Write a function which takes in an int and returns an int:
square
cube
absolute
2) Write a function which takes in two integers and returns an int:
power(X, Y) will return X^Y
sum(X, Y) will return X+Y
difference(X, Y) will return X-Y
product(X,Y) will return X*Y
3) Write a function which takes in two integers and returns a bool
isBigger(X,Y) will return true if X is bigger than Y and false otherwise
isSmaller
isEqual
4) Write a function printRange(X, Y) which returns void. It will print the numbers in the range of X through Y.
After writing each of these functions, call them from a main function.
square
cube
absolute
2) Write a function which takes in two integers and returns an int:
power(X, Y) will return X^Y
sum(X, Y) will return X+Y
difference(X, Y) will return X-Y
product(X,Y) will return X*Y
3) Write a function which takes in two integers and returns a bool
isBigger(X,Y) will return true if X is bigger than Y and false otherwise
isSmaller
isEqual
4) Write a function printRange(X, Y) which returns void. It will print the numbers in the range of X through Y.
After writing each of these functions, call them from a main function.
Monday, March 15, 2010
lab 9
1) Google printf function and use it and a loop to print the following chart:
// print sums of cubes
http://venus.cs.qc.edu/~ryba/cs111/Ch3/sumcubes.cpp
2) Research the following functions, and write a program making use of them: printf, scanf, pow, modf, rand, ceil, floor, getch, getche.
3) Research the switch-case construct, and write a program which makes use of it.
4) Implement a two player game of poker dice.
http://en.wikipedia.org/wiki/Poker_dice
// print sums of cubes
http://venus.cs.qc.edu/~ryba/cs111/Ch3/sumcubes.cpp
2) Research the following functions, and write a program making use of them: printf, scanf, pow, modf, rand, ceil, floor, getch, getche.
3) Research the switch-case construct, and write a program which makes use of it.
4) Implement a two player game of poker dice.
http://en.wikipedia.org/wiki/Poker_dice
Wednesday, March 10, 2010
another way
for (r = 1; r <= height; r++)
{
// print spaces
for (i = 1; i <= height - r; i++)
cout << " ";
// print stars
// print spaces
for (i = 1; i <= r * 2 - 1; i++)
cout << "*";
cout << endl;
}
{
// print spaces
for (i = 1; i <= height - r; i++)
cout << " ";
// print stars
// print spaces
for (i = 1; i <= r * 2 - 1; i++)
cout << "*";
cout << endl;
}
this code doesn't work 100%, for even nums but add some rounding in and it will
#include "stdafx.h"
#include
using namespace std;
int main()
{
int height;
cin >> height;
int rows = height;
int cols = height*2 - 1;
for (int r = 1; r <= rows; r++) {
for (int c = 1; c <= cols; c++)
if (c <= cols/2 - (r) || c >= cols/2 + (r)) cout << " ";
else cout << "*";
cout << endl;
}
return 0;
}
the one to print a balanced triangle
#include
using namespace std;
int main()
{
int height;
cin >> height;
int rows = height;
int cols = height*2 - 1;
for (int r = 1; r <= rows; r++) {
for (int c = 1; c <= cols; c++)
if (c <= cols/2 - (r) || c >= cols/2 + (r)) cout << " ";
else cout << "*";
cout << endl;
}
return 0;
}
the one to print a balanced triangle
Wednesday, March 3, 2010
quiz 2
1) The following is NOT a valid loop in C++:
a) for
b) while
c) do-while loop
d) fruit
2) The following is NOT a valid built-in data type:
a) float
b) double
c) triple
d) string
3) When working in Visual Studio, to use a string data type, you must:
a) #include
b) #include
c) #include
d) all of the above
4) The watch window, in Visual Studio, lets you:
a) time things using a stopwatch
b) check the current value of variables
c) declare a variable
d) none of the above
5) Write a loop to print the numbers 1 thru 4, inclusive
a) for
b) while
c) do-while loop
d) fruit
2) The following is NOT a valid built-in data type:
a) float
b) double
c) triple
d) string
3) When working in Visual Studio, to use a string data type, you must:
a) #include
b) #include
c) #include
d) all of the above
4) The watch window, in Visual Studio, lets you:
a) time things using a stopwatch
b) check the current value of variables
c) declare a variable
d) none of the above
5) Write a loop to print the numbers 1 thru 4, inclusive
Monday, March 1, 2010
Lab 7
1) find the sum of the numbers 1 thru 10
2) find the average of the numbers 1 thru 10
3) prompt for n, find the sum of 1 thru n
4) prompt for n, print all the factors of n
5) using the watch window, trace thru the number reversing program
6) on paper or excel, trace thru change in coins
7) prompt for a letter, say if it is vowel or a consonant
8) work on practice problems for midterm
2) find the average of the numbers 1 thru 10
3) prompt for n, find the sum of 1 thru n
4) prompt for n, print all the factors of n
5) using the watch window, trace thru the number reversing program
6) on paper or excel, trace thru change in coins
7) prompt for a letter, say if it is vowel or a consonant
8) work on practice problems for midterm
Subscribe to:
Posts (Atom)