1) Write a code segment that provides at least three possible outcomes (i.e., IF with a couple of ELSE blocks).
2) Write a FOR loop that would cause a section of code to be executed 10 times.
3) Write a WHILE loop that would cause a section of code to be executed 10 times.
4) What is a variable?
5) Name 5 different “data types” used in C++ programming.
1)
int num = 15;
if(num < 18) {
cout << "Young" << endl;
} else if(num <= 60) {
cout << "Adult" << endl;
} else {
cout << "Old" << endl;
}
2)
for(int i=0; i<10; i++) {
cout << "Hello" << endl;
}
3)
int i=0;
while(i<10) {
cout << "Hello" << endl;
i++;
}
4)
Variables are simply names used to refer to some location in memory
5)
bool
char
int
float
long
1) Write a code segment that provides at least three possible outcomes (i.e., IF with a...
Please use C programming to write a code segment as an answer. Instead of using an while-loop like the following code, please implement a code segment by using a do-while loop. What is the output of the code? #include <stdio.h> void main() { int i = 0; while (i < 5); { printf(“%d ”, ++i); } }
Assume that, there is no strlen() function defined for us. Write a code segment using while loop that will calculate the length of the following declaration. char stringVar[10] = “Hello”; Note that, the length of the C-string variable stringVar is 5. Can someone help me with this?
31. The following code segment is syntactically correct: int number{20}; cout << number << setbase(16) << " " << number << setbase(10) << " " << number << showpos << " " << number << endl; T__ F__ 32. The following statement wants to determine if ‘count’ is outside the range of 0 through 100: if (count < 0 && count > 100) T__ F__ 33. There is...
What will be the value of x after the following code is executed? int x = 5; while (x <50) { x += 5; } a) 50 b) 45 c) Infiniteloop d) 55 Given the following code segment: Scanner in = new Scanner (System.in); boolean done = false; while (!done) { int input = in.next(); if(input.equalsIgnoreCase("q")) done = false; } What will cause the loop to terminate? a) When the user enters -1 b) The loop will never terminate c)...
What is the value of GPA when grade is 'B' in the following code segment? int GPA=0; switch (grade) { case 'A': case 'a': GPA = GPA + 1; case 'B': case 'b': GPA = GPA + 1; case 'C': case 'c': GPA = GPA + 1; case 'D': case 'd': GPA = GPA + 1; } 4 3 2 1 None of the above #2. Branching - switch statements... Extra info/hint? It's free What is the value of GPA when...
Language is C++ Complete the following Review Questions: 1. This is a control structure that repeats a group of statements in a program? a. loop b. switch c. main() function d. compiler 2. In the expression number++,the ++operator is in what mode? a. Prefix b. Pretest c. Postfix d. Posttest 3.This is a variable that controls the number of iterations performed by a loop. a. Loop control variable b. Accumulator c. Iteration register variable d. Repetition meter 4. The do-whileloop...
Linux & Unix Write a bash program to indent the code in a bash source file. Conditions: The source file will contain only printing characters, spaces, and newlines. It is not necessary to check for invalid input. The source file will not contain comments (words beginning with #). Requirements: Read from standard input, write to standard output. Code inside while statements should be indented 2 spaces. Be sure your program includes all of the following: ...
QUESTION 1 Which statement results in the value false? The value of count is 0; limit is 10. (count != 0)&&(limit < 20) (count == 0)&&(limit < 20) (count != 0)||(limit < 20) (count == 0)&&(limit < 20) 10 points QUESTION 2 If this code fragment were executed in an otherwise correct and complete program, what would the output be? int a = 3, b = 2, c = 5 if (a > b) a = 4; if (...
1. What kind of exception will be generated when the code segment below is executed? Why? int numerator 10; int denominator 0; int wholePart numerator/denominator Questions 2 and 3 refer to the Person constructor below. Person constructor has two String parameters, a first nam and a last name. the constructor initializes the e-mail address to the first letter of the first name followed by the fir five letters of the last name followed by @jc.com. If the last name has...
How would I change the following C code to implement the following functions: CODE: #include <stdio.h> #include <stdlib.h> int main(int argc, char * argv[]) { if (argc != 2) printf("Invalid input!\n"); else { FILE * f = fopen (argv[1], "r"); if (f != NULL) { printf("File opened successfully.\n"); char line[256]; while (fgets(line, sizeof(line), f)) { printf("%s", line); } fclose(f); } else { printf("File cannot be opened!"); } } return 0; } QUESTION: Add a function that uses fscanf like this:...