adspace
write a program using 2 D that searches a number and display
the number of items 12 inputs values
input 15,20, 13, 30, 38, 40,16, 18, 20 ,18 ,20
enter no. to search : 20
Answer Posted / Vishal Kumar Rai
Here is a simple C++ code for searching a specific number in a 2D array and displaying its count:n```cppn#include <iostream>nconst int size = 4;nint arr[size][size] = {n{15, 20, 13, 30},n{38, 40, 16, 18},n{20, 18, 20, 38},n{15, 30, 40, 16}n};nint search(int num){n int count = 0;n for (int i = 0; i < size; ++i) {n for (int j = 0; j < size; ++j) {n if (arr[i][j] == num) {n count++;n }n }n }n return count;n}nint main() {n int num;n std::cout << "Enter a number to search: ";n std::cin >> num;n std::cout << "The number of occurrences for " << num << " is: " << search(num) << '.'n return 0;n}n```
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Question 1: Implement a base class Appointment and derived classes Onetime, Daily, Weekly, and Monthly. An appointment has a description (for example, “see the dentist”) and a date and time. Write a virtual function occurs_on(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill a vector of Appointment* with a mixture of appointments. Have the user enter a date and print out all appointments that happen on that date. *This Should Be Done IN C++