Sie sind auf Seite 1von 6

LAB7

PROGRAMA 1

#include<iostream.h>

#define nmax1 20

#define nmax2 15

#define nmax3 10

int i;

union tip_siruri

int sint[nmax1];

char scar[nmax2];

double sreal[nmax3];

void citeste_sir(int n,char tsir) //functia membru de citire

for(i=0;i<n;i++)

if(tsir=='i')

cout<<"\n sint("<<i<<" ";

cin>>sint[i];

if(tsir=='c')

cout<<"\n scar("<<i<<" ";

cin>>scar[i];

}
if(tsir=='r')

cout<<"\n sreal("<<i<<" ";

cin>>sreal[i];

void afisaza_sir(int n,char tsir) //functia membru de afisare

for(i=0;i<n;i++)

if(tsir=='i') cout<<sint[i]<<' ';

if(tsir=='c') cout<<scar[i]<<' ';

if(tsir=='r') cout<<sreal[i]<<' ';

void ordonare_sir(int n,char tsir) //functia membru de ordonare

int ok,i,auxi; char auxc;double auxr;

ok=1;

while(ok)

ok=0;

for(i=0;i<n-1;i++)

if(tsir=='i')

{
if(sint[i]>sint[i+1])

auxi=sint[i];sint[i]=sint[i+1];

sint[i+1]=auxi;ok=1;

if(tsir=='c')

if(scar[i]>scar[i+1])

auxc=scar[i];scar[i]=scar[i+1];

scar[i+1]=auxc;ok=1;

if(tsir=='r')

if(sreal[i]>sreal[i+1])

auxr=sreal[i];sreal[i]=sreal[i+1];

sreal[i+1]=auxr;ok=1;

};

void main(void)

{
tip_siruri u;

int n;char r='d';

while(r=='d')

do

cout<<"\n dati nr de intregi de citit(n<"<<nmax1<<" ";

cin>>n;

while((n<1)||(n>nmax1));

cout<<"\n se citesc "<<n<<" intregi:\n";

cout<<"===============================";

u.citeste_sir(n,'i');

u.ordonare_sir(n,'i');

cout<<"\n=============================";

cout<<"\n sirul de intregi ordonat:";

u.afisaza_sir(n,'i');

cout<<"\n=============================";

do

cout<<"\n dati nr de caractere de citit(n<"<<nmax2<<" ";

cin>>n;

while((n<1)||(n>nmax2));

cout<<"\n se citesc "<<n<<" caractere:";

cout<<"\n=============================";

u.citeste_sir(n,'c');
u.ordonare_sir(n,'c');

cout<<"\n=============================";

cout<<"\n sirul de caractere ordonat:";

u.afisaza_sir(n,'c');

cout<<"\n=============================";

do

cout<<"\n dati nr de reali de citit(n<"<<nmax3<<" ";

cin>>n;

while((n<1)||(n>nmax3));

cout<<"\n se citesc "<<n<<" reali:\n";

cout<<"\n=============================";

u.citeste_sir(n,'r');

u.ordonare_sir(n,'r');

cout<<"\n=============================";

cout<<"\n sirul de reali ordonat:";

u.afisaza_sir(n,'r');

cout<<"\n=============================";

cout<<"\n continuati?(d/n):";

cin>>r;

}.
PROGRAMA 2

#include <iostream>

using namespace std;

class X {

int v;

public:

X(int a = 0): v(a) {}

void Print() const {

cout << v << endl;

};

template <class T1, class T2>

class A{

public:

template <class T2>

class B {

public:

B(T1 a): v1(a) ,

v2(v1) {}

T1 v1;

T2 v2;

void g() { v2.Print(); }

};

B<T2> m;

A(T1 s): m(s) {}

void f() { m.g(); }

};

void main() {

A<int, X> a(7);

a.f();