Jan 17, 2013 at 8:03am UTC
Ajutati,puneti pentru tota lumea :D
Jan 17, 2013 at 8:08am UTC
#include <stdio.h>
#include "iostream"
#include <math.h>
#include <conio.h>
using namespace std;
class numarC
{
double real;
double imag;
public :
numarC( double real = 0., double imag = 0.); // constructor
numarC operator+(const numarC&) const; // operator+()
numarC operator-(const numarC&) const;
numarC operator*(const numarC&) const;
numarC operator~() const;
double modul () {
cout << "bau";
return sqrt (real*real + imag*imag);
}
};
numarC::numarC (double a, double b) {
real = a;
imag = b;
static int count = 0;
count ++;
}
numarC numarC::operator+ (const numarC& c) const
{
numarC rezultat;
rezultat.real = (this->real + c.real);
rezultat.imag = (this->imag + c.imag);
cout << rezultat.real;
cout << endl;
return rezultat;
};
numarC numarC::operator- (const numarC& c) const
{
numarC rezultat;
rezultat.real = (this->real - c.real);
rezultat.imag = (this->imag - c.imag);
return rezultat;
};
numarC numarC::operator*(const numarC& c) const {
numarC rezultat;
rezultat.real=this->real*c.real-this->imag*c.imag;
rezultat.imag=this->real*c.imag+c.real*this->imag;
return rezultat;
}
numarC numarC::operator~() const
{
numarC conj;
conj.imag = -1 * imag;
conj.real = real;
return conj;
}
void sort (double a[10], int lenght) {
for (int i=0 ; i < 10 ; i++ ){
for (int k=i ; k < 10; k++) {
if (a [i] > a [k]) {
static double aux = 0;
aux = a[i];
a[i] = a[k];
a[k] = aux;
}
}
}
}
int main () {
/*
numarC x(4,4);
for(int i=1 ;i<=20; i++) {
numarC y(6,6);
}
numarC y(6,6);
numarC z = x + y;*/
numarC vector [10];
double module [10];
static int count = 0;
do {
static int a,b;
cout << "Introduceti partea reala" << endl;
cin >> a;
cout << "Intorduceti partea imaginara" << endl;
cin >> b;
numarC c(a,b);
vector [count] = c;
module [count] = c.modul();
count ++;
}while (count < 10);
cout << endl;
for (int i=0 ; i<10 ; i++) {
cout <<module[i]<<" ";
}
sort (module,10);
cout << endl;
for (int i=0 ; i<10 ; i++) {
cout <<module[i]<<" ";
}
getch ();
return 0;
}
Jan 17, 2013 at 8:21am UTC
#include<iostream>
using namespace std;
template <class tip_de_date> //tipul de data care va vi vectorul
class Vector
{
private:
tip_de_date* cap_vector;
int numar_elemente;
public:
Vector(int n) //aici se constr un vector de n elemente
{
cap_vector=new tip_de_date[n];
numar_elemente = n;
}
void adaugareElement(tip_de_date a, int n)
{
*(cap_vector+n)=a; //cap_vector[n]=a
}
void afisareElemente()
{
for(int i=0; i<numar_elemente; i++)
{
cout<<*(cap_vector+i)<<" ";
}
}
};
int main()
{
Vector <int> vectorulMeu(10); //aloca 10 locuri
Vector<char> vectorCaractere(20);
for(int i=0;i<10; i++)
{
vectorulMeu.adaugareElement(i,i);
}
vectorulMeu.afisareElemente();
cout<<endl;
for(char i='a'; i<20; i++)
{
vectorulMeu.adaugareElement((char)65+i,i);
}
vectorulMeu.afisareElemente();
getchar();
getchar();
return 0;
}
Jan 17, 2013 at 9:01am UTC
mie nu mi se compileaza dar ar trebui sa mearga dupa mintea mea
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
template <class adt>
struct nrComplex
{
adt pReala;
adtpImag;
};
template <class adt>
void main()
{
nrComplex n[10];
vector v;
for(int i = 0; i <= 10; i++)
{
cout << "Introduceti partea reala: ";
cin >> n[i].pReala;
cout << "Introduceti partea imaginara: ";
cin >> n[i].p.Imag;
}
for(int i = 0; i <= 10; i++)
{
v[i] = modul(n[i].pReala, n[i].pImag);
}
sort(v);
for(int i = 0; i <= 10; i++)
cout << v[i] << " ";
cout << endl;
}
template <class adt>
adt modul(adt r, adt i)
{
return (sqrt(r * r + i * i));
}
Jan 17, 2013 at 10:04am UTC
Are you guys seriously abusing this forum to share exam solutions?
All the best,
NwN