Question

In: Computer Science

Every C++ program starts with this function:____________________ 2. If A is > 100 I want cnt...

Every C++ program starts with this function:____________________

2. If A is > 100 I want cnt to be equal to 32 but if A 100 or less I want cnt to be 2. Write a single line using a conditional operator to do this.

3. I want to store into B the remainder of dividing B by the total of A plus D. Write the statement:

as a combined operator statement

not using a combined operator

4. I want to print the following, including quotes, apostrophes and slashes

"My system's programs are in c:\prog"

Write the code below.

5. I have the following bit patterns stored in 2 variables, A and B. In the answer part of each column write the results of the following bitwise operations.

A 1 1 0 0 1 1 0 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1

B 1 0 1 0 1 0 1 1 1 0 0 1 0 1 0 1 1 1 1 0 0 0 1

operation ^ & |

answer

6. Write an if ... else to do the following, all having to do with the variables A, B, C, D.

Your answer should not have independent if statements but should be one if...else...if...else.........

If the variable A is between 1 and 17, but not 10, print “hello” . 1 and 17 are included

If the variable A is greater than 72 and also less than 100 print “Goodbye” or if

the variable D is 12 print "Goodbye"

If the variable A is between 200 and 300 while C is not 12 print “waiting”




7. Write the if statement which will satisfy the following conditions about the variables A, B, and C.

a. If A is not equal to 23 at the same time that either B or D is equal to 11 then

print the value of A otherwise print the value of B.

b. If A is 23 at the same time that B is 3 then cout the value of C otherwise print

“Bye”.

8. What is the value of the variable Number after each statement. Each answer is dependent on the previous answer.

int Number=0; ___________________

Number = 100; __________________

Number /= 3 + 2; ________________

Number--; ________________

9. Based on the last answer above, what will this print: cout << (Number++ + 2);

Solutions

Expert Solution

1. Main()
Reason: Main() function is the entry point of all c++ programs
2. cnt = A > 100 ? 32 : 2;
Reason: syntax of conditional operator: condition?statement for true condition:statement for false condition
3. B %= (A + D);
Reason a % = b is equivalent to a = a % b
4.
#include<iostream>
using namespace std;
int main()
{
   cout<<"\"My system's programs are in c:\\prog\"";
   return 0;
}
Reason: '\' is called as escape character. compiles prints " if it is after a '\'.
5.
^: 0 1 1 0 0 1 1 0 0 1 1 0 0 0 1 0 1 0 0 1 0 1 0
&: 1 0 0 0 1 0 0 1 1 0 0 1 0 1 0 1 0 1 1 0 0 0 1
|: 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1
Reason: a ^ b is 1 if a and b are different and 0 otherwise
a & b is 1 if a and b both are 1 and 0 otherwise
a | b is 1 if either a or b is 1 and o if both are 0
6.
if(A >= 1 && A <= 17) cout<<"hello";
else if((A > 72 && A < 100) || (D == 12)) cout<<"Goodbye";
if(A >= 200 && A <= 300 && C != 12) cout<<"waiting";
7.
a.
if(A != 23 && (B == 11 || D == 11)) cout<<A;
else cout<<B;
if(A != 23 && B == 3) cout<<C;
else cout<<"Bye";
8.
int Number=0;//Number=0
Number=100;//Number=100
Number /= 3 + 2;//Number = Number/3 + 2 = 100/3 +2 = 33 + 2 =35
Number--;//Number=Number-1=33-1=32
9.
34
Reason:Number++ + 2 = Number + 1 + 2 = 32 + 2=34
In post increment, a number is updated in the next statement, that is why Number wasn't incremented here.'


Related Solutions

