aniri, on 19 April 2010 - 05:37 AM, said:
So, who won? 
I know right!
Posted 20 April 2010 - 03:34 PM
#ifndef COMPLEX_BODOM658
#define COMPLEX_BODOM658
#include<iostream>
using std::ostream;
class Complex {
double real;
double imag;
public:
Complex(double r, double i);
double getReal();
double getImag();
double mod();
friend Complex operator + (Complex& a, Complex& B)/>;
friend Complex operator - (Complex& a, Complex& B)/>;
friend Complex operator * (Complex& a, Complex& B)/>;
friend Complex operator / (Complex& a, Complex& B)/>;
friend ostream& operator << (ostream& out, Complex a);
};
#endif
#include "complex.h"
#include <cmath>
// Methods
Complex::Complex(double r, double i) : real(r), imag(i) {}
double Complex::getReal() { return real; }
double Complex::getImag() { return imag; }
double Complex::mod() { return sqrt(real*real + imag*imag); }
// Friends
Complex operator + (Complex& a, Complex& B)/> {
return Complex(a.getReal() + b.getReal(),
a.getImag() + b.getImag());
}
Complex operator - (Complex& a, Complex& B)/> {
return Complex(a.getReal() - b.getReal(),
a.getImag() - b.getImag());
}
Complex operator * (Complex& a, Complex& B)/> {
return Complex(a.getReal()*b.getReal()-a.getImag()*b.getImag(),
a.getReal()*b.getImag()+a.getImag()*b.getReal());
}
Complex operator / (Complex& a, Complex& B)/> {
double coeff = (1.0/(b.getReal()*b.getReal() + b.getImag()*b.getImag()));
return Complex(coeff*(a.getReal()*b.getReal() + a.getImag()*b.getImag()),
coeff*(a.getImag()*b.getReal() - a.getReal()*b.getImag()));
}
ostream& operator << (ostream& out, Complex a) {
if(a.getImag() > 0)
out << a.getReal() << "+" << a.getImag() << "j";
else if (a.getImag() == 0)
out << a.getReal();
else
out << a.getReal() << a.getImag() << "j";
return out;
}
#include <iostream>
#include <cstdlib>
#include "complex.h"
using namespace std;
int main(int argc, char** argv) {
if (argc != 6) {
cerr << "Usage: " << argv[0] << " min_x max_x min_y max_y step" << endl;
return 1;
}
double minx = atof(argv[1]);
double maxx = atof(argv[2]);
double miny = atof(argv[3]);
double maxy = atof(argv[4]);
double step = atof(argv[5]);
int iterations = 64;
double bound = 2;
// header
cout << "x,y,iterations\n";
for (double x = minx; x <= maxx; x += step) {
for (double y = miny; y <= maxy; y += step) {
Complex c(x,y);
Complex z(0,0);
double crtmod;
int i;
for (i = 0; i < iterations; i++) {
z = z*z;
z = z + c;
crtmod = z.mod();
if (crtmod > bound) {
break;
}
}
cout << x << "," << y << "," << i << endl;
}
}
return 0;
}
Posted 21 April 2010 - 10:13 AM
Posted 03 May 2010 - 07:01 AM
#ifndef CALCULATE_H
#define CALCULATE_H
#include <QApplication>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLineEdit>
#include <QLabel>
#include <QPushButton>
class Calculate : public QApplication
{
Q_OBJECT
public:
Calculate(int argc, char * argv[]);
~Calculate();
public slots:
void calcAdd(); // to calculate addition
void calcSubtract(); // to calculate subtraction
void calcMultiply(); // to calculate multiplication
void calcDivide(); // to calculate division
void quit(); // to quit the application
private:
QWidget * widget;
QHBoxLayout * hLayout1;
QVBoxLayout * vLayout1;
QVBoxLayout * vLayout2;
QVBoxLayout * vLayout3;
QLineEdit * edit1;
QLineEdit * edit2;
QLabel * label;
QPushButton * add;
QPushButton * subtract;
QPushButton * multiply;
QPushButton * divide;
QPushButton * exit;
};
#endif // CALCULATE_H
#include "Calculate.h"
//Calculate::Calculate(QString msg, QWidget * parent)
Calculate::Calculate(int argc, char * argv[])
: QApplication(argc, argv)
{
// INITIALIZE WIDGETS
widget = new QWidget();
hLayout1 = new QHBoxLayout();
vLayout1 = new QVBoxLayout();
vLayout2 = new QVBoxLayout();
vLayout3 = new QVBoxLayout();
edit1 = new QLineEdit();
edit2 = new QLineEdit();
label = new QLabel();
add = new QPushButton("Add");
subtract = new QPushButton("Subtract");
multiply = new QPushButton("Multiply");
divide = new QPushButton("Divide");
exit = new QPushButton("Exit");
// LAYOUT OF WIDGETS
// vertical layout 1
vLayout1->addWidget(edit1);
vLayout1->addWidget(edit2);
vLayout1->addWidget(label);
// vertical layout 2
vLayout2->addWidget(add);
vLayout2->addWidget(subtract);
vLayout2->addStretch();
// vertical layout 3
vLayout3->addWidget(multiply);
vLayout3->addWidget(divide);
// vLayout3->addStretch();
vLayout3->addWidget(exit);
// horizontal layout
hLayout1->addLayout(vLayout1);
hLayout1->addLayout(vLayout2);
hLayout1->addLayout(vLayout3);
widget->setLayout(hLayout1);
widget->show();
// CONNECTING SIGNALS TO SLOTS
connect(add, SIGNAL(clicked()), this, SLOT(calcAdd()));
connect(subtract, SIGNAL(clicked()), this, SLOT(calcSubtract()));
connect(multiply, SIGNAL(clicked()), this, SLOT(calcMultiply()));
connect(divide, SIGNAL(clicked()), this, SLOT(calcDivide()));
connect(exit, SIGNAL(clicked()), this, SLOT(quit()));
// connect(quit, SIGNAL(triggered()), this, SLOT(close()));
}
Calculate::~Calculate()
{
delete hLayout1;
delete vLayout1;
delete vLayout2;
delete vLayout3;
delete widget;
}
void Calculate::calcAdd()
{
int num1 = edit1->text().toInt();
int num2 = edit2->text().toInt();
int sum = num1 + num2;
label->setText(QString::number(sum, 10));
}
void Calculate::calcSubtract()
{
int num1 = edit1->text().toInt();
int num2 = edit2->text().toInt();
int difference = num1 - num2;
label->setText(QString::number(difference, 10));
}
void Calculate::calcMultiply()
{
int num1 = edit1->text().toInt();
int num2 = edit2->text().toInt();
int product = num1 * num2;
label->setText(QString::number(product, 10));
}
void Calculate::calcDivide()
{
double num1 = edit1->text().toDouble();
double num2 = edit2->text().toDouble();
double quotient = num1 / num2;
label->setText(QString::number(quotient, 'g', 10));
}
void Calculate::quit()
{
QApplication::quit();
}
#include <QApplication>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QString>
#include <QPushButton>
#include "Calculate.h"
int main(int argc, char * argv[])
{
Calculate app(argc, argv);
return app.exec();
}
This post has been edited by NickDMax: 08 May 2010 - 06:55 AM
Posted 25 June 2010 - 06:18 PM
#include "stdafx.h"
#include <algorithm>
#include <iostream>
int main()
{
using namespace std;
const int nSize = 10;
int anArray[nSize] = { 30, 50, 20, 10, 40, 70, 100, 60, 90, 80 };
for (int nStartIndex = 0; nStartIndex < nSize; nStartIndex++)
{
int nLargestIndex = nStartIndex;
for (int nCurrentIndex = nStartIndex + 1; nCurrentIndex < nSize; nCurrentIndex++)
{
if (anArray[nCurrentIndex] > anArray[nLargestIndex])
nLargestIndex = nCurrentIndex;
}
swap(anArray[nStartIndex], anArray[nLargestIndex]);
}
for (int nPrint = 0; nPrint < nSize; nPrint++)
cout << anArray[nPrint] << endl;
return 0;
}
Posted 27 June 2010 - 12:19 AM
#include <iostream>
int main()
{
using namespace std;
int y;
int x;
cout >> "Enter a number to have it multiplied by another number:";
cin << x << End1;
cout >> "Enter second number:"
cin << y;
cout >> x * y "This is the products of your numbers." << End1;
return 0;
}
Posted 30 July 2010 - 06:48 PM
Lord_C_52_WOC_DIC.zip (16.98K)
Posted 13 October 2010 - 08:11 AM
