Anonymous
Just tell me what should I do in main function and in user defined function. I am totally confused.
Junaid
Write a C++ Program that contains four user defined function(s): addition(), subtraction(), division(), multiplication(). Develop a calculator as follows: • In main() function: o A menu with choices addition, subtraction, division and multiplication must be displayed. o Get two numbers and a choice from user o Call the respective functions with user given number as parameter using switch statement o Print the result from addition (), subtraction (), division (), multiplication (). • In user defined functions: o Plus and minus function get two integer values and return integer. o Multiply and Divide functions get two integer values and return double.
#include<stdio.h> int sum(int num1,int num2); int mul(int num1,int num2); int div(int num1,int num2); int sub(int num1,int num2); int main() { float num1,num2; char op; printf("Enter First Number:"); scanf("%f",&num1); printf("Enter your operation:"); scanf(" %c",&op); printf("Enter Second Number:"); scanf("%f",&num2); if(op=='+') { sum(num1,num2); } else if(op=='*') { mul(num1,num2); } else if(op=='-') { sub(num1,num2); } else if(op=='/') { div(num1,num2); } return 0; } int sum(int num1,int num2) { printf("Sum is %d",num1+num2); return num1+num2; } int mul(int num1,int num2) { printf("product is %d",num1*num2); return num1*num2; } int sub(int num1,int num2) { printf("Subtraction is %d",num1-num2); return num1-num2; } int div(int num1,int num2) { printf("division is %d",num1/num2); return num1/num2; }
Roshan
And get the two numbers and the operation
Roshan
Are you both kidding me?
Roshan
Really?
Anonymous
ooh sorry
Anonymous
i was wrong
Junaid
I have not allowed to use any other dictionary, but iostream.
iostream in c++ and stdio.h in c are same
Roshan
ooh sorry
Iostream is for c++
Anonymous
I just want to say the header. We have never studied about studio.h . We are allowed to use <iostream> only.
Anonymous
brother logic is same just syntax is different
Brother I can't use that syntax because it is my home work. And I have not studied yet. I just ask here for any help. 11:59 Pm is deadline to submit the assignment and I tried my hard but I can't understand this question. I have written the codes for three question but I'm hanged on this question because I am not understanding this one.
Anonymous
how to enable multi queue feature in nic card ?
Anonymous
it want to set special priority in skb ?
Anonymous
ok
Anonymous
Hi
Anonymous
How do I start learning c program
Anonymous
Hi how can i take a number from my user and then first calculate average of odd numbers then calculate average of even numbers like this e.g 2569 is the input (9+5)/2 = 7 for odd numbers (2 + 4) /2 = 4 for even numbers
Anonymous
Let's sày you are a programmer which job can you d9
Anonymous
I've given half logic find the divisor by yourself!
can't you help me to write the exact code of that🤦‍♂? I'm beginner & i want to learn
Roshan
Do write the code by yourself
Anonymous
Do write the code by yourself
i know but i don't understand ur saying
Junaid
/get ide
Junaid
Hi how can i take a number from my user and then first calculate average of odd numbers then calculate average of even numbers like this e.g 2569 is the input (9+5)/2 = 7 for odd numbers (2 + 4) /2 = 4 for even numbers
#include<stdio.h> int main() { int list_count,sume=0,sum=0,num,i,even=0,odd=0; float avge,avgo; printf("Enter your amount of numbers:"); scanf("%d",&list_count); for(i=1;i<=list_count;i++) { printf("Enter your %d number",i); scanf("%d",&num); if(num%2==0) {sume=sume+num; even++; } else { sum=sum+num; odd++; } } printf("the total sum of even is %d\n",sume); printf("the total sum of odd is %d\n",sum); printf("the total avg of even is %d\n",sume/even); printf("the total avg of odd is %d\n",sum/odd); return 0; }
Junaid
this is it amir bro
14•08
What’s up
g3rm4n
hey everyone, i have a task to write a function that will get 2 arrays and their size: int contain(int big[], int size_b, int small[], int size_s) the program should check if the small array is a sub array of the big array, if true should return the Index number of the first number in the small array, else return -1. Example: 2 4 61 5 8 5 56 89 3 -2 5 56 89 3 -2 function should return 5. 9 5 12 7 8 -2 4 32 900 13 9 5 12 8 7 function should return -1. can someone help me please?
Anonymous
hey everyone, i have a task to write a function that will get 2 arrays and their size: int contain(int big[], int size_b, int small[], int size_s) the program should check if the small array is a sub array of the big array, if true should return the Index number of the first number in the small array, else return -1. Example: 2 4 61 5 8 5 56 89 3 -2 5 56 89 3 -2 function should return 5. 9 5 12 7 8 -2 4 32 900 13 9 5 12 8 7 function should return -1. can someone help me please?
Steps 1. Make a large array and populate it 2. Make a small array and populate it 3. Make helper function that will take the first element of the small array and compare with each element of the large array, if true then print the index number of that point and break, if nothing then print -1 and break Edited for some clarity
mov $22, %rax
Does anyone of you have any familiarity with xlib.h?
mov $22, %rax
I was trying to write a simple clipboard manager, but Im'm having trouble in understanding how the whole clipboard thing works in Xorg
mov $22, %rax
I found out how to succesfully ask for the owner of a selection, but I can't ask it so that I can use it in my program
Anonymous
Does anyone of you have any familiarity with xlib.h?
nohello.com also there should be Xlib channel on freenode
Anonymous
that is a russian website
Sorry, edited, but that’s not so import, just try not to ask meta questions. Hope you will find people who know Xlib
mov $22, %rax
nohello.com also there should be Xlib channel on freenode
I don't want to get banned like in every other group, but I can't stand the idea of not telling you how that website's content is unrelated to my request. Moreover if I can't ask questions about xlib here (considering it's not something so uncommon... it's a c library), than I don't know where to ask it. Now if you whish you can ban me, I'm not here 'cause I want to ask how to write a loop to pass my c++ test at school, I'm really sorry for that
Anonymous
I don't want to get banned like in every other group, but I can't stand the idea of not telling you how that website's content is unrelated to my request. Moreover if I can't ask questions about xlib here (considering it's not something so uncommon... it's a c library), than I don't know where to ask it. Now if you whish you can ban me, I'm not here 'cause I want to ask how to write a loop to pass my c++ test at school, I'm really sorry for that
Sorry, about that. This site is related to metaquestions. You can ask questions about Xlib here, moreover i think you even can ask metaquestions. But if you want your questions answered you would mind asking them. I actually believe that your question about Xlib would be answered on corresponding channel. #Xlib on freenode. Just think about how where more people know something about Xlib on this chat or on channel which name is Xlib. I don't want to ban you neither i can. If you wan't to get banned better ask Danya, i don't have any moderator rights here
Anonymous
Wish you luck dealing with X
𝐀𝐥𝐞𝐞𝐮🪐💰🕊️
Hello 👋
Sergey
Hello everyone! Please, give an advice: I want to use func ptr to some functions that have various signature. What is the best way? Templates or smth like this, idk. I'm looking at smth like this for c++11 int (*my_f)(int, int, int, <smth>) = 0; If (cond1){ my_f = my_inh1; } else if(cond2){ my_f = my_inh2; } Inherited: int (*my_inh1)(int, int, int, uint8_t) int (*my_inh2)(int, int, int, uint16_t)
🇭🇷Ivan Keca
Hello guys, glad to be here
𝙰𝚖𝚖𝚊𝚛
Good evening Excuse me for my modest question But how can i replace an element from array (1d) with element that i choose
Joe
Is there any extension could launch VS Code from Development Command Prompt
Anonymous
Hello everyone
Sergey
I don't think thee is a good way to do this.. At the point you call my_f, how do you differentiate what the last parameter should be?
I thought that maybe there are hacks like union or templates for this case. But I'm not so good in c++. That's why and asking:))
Igor🇺🇦
I thought that maybe there are hacks like union or templates for this case. But I'm not so good in c++. That's why and asking:))
What's the original issue you're trying to solve with this, let's say, weird approach?
olli
I thought that maybe there are hacks like union or templates for this case. But I'm not so good in c++. That's why and asking:))
I mean sure, there are "hacky" ways, but you should think about "why" you would do this and how you would differentiate on call site. A function pointer is like an interface, the parameters are well defined so you can use them without thinking about the actual implementation. If you need to pass different typed parameters based on a condition, call the functions directly?
Anonymous
what do you mean by a hacky way ?
olli
what do you mean by a hacky way ?
e,g, by passing void* or std::any
olli
I can call directly, but i want to set methods, that i shall use in the beginning of my own method cause i want to reduce the same conditions
yes, but when do you call my_f with uint16_t and when do you call it with uint8_t? Don't you need a check there? If it's uint8_t either way, create a wrapper function that calls my_inh2.
Anonymous
something like directives ?
Anonymous
using func_type_1 = void(*)(int); using func_type_2 = void(*)(double); std::variant<func_type_1, func_type_2> the_func; if (condition) { the_func = first_func; } else { the_func = second_func; } std::visit( std::overloaded { [](func_type_1 arg) { std::cout << arg(10) << std::endl; } [](func_type_2 arg) { std::cout << arg(42.0) << std::endl; } } ,the_func);
Anonymous
This is the one of hacky ways, I think
Anonymous
But 1. It's not C++11 2. It's bad
Sergey
so you can see repeated code inside switch
Anonymous
please use paste.ubuntu.com to paste such large piece of code
Sergey
and should i give external link? or just screen?
olli
and should i give external link? or just screen?
From @SergeiBarsukov https://paste.ubuntu.com/p/YsQg7YHWK7/
Anonymous
and should i give external link? or just screen?
Sorry Because you just joined you can't send external links But next day it'll be ok