I want c++ /c program to build a double linked list and find with a function...
I want c++ /c program to build a double linked list and find with a function the middle element and its position and the linked list must be inserted by the user aand note You should handle the both cases of whether the size of the list even or odd
Program this scenario in C. Scenario: I am in highschool and i want to go see...
Program this scenario in C. Scenario: I am in highschool and i want to go see a movie. I have a certain amount of money to spend. Matinees are $8.50 and Evening Showings are $11.75. There is a G, PG, PG-13, and R movie at the theater. Ask the highschooler their age and how much money they have. With this info determine what showtime they can go see and what movies they are not allowed to see. Make it fun...
Write Program in C: Write a program that: program starts; declares and initializes to 7.25% constant...
Write Program in C: Write a program that: program starts; declares and initializes to 7.25% constant float variable NJSALES_TAX; declares and initializes to 1000 an integer variable total; declares and initializes to zero a float variable grand_total; prompt and input on new line total; calculate grand_total to equal total plus (total*NJSALES_TAX); if grand_total <= 1000 print on new line “Grand total is less than or equal to 1000 it is $” and the grand_total to two decimal places; else if...
What is the excel function/equation to add every ten numbers. I have a list of 100...
What is the excel function/equation to add every ten numbers. I have a list of 100 numbers or so in a row. I want to add the first ten numbers and put the value in the row below the list. So add numbers 1 to 10, 2 to 11, 3 to 12, and so on. There has to be an easier way to do this than manually right?
I want to retire in 40 years. When I retire, I want to withdraw $20,000 every...
I want to retire in 40 years. When I retire, I want to withdraw $20,000 every 6 months from my savings for a period of 10 years. However, at the end of years two and three in my retirement, I will need to spend $40,000 and $60,000 respectively to send my grandson to culinary school. Assuming I can earn 4% compounded semi-annually, answer the following question: How much money will I need at year 40 to fund sending my grandson...
A C++ question: I want to indent the code of this C++ program: #include<iostream> #include<cstring> using...
A C++ question: I want to indent the code of this C++ program: #include<iostream> #include<cstring> using namespace std; int lastIndexOf(char *s, char target) { int n=strlen(s); for(int i=n-1;i>=0;i--) { if(s[i]==target) { return i; } } return -1; } void reverse(char *s) { int n=strlen(s); int i=0,j=n-1; while(i<=j) { char temp=s[i]; s[i]=s[j]; s[j]=temp; i++; j--; } return; } int replace(char *s, char target, char replacementChar) { int len=strlen(s); int total=0; for(int i=0;i<len;i++) { if(s[i]==target) { s[i]=replacementChar; total+=1; } } return total;...
Hello, I need some assistance on completing this program in Pseudocode and in C++ Program 2:...
Hello, I need some assistance on completing this program in Pseudocode and in C++ Program 2: Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode) and implement (source) for a program that reads in 1) the hero’s Hit Points (HP – or health), 2) the maximum damage the hero does per attack, 3) the monster’s HP and 4) the maximum monster’s damage per attack. When the player attacks, it will pick a random...
C++ i want .00 at the output cout << fixed << setprecision (2);where should i put...
C++ i want .00 at the output cout << fixed << setprecision (2);where should i put this line? quesstion 13. Array of Payroll Objects Design a PayRoll class that has data members for an employee’s hourly pay rate and number of hours worked. Write a program with an array of seven PayRoll objects. The program should read the number of hours each employee worked and their hourly pay rate from a file and call class functions to store this information...
How much should I save at the beginning of every month for retirement? I want to...
How much should I save at the beginning of every month for retirement? I want to provide myself with increasing income starting at age 60 lasting to age 95, replacing 100% of my current income. Assumptions: Current age 30 Inflation 2.5% Projected return before retirement 8% Projected return after retirement 6% Current income $50,000 Estimated Social Security $20,000 Wage Replacement Ratio 100% Current Retirement Accounts $10,000
Given the following code: for (i=2;i<100;i=i+1) { a[i] = b[i] + a[i]; /* S1 */ c[i-1]...
Given the following code: for (i=2;i<100;i=i+1) { a[i] = b[i] + a[i]; /* S1 */ c[i-1] = a[i] + d[i]; /* S2 */ a[i-1] = 2 * b[i]; /* S3 */ b[i+1] = 2 * b[i]; /* S4 */ } a. List all the dependencies by their types (TD: true-data, AD: anti-data, OD: output-data dependencies). b. Show how Software Pipelining can exploit parallelism in this code to its fullest potential. How many functional units would be sufficient to achieve the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT