RØB
RØB
klimi
you are saying that your program is not working properly, what is it doing differently that you want?
RØB
RØB
mito
Евгений
Евгений
Евгений
Евгений
Евгений
Евгений
Anonymous
Nana
Pls I want to do bubble sort with my class program I do get an error when I run the code
Nana
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
using namespace std;
class Rainfall
{
private:
double rain_amount;
double total_rainfall;
public:
void setRainfall(double rain)
{
rain_amount = rain;
}
int getRainfall()
{
return rain_amount;
}
void getTotalRainfall(double total_rain)
{
total_rainfall = total_rain;
}
int totalRain() const
{
return total_rainfall;
}
int getAverageRainfall() const
{
return total_rainfall / 12;
}
};
void intro();
int main()
{
intro();
return 0;
}
void intro()
{
cout<<"\t\tThis is a rainfall program in C++\n";
cout<<"\t\t--------------------------------------\n";
cout<<endl;
int month = 12;
string month_names[] = {"Jan", "Feb", "March", "April", "May", "June",
"July", "Aug", "Sept", "Oct", "Nov", "Dec"};
int amount;
int total;
int lowest;
int max = 200, min = 20;
unsigned seed = time(0);
srand(seed);
Rainfall rain[month];
for(int count = 0; count < month; count++)
{
amount = (rand()%(max - min+1))+min;
rain[count].setRainfall(amount);
total += amount;
rain[0].getTotalRainfall(total);
}
cout<<endl;
cout<<"Here are the rainfall values entered by the user\n";
cout<<"Month Names\t\tRainfall Amount\n";
cout<<"--------------------------------------------------\n";
cout<<fixed<<setprecision(2);
for(int count = 0; count < month; count++ )
{
cout<<month_names[count]<<"\t\t\t"<<rain[count].getRainfall()<<endl;
}
cout<<endl;
cout<<"The total Rainfall amount is: "<<rain[0].totalRain()<<endl;
cout<<"The average rainfall for the months is: "<<rain[0].getAverageRainfall()<<endl;
bool swap;
int temp;
do
{
swap = false;
for(int count = 0; count < month-1; count++)
{
if(rain[count].getRainfall() > rain[count + 1].getRainfall())
{
temp = rain[count].getRainfall();
rain[count].getRainfall() = rain[count + 1].getRainfall();
rain[count + 1].getRainfall() = temp;
}
}
}while(swap);
for(int count = 0; count < month; count++)
{
lowest = rain[0].getRainfall();
if(rain[count].getRainfall() < lowest)
lowest = rain[count].getRainfall();
}
cout<<endl;
cout<<"The lowest rainfall amount is: "<<lowest<<endl;
}
Nana
The error is at this part
Nana
do
{
swap = false;
for(int count = 0; count < month-1; count++)
{
if(rain[count].getRainfall() > rain[count + 1].getRainfall())
{
temp = rain[count].getRainfall();
rain[count].getRainfall() = rain[count + 1].getRainfall();
rain[count + 1].getRainfall() = temp;
}
}
}while(swap);
Nana
Pls I need your assistance
Евгений
Nana
klimi
for swapping things cannot you just use std::swap?
klimi
just curious if you were to trying to write it without it
Nana
with normal arrays, the above works
Klaus
Where to get project details
Klaus
Phone book
klimi
what?
Klaus
I wanted to do a mini project
Klaus
For my college
Klaus
How to start with my team someone guide me
Lokesh
Best flatform to learn c++
Lokesh
And java
klimi
Ludovic 'Archivist'
today still no std::htonll
You have c++23 bswap and std::endian, or you implement it with shifts and pray that a non Microsoft compiler will optimize it (they generally do, ms ones don't)
Ludovic 'Archivist'
And even worse than libphobos which was also quite traumatic
Ludovic 'Archivist'
The most problematic parts of C++ are relics: the iostream, std::allocator, locale facets, and std::unordered_map
Ludovic 'Archivist'
The rest delivers what it promises (except whatever passes for an implementation of make_heap on libstdc++ but really, did you ever use make_heap at work?)
paper
Best flatform to learn c++
https://adriann.github.io/programming_problems.html
Solve these and you're pretty much done with the basics
M
Hi guys, I’m studying MSc International Management but I’ve always been interested in coding.
So some days ago I started with C, I hope to find useful resources and nice people here :)
Engineer
https://www.efinancialcareers.co.uk/news/2022/04/c-developer-pay-finance
M
Engineer
I still remember when I was confused when reading the following for the first time 🤣
:
In object-oriented and functional programming, an immutable object (unchangeable object) is an object whose state cannot be modified after it is created. This is in contrast to a mutable object (changeable object), which can be modified after it is created.
布丁
Rajeev
#include <iostream>
using namespace std;
int main() {
int a[3];
a[0]=1;
a[1]=2;
a[2]=3;
int x[3];
x=a;
return 0;
}
Why error: invalid array assignment?
Aref
布丁
Rajeev
Rajeev
You mean 'a' stores address of the array. And we can't store an array's address to x having type-int!!
Rajeev
When we have to use size function of vector. We do vector_name.size()
Then why, we don't do same for iterator?
Example: vector_name.iterator is wrong.
But, vector<int> :: iterator it = v.begin; is right???
Rajeev
Please clear my confusion between fullstop and double colon
. and ::
Ludovic 'Archivist'
What kind of horror story?
code that works "in theory" but doesn't take into account IEEE754 properties, code that uses generic but very suboptimal algorithms instead of using type introspection and other things like that
布丁
\Device\NUL
\Device\NUL
Silly question, why most people hate C++ STL ?
M
Hi,
Is “Learn C the hard way” valid for a beginner? (after I learned the basics and pointers)
Евгений
Hi,
Is “Learn C the hard way” valid for a beginner? (after I learned the basics and pointers)
C language will give more then you can get from other high level languages. After C language you'll understand that Java, Python or even C# are garbage. Even if they have a lot of sugar syntax. C language will allow you to learn much more and more better way how it's really works. Other languages are hiding the most tasty parts of a language, that's why Java or Python programmers can't do real programming. They can only use a language like a Lego game. Java was written in C language, Python was also written in C language. But you can't make your own powerful language using Python or even Java. So now I hope you understand what C language is. It's a power))
Danya🔥
Danya🔥
I've not seen such a narrow-minded opinion in years
Danya🔥
I hope you grow up sometime
Danya🔥
Maybe you can give a more wide explanation:)
The purpose of programming is to get things done. Not to sink in "tasty parts of a language". A programming language is not a goal or an absolute, it's just a tool.
shuzuya
Danya🔥
shuzuya
shuzuya
🙄🙄
Евгений
Danya🔥
Danya🔥
So, anyways, @AndelieYoujin, I'd suggest you not to embarrass yourself and grow up already
M
Okay but my question still is unsolved ahahah
Is “Learn C the hard way” valid for a beginner? (after I learned the basics and pointers)
Danya🔥