CSC1321 Programming Assignment
Bonus Problems
Problems
Write programs for the following problems
- Write a C++ program to generate a web page showing color gradients. Feel free to use your favorite color for the pattern. Note that the pattern actually consists of stripes with different color tones.
Sample output.
Mono-color variation
//Sample skeleton program
using namespace std;
int main()
{
int r, g, b;
for(int i = 0; i < 256; i++)
{
r = 0;
g = 0;
b = i;
}
return 0;
}
-
Write a C++ program to generate a web page showing color gradients.
Sample output.
Two-color variation controled by a periodic sine function.
//Sample skeleton program
using namespace std;
#define PI 3.14159265358979323846
int main()
{
int r, g, b;
double phaseShift = PI/3;
for(int i = 0; i < 360 * 3; i++)
{
r = 256/2 * sin(i * PI / 180 + phaseShift) + 256/2;
g = 0;
b = 256/2 * sin(i * PI / 180) + 256/2;
}
return 0;
}
-
Write a program to calculate the following expression with 100 nested levels:
\(
S = \sqrt{1+\sqrt{1+\sqrt{1+\sqrt{1+ \dots}}}}
\)
Hint: Think about the relationships: \(S_1 = 0\), \(S_{2} = \sqrt{1 + S_1}\), \(S_{3} = \sqrt{1 + S_2}\), \(\dots\), \(S_{i+1} = \sqrt{1 + S_i}\) when there are many nested levels of square roots in the expression
-
Write a program to calculate the following expression with 100 nested levels:
\(
S = 1+\dfrac{1}{1+\dfrac{1}{1+\dfrac{1}{1+\dfrac{1}{\dots}}}}
\)
What to submit
Submit both C++ program and HTML output file to Canvas by the midnight of the due day.