You are on page 1of 5

MINISTERUL EDUCAŢIEI, CULTURII ȘI CERCETĂRII AL REPUBLICII MOLDOVA

UNIVERSITATEA TEHNICĂ A MOLDOVEI

Facultatea Calculatoare, Informatică şi Microelectronică

Departamentul

Informatică și Ingineria Sistemelor

REFERAT
la lucrarea de laborator nr.1

Disciplina: „Programarea orientata pe obiecte”

A elaborat st. gr.IBM -181,Țurcan Ilie

A verificat lect.univ., Oșovschi Mariana

Chișinău 2019
Sarcina lucrarii:
a) Scrieti un program care converteste un intreg intr-un numar octal.

b) Scrieti un program care roteste fiecare element al listei dublu lantuite la


dreapta cu b pozitii.

a)

#include <iostream>

#include<cmath>

using namespace std;

int decimalToOctal(int decimalNumber);

int main()

int decimalNumber;

cout<<"Enter a decimal number:";

cin>>decimalNumber;

cout<<decimalNumber<<"in decimal="<< decimalToOctal(decimalNumber)<<"in octal";

return 0;

int decimalToOctal(int decimalNumber)

int rem, i=1, octalNumber=0;

while(decimalNumber!=0)

rem=decimalNumber % 8;

decimalNumber /=8;

octalNumber+=rem*i;

i*=10;

}
return octalNumber;

b)Scrieti un program care roteste fiecare element al listei dublu lantuite la dreapta cu b pozitii.

#include<bits/stdc++.h>
using namespace std;
struct Node {
char data;
struct Node*prev;
struct Node*next;
};
void rotate(struct Node**head_ref, int N)
{
if (N==0)
return;
struct Node*current=*head_ref;
int count= 1;
while (count < N && current !=NULL) {
current= current->next;
count++;
}
if (current ==NULL)
return;
struct Node*NthNode = current;

while (current->next !=NULL)


current = current->next;
current->next = *head_ref;
(*head_ref)->prev = current;
*head_ref = NthNode->next;
(*head_ref)->prev = NULL;
NthNode->next = NULL;
}
void push(struct Node ** head_ref, int new_data)
{
struct Node* new_Node = new Node;
new_Node->data = new_data;
new_Node->prev = NULL;
new_Node->next = (*head_ref);
if((*head_ref) != NULL)
(*head_ref)->prev = new_Node;
*head_ref = new_Node;
}
void printList(struct Node* node)
{

while(node->next !=NULL) {
cout<<node->data<< ""
<<"<=>"
<<"";
node = node->next;
}
cout << node->data;
}
int nk=0;
char elem;
int main(void)
{
struct Node* head = NULL;
cout << "Dati nr. de elemente: ";
cin >> nk;
for(int i = 0; i < nk; i++){
cout<<"Dati elementele: ";
cin>>elem;
push(&head, elem);
}
int N;cout << "Dati N:";
cin >> N;
cout<<"Given linked list \n";
printList(head);
rotate(&head,N);

cout<<"\nRotated Linked list \n";


printList(head);
return 0;
}
Concluzie:In urma efectuarii lucrarii de laborator ne-am familiarizat cu limbajul C++,cu tipurile de
date recursive,operatii asupra listelor,arborilor si am elaborator programe recursive.

You might also like