Ssssss
#include <iostream> using namespace std; class BankDeposit { int principal; int years; float interestRate; float returnValue; public: BankDeposit(); BankDeposit(int p, int y, float ir); BankDeposit(int p, int y, int ir); void display(); }; BankDeposit::BankDeposit() { cout << "you are bankrupt mf " << endl; } BankDeposit::BankDeposit(int p, int y, int ir) { principal = p; years = y; interestRate = float(ir) / 100; returnValue = principal; for (int i = 1; i <= years; i++) returnValue = returnValue * (1 + interestRate); } BankDeposit::BankDeposit(int p, int y, float IR) { principal = p; years = y; interestRate = IR; returnValue = principal; for (int i = 1; i <= years; i++) returnValue = returnValue * (1 + interestRate); } void BankDeposit::display() { cout << "return value of your amount " << principal << " in " << years << " years will be " << returnValue; } int main() { BankDeposit b1; BankDeposit b2(100, 2, 4); b2.display(); BankDeposit b3(100, 3, 0.04); b3.display(); return 0; }
Ssssss
redefinition of 'BankDeposit::BankDeposit(int, int, int)'
{ЅᎯⅅⅅ-ℰ}
is it nested ?
Do not understand the question🧐
Ssssss
Yes... You have it twice
guide me me with it
\Device\NUL
klimi
guide me me with it
you call it as 0.04 is that a double or float?
Ssssss
you call it as 0.04 is that a double or float?
i have crreated two constructors one has int parameter and other has float
klimi
yes
klimi
and you call it with double
klimi
but you don't have double variant
{ЅᎯⅅⅅ-ℰ}
is it nested loop ?
With for loop business I have my question whether it works with while loop. Each digit should be displayed as often as it is. So 1 22 333 4444
Ssssss
but you don't have double variant
i called it with two different parameters once with int and second time with float
Ssssss
you are calling it with double
got it..thank u...i m beginner
klimi
got it..thank u...i m beginner
float fc = 3.9999999f; double da = 1.0;
klimi
note the f
Nomid Íkorni-Sciurus
Oh, that's why they do it.
Antonio
Hi everyone, I need a lot of help with this task, I have created my client and server but it seems that my code has several things that do not work, these are the requests to be fulfilled for the task "Link in pvt " , if you can help me contact me in pvt
Antonio
the programming language used is c
Кто-то
Hello. Do I need to mark the variables in this function as const? bool testTriangleBBoxIntersect(const bbox& b, Plane p) { glm::vec3 c = (b.max + b.min) * 0.5f; glm::vec3 e = b.max - c; float r = e.x * std::abs(p.n.x) + e.y * std::abs(p.n.y) + e.z * std::abs(p.n.z); float s = glm::dot(p.n, c) - p.d; return std::abs(s) <= r; }
Captain
I mean local variables (c, e, r, s)
You can as they are not getting updated.
Captain
Depends on you, your logic
Pavel
I mean local variables (c, e, r, s)
If you don't intend to change them, mark as const, nobody will be hurt by that but the compiler will check that this intention is not changed
Кто-то
You can as they are not getting updated.
I will not update them. But usually, const is skipped in this case. So I ask: is it better to use const or omit?
Peace
What is self type in C++ ?
Antonio
Anyone can help me with tcp client/server calculator in c?
klimi
indeed it has to be written in English but... it still seems that it is just some assignment from some school...
Anonymous
Hi Guys I have a some questions I have a some ardunios code how can I convert STM 32 from ardunio. I couldn't find any converter on the internet for this
Anton
Hi everyone. I have a function foobar(n) that executes another function based on integer type. Is following construction possible in C? If yes, how can I detect which type n belongs to? Pseudo code: void foobar(n) { if (typeof(n) == int) foo(n); else if (typeof(n) == unsigned int) bar(n); } int main(void) { int a; foobar(a); unsigned int b; foobar(n) return (0); }
Anton
Thanks! The main question rather how foobar(n) function should be prototyped to take any integer type, so that it could work with n later on.
Ludovic 'Archivist'
They also generally lack static reflection
Anton
Sadly C-family languages generally lack pattern matching
Actually someone told me to look into _Generic keyword and it is not dissapointing! #define typecheck(X) _Generic((X), \ unsigned int: 1, \ int: 2 \ )
Anton
Keep in mind that it is platform specific
Meaning Mac vs Windows vs Linux?
Ludovic 'Archivist'
Meaning Mac vs Windows vs Linux?
No, gcc vs msvc vs clang vs nvcc vs craycc...
olli
Hi everyone. I have a function foobar(n) that executes another function based on integer type. Is following construction possible in C? If yes, how can I detect which type n belongs to? Pseudo code: void foobar(n) { if (typeof(n) == int) foo(n); else if (typeof(n) == unsigned int) bar(n); } int main(void) { int a; foobar(a); unsigned int b; foobar(n) return (0); }
Why do you want this? you can do this however #include <stdio.h> #include <math.h> void foo_impl_i(int i) { puts("Signed version called"); } void foo_impl_ui(unsigned int i) { puts("Unsigned version called"); } #define foo(x) _Generic((x), \ int: foo_impl_i, \ unsigned int: foo_impl_ui)(x) int main(void) { foo((int)123); foo((unsigned int)123); }
Anton
No, gcc vs msvc vs clang vs nvcc vs craycc...
Thanks for mentioning, that's actually pretty important in my case 😔
Ludovic 'Archivist'
While a lot of programming languages are defined by their implementation, that is rarely the case for older languages like C, C++, lisp flavours... Where instead implementations follow a more or less vague guide book
Ludovic 'Archivist'
And that guide book says, for C and C++, that anything starting with __ may or may not cause demons and pixies flying out of your nose
olli
And that guide book says, for C and C++, that anything starting with __ may or may not cause demons and pixies flying out of your nose
not sure how this applies here, yes n1570 7.1.3 reserves identifiers beginning with an underscore that is either followed by an uppercase letter or another underscore for any use, but then 6.4.1 lists _Generic as Keyword
Ludovic 'Archivist'
Ah my bad then
olli
tbf I don't like it, but it was the attempt to bring Generics to C....
Anton
No, but in C11 it is
Thanks for guiding through :)
Nomid Íkorni-Sciurus
Hi guys I have an issue with this procedure: HWND Container::createWindow(void) const { int width = CLASSNAME_APP_MIN_WIDTH; int height = CLASSNAME_APP_MIN_HEIGHT; auto parentHandle = this->getParent()->getHWND(); auto hInstance = this->getInstance(); return ::CreateWindow( _T(CLASSNAME_CONTAINER), nullptr, WS_CHILD, 0, 0, width, height, parentHandle, nullptr, hInstance, nullptr ); } The debugger says that CreateWindowW is trying to call a null pointer to a function deep inside user32.dll I guess some of the parameters are wrong. I know for sure that: 1. parentHandle comes from the hwnd parameter of WM_CREATE ; 2. hInstance is valid 3. the other nullptr s are not the issue. What would you suggest?
Jagadeesh
#include<stdio.h> int main(){ int a = 178; char *ptr; ptr =( char *)&a; printf("%d ",*ptr); return 0; } how it's printing -78
\Device\NUL
Max value of signed char is 127, 2 ^ 7
\Device\NUL
Data type overflow i think
Jagadeesh
okay
\Device\NUL
Is there any specific reason to declare variable outside loop beside compability with ANSI C (C89) ? type i; for (i = n; ;) for (type i = n; ;)
Ammar
Is there any specific reason to declare variable outside loop beside compability with ANSI C (C89) ? type i; for (i = n; ;) for (type i = n; ;)
Apart from compatibility with ANSI C (C89), this is required when you still use the variable outside the loop body. for (int i = 0; i < n; i++) { // you can use i here } // you cannot use i here ^ As such, if you still want to access the i, it must be declared outside the loop.
Ammar
/report
Phoenix
Guys can any 1 help me out here? I was trying to swap two numbers using this #include<iostream> using namespace std; void swapNums(int,int); int main() { int a=10,b=20; cout<<"before swap value of a is "<<a<<" and value of b is "<<b<<endl; swapNums(a,b); cout<<"after swap value of a is "<<a<<" and value of b is "<<b<<endl; return 0; } void swapNums(int x,int y) { int z=x; x=y; y=z; } Output: before swap value of a is 10 and value of b is 20 After swap value of a is *10* and value of b is *20*. But why is this happening even when i called the function inside main function?
Phoenix
Nope
\Device\NUL
Nope
Then use it