Consider the following C++ code segment below.
1 int result(int valueP)
2 {
3 int a = 2;
4 int count = 0;
5 while (count < valueP)
6 {
7 a += count + a / 2;
8 count += 2;
9 }
10 return a;
11 }
Demonstrate the execution and output of the program by drawing a variable diagram that traces each line of code if the value of valueP is 6. You are required to draw a variable diagram to illustrate what the code does.
2.1 Assume that s and n have been declared as integers. Explain in words what the purpose of the following segment of code is: (2)
int s = 0;
int n = 0; while (n <= 5)
{
s = s + n;
n++;
}
2.2 Explain the purpose of the following segment of code: (2)
int numbers[ ] = {11, 0, 15, 0, 16, 23};
int c = 0;
for (int i = 0; i <= 5; i++)
if (numbers[i] != 0)
c += 1;
int findValue(int numberP)
{
int count = 0;
int value = 20;
while (count < numberP)
{
value += count;
count ++;
}
return value;
}
What will be the output of the following statement executed in the main function?
cout << findValue
Suppose the input value for a is 5. What is the value of a after the following C++ code has been executed?
int a;
cin >> a;
switch (a)
{
case 1: a += 3;
case 3: a = a * 3; break;
case 5: a = ++a + 10; case 6: a /= 2; default: a = a + 1;
}
Given a string S. Let us divide 5 into two equal parts s1 and s2.s is called a halindrome if at least any one of the following conditions satisfy:
1.Sis a palindrome and length of S>=2
2.S1 is a halindrome.
3S2 a halindrome.
In the case of an odd length string the middle element is not present in both S1 and S2. If index of middle element is m. then, S1= S [0,m-1] and S2=S[m+1|S|-1].
Input Specification
input 1: Number of strings 1<=input1<=100.
imput2:An array of size input1 containing strings 2<=length of each string<=100.
output specification:
for each test case, return the number of strings which are halindromes.
EX:input1:1
input2:{harshk}
output 0
explanation:1.string S is not forming a palindrome.
2.string S1=har,which is not a halindrome.
3.String S2=shk,which is not a halindrome.
as none of the conditions are true,hence output to be returned is 0.
Head->5->3->7->9->1->Null
TASK :
Draw a diagram of the above list after the following lines of code have been executed:
Node * prev = head ->next;
Node* nodeToInsert = new Node;
nodeToInsert-> data = 4;
nodeToInsert -> next = prev -> next;
prev -> next = nodeToInsert;
Given an integer N, count the numbers having an odd number of factors from 1 to N (inclusive).
Example 1:
Input:
N = 5
Output:
2
Explanation:
From 1 - 5 only 2 numbers,
1 and 4 are having odd number
of factors.Given numbers a and b where 1<=a<=b, find the number of perfect squares between a and b(a and b inclusive)
Type
Price/Kg (RM) Discount
Grade AA Grade AAA Total Purchase >
RM200
Ajwa 45.00 75.00 5%
Mariami 50.99 90.99 8%
Safawi 47.50 85.90 6%
Given a table of prices according to type of dates and discount percentages. Write a complete
C++ program based on the following requirements.
a. main() should request required inputs
b. Include a function to display menu for type of dates dan grades.
c. Include a function that receive type, grade, quantity and price. The function will
calculate price and update parameter price. Make price as parameter pass by
reference.
d. Include a function that receive price and discount percentage and return discounted
price.
e. main() should repeatedly request input, use all functions defined and display final
price until user request to stop. Use flag variable as terminating condition.
* Do not use string as data type, use char[x] instead.
define c++