C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Question
error_outline
This textbook solution is under construction.
Students have asked these similar questions
In C++:
Examine the code segment. What will be printed?
If there are any errors indicate the nature of each error.
int a[7] = {31, 12, 32, 14, 25, 16, 27};
int *ptr;
ptr = & a[2];
for ( i=1; i<=5; i=i+2)
cout << *(ptr +i);
cout << a[0] << *ptr << *ptr - 2 << *(ptr -1)) << endl;
Q13/ Write a program in c++ that asks the user to input two numbers. If the first number entered is greater than the second number, the program should print the message:
"The first number is greater." Otherwise, it should print the message:
"The first number is smaller."
.By using functions
Convert the following code into descriptive code, and verify using White Box Testing.
int a[10]={23, 45, 10, 0, 98, 36, 2, 56, 34, 12};
for (int i=0; i a[j+1])
swap(&a[j], &a[j+1]);
end-if
end-for
end-for
Knowledge Booster
Similar questions
- What is the output of the following code? int num = 17; //Line 1 double gpa = 3.85; //Line 2 bool donr; //Line 3arrow_forwardi.Consider the following code: Int a=5,b=a++ - 2; a)Explain what happened in above code?arrow_forwardConsider the following function: int test(int x, int y) { if (x == y) return x; else if (x > y) return (x + y); else return test(x + 1, y - 1); } What is the output of the following statements? a. cout << test(5, 10) << endl; b. cout << test(3, 9) << endl;arrow_forward
- Q9/Write a program in c++ that inputs a three-digit integer, separates the integer into its individual digits and prints the digits separated from one another by three spaces each by using functions. For example, if the user types in 429, the program should print: 4 2 9arrow_forwardR7.30Assuming the following declarations, find the mistakes in the statements below. struct A { int m1[2]; int m2; } struct B { A a1; A* a2; int m3; } A a; B b[2]; a.b[0].a2 = a; b.b[1].m2 = 42; c.b[2].a2 = new A; d.b[0].a1.m1 = 42; e.b[1].a2->m2 = 42;arrow_forwardQuestion 1 is already done need help with the others though This is the C code I have so far #include <stdio.h> #include <stdlib.h> struct employees { char name[20]; int ssn[9]; int yearBorn, salary; }; struct employees **emps = new employees()[10]; //Added new statement ---- bartleby // function to read the employee data from the user void readEmployee(struct employees *emp) { printf("Enter name: "); gets(emp->name); printf("Enter ssn: "); for(int i =0; i <9; i++) scanf("%d", &emp->ssn[i]); printf("Enter birth year: "); scanf("%d", &emp->yearBorn); printf("Enter salary: "); scanf("%d", &emp->salary); } // function to create a pointer of employee type struct employees *createEmployee() { // creating the pointer struct employees *emp = malloc(sizeof(struct employees)); // function to read the data readEmployee(emp); // returning the data return emp; } // function to…arrow_forward
- 18. What is the return type of function id ? a. int b. float c. bool d. dictarrow_forwardPlease use the below code to write code for median and standard deviation. I have already written for Average, Min, and Max value. Thanks! #include <stdlib.h> #include <stdio.h> #include <pthread.h> int nums; int* vals; double avg; int min, max; void* myAvg(void* param) { avg = 0.0; for(inti = 0; i < nums; ++i) { avg += vals[i]; } avg /= nums; pthread_exit(0); } void* myMin(void* param) { min = vals[0]; for(inti = 1; i < nums; ++i) { if(min > vals[i]) min = vals[i]; } pthread_exit(0); } void* myMax(void* param) { max = vals[0]; for(inti = 1; i < nums; ++i) { if(max < vals[i]) max = vals[i]; } pthread_exit(0); } int main(int argc, char** argv) { int i; nums = (argc - 1); if(nums <= 0) { printf("you have to give atleat one value!\n"); return1; } vals =…arrow_forwardWhat is the output of the following code? for (int k = 2; k <= 10000; k = k * k)cout << k << " ";cout << endl;arrow_forward
- Write minimum test cases for statement coverage.arrow_forwardWhat is the output of the code below? def mystery_func(input, num, t = 0, x = 10, y = 10)[this function multiples all arguments together (except t) and raises the result to the power of t and returns this]print(mystery_func(2, 3))arrow_forwardWhat does it mean by line1 of the following C++ statements. void y (int k) //line1 { if ((k%2)==0) cout<< k << " is an even number"; else cout<< k << " is an odd number"; } A.Function name y receives an int-type parameter. The function y does not return anything to the caller. B.Function name y receives an int-type parameter. The function y does return an int-type value to the caller.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning