Question

In C++ 9) (5 pts) Complete the following function that takes 3 arguments of a circle...

In C++

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;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

////////////////////question 9

bool circleAreaAndCircumference (double radius, double *area, double *circumference);
int main() {
double radius, area, circumference;
cout << "Enter a circle radius:";
cin >> radius;
bool res =circleAreaAndCircumference (radius, &area, &circumference);
if (res)
cout << "Area is " << area << endl << "Circumference is " << circumference << endl;
else
cout << "Invalid circle";
return 0;
}

bool circleAreaAndCircumference (double radius, double *area, double *circumference)
{
if(radius<0)
return false;
else
{*area=3.14*radius*radius;
*circumference=2*3.14*radius;
return true;}
}


////////////////question 10

a) 9+5=14

b) 7

c) 0+1=1

d) 0

//////////question 11

for(int i=0;i<=9;i++)
digits[i]=c+i;
c='A';
for(int i=0;i<=5;i++)
digits[10+i]=c+i;

///////////question 12

int countDigit(int digit, string str) ;
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;

}
int countDigit(int digit, string str)
{
int count=0;
string dig=to_string(digit);
for(int i=0;i<str.length();i++)
if(dig[0]==str[i])
count++;
return count;
  
}

Add a comment
Know the answer?
Add Answer to:
In C++ 9) (5 pts) Complete the following function that takes 3 arguments of a circle...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand....

    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    ...

  • A) One of the problems that have been discussed in the class is to write a simple C++ program to ...

    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...

  • A) One of the problems that have been discussed in the class is to write a...

    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() { double radius; double area; double circumference; //the radius...

  • Need C++ Code (Please put //comments on there too) 1. Complete the following code: Design a...

    Need C++ Code (Please put //comments on there too) 1. Complete the following code: Design a class called Circle. The class should have an integer member variable named radius and three member functions; setRadius, getRadius, calArea; the functions' prototypes should be done inside the class declaration and the functions' definitions should come after the main function #include <iostream> using namespace std; const double PI = 3.14; // fill in the declaration of the class Circle here int main() { Circle...

  • c++ Please help! i keep getting an error message. I think my main problem is not...

    c++ Please help! i keep getting an error message. I think my main problem is not understanding the circle calculations function and how both the area and the circumference is returned from the function. I know & needs to be used, but I am unsure how to use it. Copy the following code and run it. You should break it into the following 3 functions getValidinput - which asks the user to enter the radius and then make sure that...

  • Write a Python function, called counting, that takes two arguments (a string and an integer), and...

    Write a Python function, called counting, that takes two arguments (a string and an integer), and returns the number of digits in the string argument that are not the same as the integer argument. Include a main function that inputs the two values (string and integer) and outputs the result, with appropriate labelling. You are not permitted to use the Python string methods (such as count(), etc.). Sample input/output: Please enter a string of digits: 34598205 Please enter a 1-digit...

  • Need some help on this C++ program. Circle - color:String - radius:double +Circle() +Circle(newColor:String, newRadius:double) +setColor(color:String):void...

    Need some help on this C++ program. Circle - color:String - radius:double +Circle() +Circle(newColor:String, newRadius:double) +setColor(color:String):void +setRadius(radius:double):void +getColor():String +getRadius():double +printCircleInfo():void Create the class using three files - a .h, a .cpp and a main.cpp Create a class called Circle as describe below Constructor with no arguments Sets radius to 1 and color to “black” Constructor with arguments Sets the color and radius to the values passed in Get methods (accessors) return the field that the get refers to Set methods...

  • modify sample code from example two to calculate the surface area and volume of a sphere...

    modify sample code from example two to calculate the surface area and volume of a sphere givin the radius int main() Example 2 Introduction to structures and passing the structure variables as arguments into functions. 1. A structure is created with circle related variables. 2. Two functions are created related to circle calculations. 3. This example passes structure variables from the main function to the message Circle function 4. The message Circle function converts the structure variables into regular double...

  • C++ Object Oriented assignment Can you please check the program written below if it has appropriately...

    C++ Object Oriented assignment Can you please check the program written below if it has appropriately fulfilled the instructions provided below. Please do the necessary change that this program may need. I am expecting to get a full credit for this assignment so put your effort to correct and help the program have the most efficient algorithm within the scope of the instruction given. INSTRUCTIONS Create a fraction class and add your Name to the name fraction and use this...

  • ***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName)...

    ***************Fix code recursive function #include <iostream> #include <cctype> #include <string> using namespace std; void printUsageInfo(string executableName) { cout << "Usage: " << executableName << " [-c] [-s] string ... " << endl; cout << " -c: turn on case sensitivity" << endl; cout << " -s: turn off ignoring spaces" << endl; exit(1); //prints program usage message in case no strings were found at command line } string tolower(string str) { for(unsigned int i = 0; i < str.length(); i++)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT