In C++
Do not use a compiler like CodeBlocks or online. Trace the code by hand.
Do not write "#include" and do not write whole "main()" function. Write only the minimal necessary code to accomplish the required task.
Save your answer file with the name: "FinalA.txt"
1) (2 pts) Given this loop
int cnt = 1;
do {
cnt += 3;
} while (cnt < 25);
cout << cnt;
It runs ________ times
After the loop, code will print the number _______
2) (2 pts) Given this loop
int cnt = 10, i = 0;
while (cnt < 11 || i > 0) {
i += 1;
} ;
It runs ________ times
3) (2 pts) Given this loop
for (int k = 0 ; k > 20 ; k++) {
cout << "Hello";
}
It runs ________ times
4) (2 pts) Given this loop
int k = 0;
for ( ; ; ++k) {
if (k == 30) break;
}
It runs ________ times
5) (2 pts)Given this code
string name;
cout << "Enter a name: ";
cin >> name;
Write one line of code to print the last character of the name:
_______________________
6) (4 pts)Given this code
string s;
cout << "Enter a string:";
cin >> s;
//To do
Write the code to find if the character 'A' is present in the input string. If it is present, print the position number of the first occurrence of 'A'; the printed position of the first character is 1.
__________________
7) (5 pts) Write the code to create an integer array that contains all the numbers that are divisible by 2 in the range from 1 to 1000.
_______________
8) (5 pts) Complete this function that calculates the N-powers of the numbers in an array "numbers" and put the results in the same numbers array. N is given as the exponent parameter. Function returns the sum of all the results. Assume that "cmath" is already included. Use only one loop in the function
In main()
This is given to you as a sample, do not write it:
double arr [5] = { 1.2, 3.4 , 5.6, 12.8, 1.7 };
double result = getPowers(arr, 3, 5); // result contains the sum of the result array
// arr array will contain the cubic powers (power 3) of the numbers
Function definition:
double getPowers(double numbers[ ], int exponent, int size) {
// fill out the code
……………..
}
9) (5 pts) Complete the following function that takes 3 arguments of a circle :
- radius (input argument)
- area (output argument, to be calculated)
- circumference (output argument, to be calculated)
All arguments are double type.
If a radius is negative, the function returns false, otherwise it returns true.
The function does only calculation, and does nothing else.
Assume that all #include are already there
// Fill in your Function prototype
bool circleAreaAndCircumference ( _______, ________, __________);
int main() {
double radius, area, circumference;
cout << "Enter a circle radius:";
cin >> radius;
bool res =____________________ // call the function
if (res)
cout << "Area is " << area << endl << "Circumference is " << circumference << endl;
else
cout << "Invalid circle";
}
// Fill in your full function definition
//................
//
10) (4 pts) Given the following code
int num[30] = {2, 4, 6, 9, 5, -1, 7, 10};
Do not write any code.
Show the value of:
a. num[3] + num[4]
b. num[6]
c. num[9] + 1
d. num[30]
11) (6 pts) Suppose we want to have an array of 16 hexadecimal digits from '0', .....,'9', 'A',....'F'. Use one or two loops to fill data in the array. Fill in the ___ portion below:
char digits [ ___ ];
// Write your loop and other code
......
12) (6 pts) Write a function to count the number of occurrences of a specific decimal digit in a string
// Function prototype
int countDigit(int digit, string str) ;
For example, this function can be called like this:
int main() {
string str = "12314561asd vd&*1";
int digit = 1;
int cnt = countDigit(1, str);
// Expected output : Number of 1 in the string is 4
cout << "Count of digit " << digit << " in the string is " << cnt;
}
13) (5 pts) Create 2 parallel arrays:
-one array contains the names of the 12 months.
-one array contains the number of days in each month. Assume that it is not a leap year.
Then write a loop using the above 2 arrays to display the names and numbers of days in each month that has the format like this:
MM has DD days
January has 31 days
February has 28 days
_______
14) (5 pts) Write one single function that can multiply either 2, 3, or 4 numbers and returns the product
double res1 = multiply(1.2, 3.4);
double res2 = multiply(1.2, 3.4, 5.8);
double res3 = multiply(1.2, 3.4, 5.8, 4.7);
15) (5 pts) Write the code to create a vector named 'letters' of char type. Then use a loop to add 26 characters of the alphabet in uppercase 'A' through 'Z' to the vector.
1. It will run 8 times and it will print 25
2. It will run infinite times.
3. It will run 0 times
4. It will run 31 times.
Friend, this was a really nice question to answer. As per the Chegg policy, I am obliged to answer the first four questions. If you find my answer helpful, please like it. Thanks.
In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand....
Create a CodeBlocks project "HW 9" Write the code to ask the user to enter the size of an array. Then create an integer array of that exact size. Ask the user to enter a maximum value and then write a loop to fill the array with random numbers with value in the range of 1 to the maximum value. For example, if the maximum value is 100, random numbers must have value 1 to 100 inclusive. Input size of...
C++ programming question will upvote
A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following int main //the radius of the...
1. If the below function countAll is called like this: countAll(10, 15); There will be an infinite loop. How would you fix this problem? void countAll(int num, int end) { cout << num << " "; countAll(num + 2, end); } Group of answer choices A.Change the 'cout' to print 'end' instead of 'num' B.Make the function return a string C. Change 'num + 2' to 'num + 1' D.It is not possible to fix E. Add a base case...
Remove srand(time(NULL)); from this C++ code so that it still finds random numbers correctly. Then, Write a program that adds the following to the fixed code. • Add a function that will use the BubbleSort method to put the numbers in ascending order. – Send the function the array. – Send the function the size of the array. – The sorted array will be sent back through the parameter list, so the data type of the function will be void....
C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...
can someone please comment through this code to explain me
specifically how the variables and arrays are working? I am just
learning arrays
code is below assignment
C++
Programming from Problem Analysis to Program Design by D. S. Malik,
8th ed.
Programming
Exercise 12 on page 607
Lab9_data.txt
Jason, Samantha, Ravi,
Sheila, and Ankit are preparing for an upcoming marathon. Each day
of the week, they run a certain number of miles and write them into
a notebook. At the...
Use the code below to answer the questions that follow. Assume that all proper libraries and name spaces are included and that the code will compile without error. Within the main function, for the variable int last_sid , write in the last digit of your SMC student ID. int foo(int a, int b) { //First int c = a+b; while(c>=3) c-=3; return c; } //------------------------------------ char foo(string a, int b) { //Second return a[b]; } //------------------------------------ string foo(int b, string...
DO NOT USE ANY EXTERNAL LIBRARIES BESIDES BUILT IN JAVA
LIBRARIES! KEEP IT SIMPLE!!!
Provided Code:
import java.util.Scanner;
public class OddAndEven{
/* PART 1: Create a nonstatic method that takes in an int number
quantity (n) and returns a returns a
String of numbers from 0 to n (inclusive) as the example above
demonstrates. Call this quantityToString.
In this method you should check that n is between 0(inclusive) and
100(inclusive).
If n is outside these boundaries return and empty...
The following code is a Java code for insertion sort. I would like this code to be modified by not allowing more than 10 numbers of integer elements (if the user enters 11 or a higher number, an error should appear) and also finding the range of the elements after sorting. /* * Java Program to Implement Insertion Sort */ import java.util.Scanner; /* Class InsertionSort */ public class InsertionSortTwo { /* Insertion Sort function */ public static void sort( int...
c++ #include <iostream> #include <string> using namespace std; /* Write a function checkPrime such that input: an int output: boolean function: Return true if the number is a prime number and return false otherwise */ //TO DO ************************************** /* Write a function checkPrime such that input: an array of int and size of array output: nothing function: Display the prime numbers of the array */ //TO DO ************************************** /* Write a function SumofPrimes such that input: an int output: nothing...