In Class Activity – Repetition Worksheet
cout<<“*”;
cout<<“*”;
cout<<“*”;
cout<<“*”;
cout<<“*”;
{
cout<<“*”;
i = i+1;
}
In Class Activity – Repetition Worksheet
do
x = x + 10;
while(x < y);
cout<<x<<” “<<y;
do
x = x * 2;
while(x < y);
cout<<x<<” “<<y;
do
x = x + 2;
while(x >= y);
cout<<x<<” “<<y;
while(x < y)
x = x + 10;
cout<<x<<” “<<y;
while(x <= y)
x = x * 2;
cout<<x<<” “<<y;
In Class Activity – Repetition Worksheet
while(x > y)
x = x + 2;
cout<<x<<” “<<y;
in each case, the exact output.
for(i = 1; i <= 5; i++)
{
for(j = 1; j <= 5; j++)
cout<<setw(3)<< i*j;
cout<<endl;
}
for(i = 1; i <= 5; i++)
{
for(j = 1; j <= 5; j++)
cout<<setw(3)<<i;
cout<<endl;
}
for(i = 1; i <= 5; i++)
{
for(j = (i + 1); j <= 5; j++)
cout<<setw(5)<<j;
cout<<endl;
}
In Class Activity – Repetition Worksheet
for(i = 1; i <= 5; i++)
{
for(j = 1; j <= i; j++)
cout<<setw(3)<<j;
cout<<endl;
}
const int n = 10;
int i,j;
for(i = 1; i <= m; i++)
{
for(j = 1; j <= n; j++)
cout<<setw(3)<<m*(i-1)+j;
cout<<endl;
}
for(i = 1; i <= 9; i++)
{
for(j = 1; j <= (9 – i); j++)
cout<<” “;
for(j = 1; j <= i; j++)
cout<<setw(1)<<j;
for(j = (i -1); j >= 1; j–)
cout<<setw(1)<<j;
cout<<endl;
}
Due: _________________________________
In Class Activity – Functions Worksheet
its argument. For example, sqrt(16.0) = 4.0. The specification of the function sqrt is in the header file math.h)
#include <iostream>
#include <cmath>
int main()
{
int counter;
for(counter = 1; counter <= 100; counter++)
if(pow(floor(sqrt(counter)),2) == counter)
cout<<counter<<” “;
cout<<endl;
return 0;
}
double num1, num2, num3;
int int1, int2, int3;
int value;
num1 = 5.0; num2 = 6.0; num3 = 3.0;
int1 = 4; int2 = 7; int3 = 8;
and the function prototype
double cube(double a, double b, double c);
Which of the following statements are valid? If they are invalid, explain why.
In Class Activity – Functions Worksheet
int secret(int x)
{
int i, j;
i = 2 * x;
if (i > 10)
j = x / 2;
else
j = x / 3;
return j-1;
}
int another(int a, int b)
{
int i , j;
j = 0;
for(i = a; i <= b; i++)
j = j + i;
return j;
}
What is the output of each of the following program segments?
cout<<secret(x)<<endl;
cout<<another(x,y)<<endl;
cout<<x<<” “<<k<<” “<<another(x,k)<<endl;
cout<<another(y,x)<<endl;
In Class Activity – Functions Worksheet
int test(int, char, double, int);
double two(double, double);
char three(int, int, char, double);
Answer the following questions.
call to the function test?
parameters 5, 5, 7.3, and ‘z’.
parameters 17.5 and 18.3, respectively.
own actual parameters.)
In Class Activity – Functions Worksheet
int mystery(int x, double y, char ch)
{
int u;
if(‘A’ <= ch && ch <= ‘R’)
return(2 * x + static_cast<int>(y));
else
return(static_cast<int>(2*y)-x);
}
What is the output of the following C++ statements?
int secret(int one)
{
int I;
int prod = 1;
for(I = 1; I <= 3; I++)
prod = prod * one;
return prod;
}
In Class Activity – Functions Worksheet
#include <iostream>
int mystry(int);
int main()
{
int n;
for(n = 1; n <= 5; n++)
cout<<mystry(n)<<endl;
return 0;
}
int mystry(int k)
{
int x, y;
y = k;
for(x = 1; x <= (k – 1); x++)
y = y * (k – x);
return y;
}
(OVER)
#include <iostream>
bool strange(int);
int main()
{
int num = 0;
while(num <= 29)
{
if(strange(num))
cout<<“True”<<endl;
else
cout<<“False”<<endl;
num = num + 4;
}
return 0;
}
bool strange(int n)
{
if(n % 2 == 0 && n % 3 == 0)
return true;
else
return false;
}
Due: _________________________________
In Class Activity – One Dimensional Arrays Worksheet
1 //print the scores2 for (int i = ____; i _______________; i++)3 {4 cout <<“The value of score[” << i << “] is “;5 cout << ___________________ << endl;6 }
In Class Activity – One Dimensional Arrays Worksheet
a. index = LinearSearch (list, 12, 3); index = ________________b. index = LinearSearch (list, 12, 21); index = ________________
For example, if you trace the call BinarySearch(list, 12, 10), the following is a possible answer:
Guess 1: middle = 5 Guess 2: middle = 8 Guess 3: middle = 6 Guess 4: middle = 7 Function returns 7 a. index = BinarySearch (list, 12, -2); b. index = BinarySearch (list, 12, 100);
Due: _________________________________
In Class Activity – Strings Worksheet
For example, to show the internal representation of “x=” on the answer sheet, one would type:
x =
0 1 2
value of the variable length after each of the following statements, given the declarations:
char str1[5]; int length; 1. strcpy(str1, “Joe”); ___________________ 2. length = strlen(str1); ___________________ 3. strcpy(str1, “Joseph”); ___________________ 4. length = strlen(str1); ___________________
In Class Activity – Strings Worksheet
(1) Reads a C string,
(2) Finds the length of the C string using your MyStrLen() function,
(3) Prints the length of the C string.
Due: _________________________________
_____
In Class Activity – Two-Dimensional Arrays Worksheet
Declare a two-dimensional array which can be used to store a yearly budget. Each row of the array corresponds to a particular budgeted item like rent, electric, etc. There are at most 15 items to be budgeted. Each column of the array corresponds to a month, January, February, etc. Of course there are 12 columns corresponding to the 12 months of the year. All the data to be placed in the array consists of real numbers.
of all of one student’s labs appearing first, the file has all grades on lab 1 first, then all grades on lab 2, etc. How must the code above be changed to accommodate this new arrangement of data? Explain the difference.
Student 1: 80 90 70 100 60 90 85 78 93 80 70 98 89 94 Student 2: 98 85 100 99 89 90 72 0 78 98 100 65 0 56 Student 3: 85 60 25…. . .
In Class Activity – Two Dimensional Arrays Worksheet
4. Add a function to your program called StudentAvg(), which finds and prints the lab average for each student in the class. A function prototype for this function is shown below. Activate this function from the main program. void StudentAvg(int labScores [][MAX_LABS], //IN: Lab scores int numStudents, //IN: # of students in the class int numLabs) //IN: # of labs recorded per student
Activate this function from the main program.
Due: _________________________________
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more