Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

atjari Group Title

Plss sum1 help me to construct a C++ program for the following question. Construct a program in C++ to calculate the value when you perform the following operations using functions and keyboard input. Addition Subtraction Multiplication Integer division Real division

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    first, you'll need a way to let the user enter values and commands using the keyboard. Do you know how to do that?

    • 2 years ago
  2. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    It will b cout<<"Enter the values"; Isnt t?

    • 2 years ago
  3. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    No, cout is for output, not input. Please find out how to do keyboard input in C++, then come back.

    • 2 years ago
  4. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    cout<<"Enter the values"; cin>>values;

    • 2 years ago
  5. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    Please construct a complete program that will let the user enter a value, and then echo back that value.

    • 2 years ago
  6. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Suppose f the ques is to construct a C++ program to display the registration number #include<iostream> using namespace std; int main() { int regno; cout<<"Enter the Registration Number"<<endl; cin>>regno; cout<<regno<<endl; system ("PAUSE"); return 0; } Is this right ?

    • 2 years ago
  7. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    looks good so far (you can determine yourself whether it is correct by running it). Since the user is meant to be able to provide commands (as well as numbers), an int input will not suffice. Change your program to allow the user to enter something like "+ 3 4". You can change the prompt to say something like "Please enter a command" or whatever you like.

    • 2 years ago
  8. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Hi @future_engineer can u help me vth this?

    • 2 years ago
  9. future_engineer Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @atjari , hii bro...I am new into CSomputer course...haven't learnt much abt C yet...:(

    • 2 years ago
  10. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    It's k. Thanx a lot.

    • 2 years ago
  11. future_engineer Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    :)

    • 2 years ago
  12. arcticf0x Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    The approach would be, initiate a switch case for all those operations after declaring them as functions, then declare a function for the user to input data. Then define each function. I know its an old approach, i used it in C for some ADTs.

    • 2 years ago
  13. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    can u jst show me hw that program vl luk lyk f u dnt mind? I stil am unabl to get a clear f the suitabl pro for my ques.

    • 2 years ago
  14. arcticf0x Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    I can show you a similar program, but it is in C, http://www.w3professors.com/Data/Courses/Data-Structure/Programs/Stack/stack-using-array.pdf Look closely how the functions are used.

    • 2 years ago
  15. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    which part of my last answer did you not understand? Yes, at some point you'll need to create functions that actually execute the operations, but they won't help you if the user cannot type in which operations he wants to choose.

    • 2 years ago
  16. arcticf0x Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Quick google gives me this, http://cpp-programs.blogspot.in/2011/03/c-program-to-do-additionsubtraction-and.html Its not the solution, but some base to start on, atleast thats how i start.

    • 2 years ago
  17. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Jst a moment let me write and c.

    • 2 years ago
  18. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    BTW, "real division" strictly speaking cannot be done on a computer, because irrational numbers cannot be represented.

    • 2 years ago
  19. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    if v r to use the case statement where do v insert t? in the main functu=ion or sub func?

    • 2 years ago
  20. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    You need to decide how the user will decide on the operations. The question leaves out quite a few important specifications: how does the user choose the operations? (what is the syntax, i. e. "+ 3 4" =prefix, "3 + 4" =infix; the first one is easier to program but harder for to use. Are combinations allowed? "4 + 3 * 5" only pairs of operands, or would add(6,9,7) be allowed?

    • 2 years ago
  21. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    t?

    • 2 years ago
  22. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    do you mean "where do we insert it?"

    • 2 years ago
  23. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    ya. coz we need to ask the user to insert the choice number of the operation.

    • 2 years ago
  24. arcticf0x Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    @nczempin why induce complications for multiple operations? Lets get over with a simple program and then analyse these infix, prefix, postfix tweaks eh?

    • 2 years ago
  25. arcticf0x Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    @atjari the switch cases take care of that.

    • 2 years ago
  26. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    That's the problem I hav nw. I dnt knw wher to insert it @arcticf0x .

    • 2 years ago
  27. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I am extremely sorry @nczempin . V havnt learnt infix, postfix etc.

    • 2 years ago
  28. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    i mean we havnt learnt them yet.

    • 2 years ago
  29. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    nobody's introducing any complications; atjari will have to decide what to use, since the question doesn't specify it. If we are free to choose (no idea if we are) then the easiest to program would assume 2 operands, no combinations. In that case it would be easiest to choose the operation from 5 options (and we can just use numbers" and the prompt for the 2 operands. Then he wouldn't need to parse the string.

    • 2 years ago
  30. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    Well, by now I have suspected this, so let's just assume the simplest possible way, in which you let the user input 3 numbers: operation operand1 operand2

    • 2 years ago
  31. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    and then you can do a switch on the operation, and in the case you do the calculation

    • 2 years ago
  32. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    or, rather, in the case section you call the appropriate function, since the question asks you to use functions.

    • 2 years ago
  33. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    Have you learnt about enumerations?

    • 2 years ago
  34. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    No

    • 2 years ago
  35. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    something like this: switch (operation){ case 1: result =add(operand1,operand2); break; case 2: result = subtract(operand1, operand2); break; ... default: // some kind of error handling.

    • 2 years ago
  36. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    ok then just use ints, like I did in the example

    • 2 years ago
  37. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    you get the idea?

    • 2 years ago
  38. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Ya a little.

    • 2 years ago
  39. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    well, see how far you get with this rough outline; you'll have to declare the variables, the functions, the text printed out etc.

    • 2 years ago
  40. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    can u check the attachment and say if I hav started correctly?

    • 2 years ago
    1 Attachment
  41. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    the functions need parameters, e. g. "int sum(int a, int b);" And of course you'll need to define them too at some point, but just declaring works for now (you'll get link errors)

    • 2 years ago
  42. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    and since you're supposed to support "real division" (by which I'm assuming they mean "floating point division", your you may want to allow floats or doubles to be used. definitely in the realdiv function, and once you have that, it's up to you to decide whether you want to allow only integers as operands, or if floats/doubles are also allowed. Since you'll have to allow float or double for realdiv, this may make sense (although a program that only allows integers should also be fine; integerdiv(5, 2) = 2, realdiv(5,2) = 2.5

    • 2 years ago
  43. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    If u dnt mind cn u do me one more favour?

    • 2 years ago
  44. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    It's past midnite here. If u can write the whole program and show me I vl me much more grateful to u.

    • 2 years ago
  45. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Only if you dnt mind plssssssss. It's 1a.m in my place.

    • 2 years ago
  46. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @nczempin

    • 2 years ago
  47. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    sorry mate, I won't just program it for you. I have other things to do. Just go to bed and do it tomorrow

    • 2 years ago
  48. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    It's k. Anyways thanx. I need to submit t in the morning.

    • 2 years ago
  49. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanx a lot for helping me.

    • 2 years ago
  50. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    just put the switch in the main method, do the functions like this int add(int a, int b); int subtract(int a, int b); ... float realdiv(int a, int b); int main(){ int operation; int operand1; int operand2; // here do the inputting, like you previously did for just 1 variable, but here you collect all three values // here you insert my switch example } int add(int a, int b){

    • 2 years ago
  51. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    int add(int a, int b){ return a+ b; } // and the others int integerdiv(int a, int b){ return a/b; } float realdiv(int a, int b){ return (float) a /(float) b; }

    • 2 years ago
  52. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    now just put all those pieces together and correct the errors.

    • 2 years ago
  53. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    So kind of u mate. Vl never forget this help of urs. Thanx a lot.

    • 2 years ago
  54. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @nczempin

    • 2 years ago
  55. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    When I compile I get operation as undeclared.

    • 2 years ago
  56. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    I marked the place where the cout and cin goes in the comment // here do the inputting,

    • 2 years ago
  57. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    well, in the code I gave you it's declared.

    • 2 years ago
  58. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    if you put the switch in the main function (where I put the comment that says // here you insert my switch example) and also the "int operation;" it should be declared.

    • 2 years ago
  59. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    if i compile nw it says case label not within switch statement

    • 2 years ago
  60. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    please try to figure out these compile errors on your own. The error message should help you.

    • 2 years ago
  61. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    here result is int or float?

    • 2 years ago
  62. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    please show some effort, don't just keep asking others for the answer. What do you think? int or float?

    • 2 years ago
  63. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Extremely sorry for troubling u a lot. it's float.

    • 2 years ago
  64. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    If I compile I dnt get the correct answer is not displayed.

    • 2 years ago
  65. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    • 2 years ago
    1 Attachment
  66. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    yes, because there is an error in your code.

    • 2 years ago
  67. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    bt the error is nt displayed.

    • 2 years ago
  68. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    a programming error can still occur even if the program compiles correctly. debug the code, see what happens. What makes you think that your code would display the correct answer?

    • 2 years ago
  69. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I havnt learnt about debugging except its definition.

    • 2 years ago
  70. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @nczempin

    • 2 years ago
  71. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    well, before your next programming assignment you should learn how to set breakpoints and step through your code in whatever IDE you are using. In the meantime, I'll just give you the answer: You are displaying the result before you are computing it.

    • 2 years ago
  72. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I assure u that I vl definitely learn t bt for the moment vl u pls tell me where to insert t?

    • 2 years ago
  73. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    oh come on. where do you compute the result?

    • 2 years ago
  74. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    when I compile it performs only subtraction for any any choice given

    • 2 years ago
  75. atjari Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @nczempin

    • 2 years ago
  76. nczempin Group Title
    Best Response
    You've already chosen the best response.
    Medals 4

    you forgot some break statements. that would explain you getting division on choices 3 and 4, but not subtraction I gotta go now, sry.

    • 2 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.