BinaryByter
no, void is syntactically forced to be put
BinaryByter
but actually, I think that main is an inbuilt symbol and doesnt take a return type for that reason
🐰🐾 سمیه
Laith Bhais
Hi all
Laith Bhais
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
void maximumBoxVolume(double length,double width,double& maxBoxVolume,double& sqlength);
double min1(double,double);
int main()
{
double length[20],width[20],sqlength[40];
double maxBoxVolume[30];
int carboardArea;
double values[50];
int k = 0;
int i;
int count=0;
cout<<"Enter the area of the cardboard: ";
cin>>carboardArea;
for(i=1;i<=carboardArea;i++)
{
if(carboardArea % i==0)
{
values[count]=static_cast<double>(i);
count++;
}
}
for (i = 0;i<count/2;i++)
width[i]=values[i];
int x=count/2;
for (int j=count-1;j>=x;j--)
{
length[k]=values[j];
k++;
}
for(i=0;i<x;i++)
{
maximumBoxVolume(length[i],width[i],maxBoxVolume[i],sqlength[i]);
}
double max=maxBoxVolume[0];
int maxpos;
for(int i=1;i<x;i++)
{
if(maxBoxVolume[i]>max)
{
max=maxBoxVolume[i];
maxpos=i;
}
}
cout<<"\nLength of the card board = "<<length[maxpos]<<" inches\n";
cout<<"Width of the card board = "<<width[maxpos]<<" inches\n";
cout<<"Length of the square to cut to form a box = "<<setprecision(3)<<sqlength[maxpos]<<"inches\n";
cout<<"Maximum volume of a box = "<<setprecision(3)<<maxBoxVolume[maxpos]<<" cube inches\n";
return 0;
}
void maximumBoxVolume(double length,double width,double&maxBoxVolume,double& sqlength)
{
double sqSide;
double boxVolume;
sqSide=0.001;
maxBoxVolume=0.0;
double minSide=min1(length,width);
while (2*sqSide<=minSide)
{
boxVolume=sqSide*(length-2*sqSide)*(width-2*sqSide);
if(maxBoxVolume<boxVolume)
{
maxBoxVolume=boxVolume;
sqlength=sqSide;
}
sqSide+=0.001;
}
}
double min1(double 1,double w)
{
if(1<w)
return 1;
return w;
}
Laith Bhais
Error : 'w' was not declared in this scope
Nikolas
Sure why not
BinaryByter
Laith Bhais
What's the problem
BinaryByter
BinaryByter
Laith Bhais
Where do I know him?
BinaryByter
BinaryByter
+ i can solve multiple problems at once
🐰🐾 سمیه
why there is ( left + right) / 2 in swap here?
🐰🐾 سمیه
this is my question
BinaryByter
This is the amount of bytes to swap, i assume
🐰🐾 سمیه
swap interchanges elements of array
BinaryByter
yes
🐰🐾 سمیه
yes
division is for what?
BinaryByter
they only want to swap half of the char* buffer with the other buffer
BinaryByter
Right, they exchange the element left with the element left + r ight / 2
BinaryByter
so the middle between both
BinaryByter
(this formula calculates an average)
BinaryByter
though they should use
( left + right ) » 2;
for performance reasons
🐰🐾 سمیه
for example : if left is 0, which always is, and right is 1, which for the second call of qsort is, then swap becomes : swap( v, 0, 0+1/2=0)
🐰🐾 سمیه
it wont work that way
BinaryByter
left doesnt have to be 0
🐰🐾 سمیه
look at main. for the second call of qsort, it'll like what i said
BinaryByter
well in the first call, 1/2 will be 0
BinaryByter
but then you increase left
BinaryByter
read the code instead of asking lol
BinaryByter
if the element in the current left is greater than the middle, swap it lol
🐰🐾 سمیه
Anonymous
class A;
class B;
class B {
A test() {
A a;
return a;
}
};
class A {
B test() {
B b;
return b;
}
};
I cannot believe that C++ has so bad design
🐰🐾 سمیه
Francisco
🐰🐾 سمیه
Anonymous
error: aggregate 'A a' has incomplete type and cannot be defined
A a;
^
Anonymous
it cannot be compiled ... forever
BinaryByter
BinaryByter
like... You probably have something like
class A;
BinaryByter
but A; isnt defined
BinaryByter
Anonymous
look at my code
BinaryByter
You cannot use variables of an undefined type
BinaryByter
instead, use pointers
BinaryByter
pointers should be fine
🐰🐾 سمیه
Anonymous
but I have to return by VALUE
BinaryByter
BinaryByter
you might be able to get away by using inheritance
BinaryByter
but no, that will require pointers too
Anonymous
exactly I wrote - I cannot believe that C++ has so bad design
BinaryByter
No, what you are doing is bad design
Anonymous
??? I want return by value
Anonymous
what wrong with me?
🐰🐾 سمیه
😒
Mihail
BinaryByter
lmao
BinaryByter
i searched for an infinite loop in my code for half an hour
BinaryByter
Guess where it hid 😂
BinaryByter
IT FUCKING HID IN THE COMPILATION COMMAND
BinaryByter
appearently on clang -O3 means "add an infinite loop at the start of the main function"
BinaryByter
I have something befitting for you, my friend
Mihail
lets see it
BinaryByter
oh right gcc even optimizes /2 without -O1
Mihail
Mihail
oh clang too
BinaryByter
no
BinaryByter
clang doesnt
BinaryByter
clang only optimizes with -O1
BinaryByter
but other compilers might not optimize that
Mihail
well then just don't use bitshift and be more expressive
BinaryByter
so » can't hurt ¯\_(ツ)_/¯