Question

Given the incomplete program below, write two functions, one called integer and another called decimal. You...

Given the incomplete program below, write two functions, one called integer and another called decimal.

You can use following incomplete program. Your assignment is to supply the necessary missing code:

#include

#include using namespace std;

int integer (….)

{ //REPLACE THE … WITH THE REQUIRED PARAMETER (A DOUBLE) //WRITE HERE THE CODE TO EXTRACT THE INTEGER AND RETURN IT }

double decimal (….)

{ //REPLACE THE … WITH THE REQUIRED PARAMETER //WRITE HERE THE CODE TO EXTRACT THE DECIMAL PORTION, //MAKE SURE IT’S POSITIVE OR CONVERT IT AND RETURN IT }

int main() { double x,y; cout > x >> y;

//WRITE THE CODE TO DISPLAY THE RESULT OF CALLING THE //FUNCTIONS //WITH X //WRITE THE CODE TO DISPLAY THE RESULT OF CALLING THE //FUNCTIONS //WITH Y //USE SETW AND LEFT (SEE LESSON 3 NOTES ON OUTPUT) TO LINE //UP THE //RESULTS AS SHOWN ABOVE

return 0; }

Function main should be the one in charge of displaying the results.

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

#include<iostream>

using namespace std;

// function declaration

double Integer(double num1);

double Decimal(double num1);

int main()

{

//Below variable to store user input

double x;

//Below variable to store integer value of user input number

int y;

//Below variable to store decimal value of user input number

float z;

cout<<"\nEnter a number to get Integer and Decimal parts:";

cin>>x;

y=Integer(x);

z=Decimal(x);

cout<<"\nInteger part :"<<y;

cout<<"\nFractional part :"<<z;

return 0;

}

double Integer(double num1){

//New variable in function

int a;

a=num1;

//retuning integer part to main function

return a;

};

double Decimal(double num1){

//New variable in function

double c;

//Calculating decimal part

c=num1-Integer(num1);

//Returing decimal part to main function

return c;

};

Please comment if any thing required. Thanks For posting question

Add a comment
Know the answer?
Add Answer to:
Given the incomplete program below, write two functions, one called integer and another called decimal. You...
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
  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • 5.15 PROGRAM: Functions - Upset Fowls (C++) (1) Correct the first FIXME by moving the intro...

    5.15 PROGRAM: Functions - Upset Fowls (C++) (1) Correct the first FIXME by moving the intro text to the function stub named PrintIntro and then calling the PrintIntro function in main. Development suggestion: Verify the program has the same behavior before continuing. (2) Correct the second FIXME by completing the function stub GetUsrInpt and then calling this function in main. Notice that the function GetUsrInpt will need to return two values: fowlAngle and fowlVel. (3) Correct the third FIXME by...

  • Java generics Write a program that calls a method to multiply two integers and return the...

    Java generics Write a program that calls a method to multiply two integers and return the integer result. Modify the program to make the method generic, calling it with two generic data types and then returning the result in the same type which also has to be generic. Call the method two times, once with an integer and once with a double in your main program and display the results

  • Please in C Language Thank you! The following program source code is incomplete 1 #include <stdio.h> 2 3 // TODO:...

    Please in C Language Thank you! The following program source code is incomplete 1 #include <stdio.h> 2 3 // TODO: 1) Add the typedef here: 5// TODO: 2) Modify the parameter of repeat to add irn the function pointer for the function to be called repeatedly: 8 void repeat (int times) for (int k 0; k < times; ++k) 12 // TODO: 3) Add the call to the function pointer here: 14 15 17 void test (void) 18 printf("Test!\n"); 19...

  • In C++: A. Write 3 functions that are called in the program. 1. Function readInput prompt...

    In C++: A. Write 3 functions that are called in the program. 1. Function readInput prompt user to enter an integer to store to the parameter. 2. Function isPerfectSquare take an integer parameter and checks whether it's a perfect square, that it's square root is an integer. 3. Function min3 return the mainimum value of the parameter values, it shouldn’t use any if statement to compare the parameters but call min2 to do the comparison. Extra Credit: Function printPrimeFactorization print...

  • 14. Write two functions that take an integer parameter and return the square and the cube...

    14. Write two functions that take an integer parameter and return the square and the cube of this number, correspondingly. Write a C program that reads an integer and uses the functions to display the sum of the number's square and cube.

  • Write a program to reverse an integer number by using a function called reverse. The program...

    Write a program to reverse an integer number by using a function called reverse. The program reads in an integer number and prints its reverse order. Note that the function receives the number via a pointer, and uses the pointer to write the reverse number on the main function. The function MUST be used AS IS: void reverse(int *n) Language in C Bonus Problem: Number Reverser reverse c Write a program to reverse an integer number by using a function...

  • Write a complete program that uses the functions listed below. Except for the printOdd function, main...

    Write a complete program that uses the functions listed below. Except for the printOdd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention to the order of your function calls. Be sure to read in data from the input file. Using the input file provided, run your program to generate an output file. Upload the output file your program generates. •Write a...

  • Create a CPP file for a C++ Program. Write exactly these functions, power(x,y) function and a...

    Create a CPP file for a C++ Program. Write exactly these functions, power(x,y) function and a print(text, number) function and the main() function. The power(x,y) function returns an integer result that is calculated by raising a number x (integer) to a power y (integer). The second argument y (exponent) of the function can not exceed 100. If the second argument exceeds 100, the function should return -1. Your power(x,y) function must be able to take either 1 or 2 integer...

  • 2. Write a program with three functions that will be called from the main function The functions will calculate the...

    2. Write a program with three functions that will be called from the main function The functions will calculate the volume, area and perimeter of a cuboid. You should able to pass three parameters such as length, width and height, and a function will return area, another will return volume and final one will return perimeter. Define all your variables in floating point numbers 3. Modify the problem#2 to calculate the volume, area and perimeter in a sing le function...

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
ADVERTISEMENT