Você está na página 1de 5

** EXERCÍCIO 1 **

#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct produto {
int ID;
string nome;
int valor;
};

std::vector<produto> carrinho;

int main()
{
int total = sizeof(carrinho);

while (true) {

int escolha;

cout<<"1 - ADICIONAR, 2- REMOVER, 3- LISTAR" << endl;


std::cin >> escolha;

if (escolha == 1) {
produto novo_produto;

std::cout << "ID: ";


std::cin >> novo_produto.ID;

std::cout << "nome: ";


std::cin >> novo_produto.nome;

std::cout << "valor: ";


std::cin >> novo_produto.valor;

carrinho.push_back(novo_produto);

std::cout << "PRODUTO ADICIONADO!" << std::endl;


}

if (escolha == 2) {
int ID;
int indexID;

std::cout << "digite o id do produto: ";


std::cin >> ID;

for(int i=0; i<total; i++)


{
if (carrinho[i].ID == ID) { indexID = i; }
}

for (int j = indexID; j < total; j++) {


if (carrinho[j].ID == 0 && carrinho[j].nome == "") { break; }

carrinho[j] = carrinho[j + 1];


}

total--;

std::cout << "produto removido!" << std::endl;

--------------------------------------------------------------------------
---------------------------------------

** EXERCÍCIO 2 **

#include <iostream>

using namespace std;

void dobro(int *numero) {


* numero = 2 * *numero;
}

int main()
{
int valor = 2;

dobro(&valor);

cout<< valor << endl;

return 0;
}

if (escolha == 3) {
for (int i = 0; i < total; i++) {
if (carrinho[i].ID == 0 && carrinho[i].nome == "") { break; }

std::cout << "---------------------" << std::endl;


std::cout << "ID: ";
std::cout << carrinho[i].ID << std::endl;
std::cout << "nome: ";
std::cout << carrinho[i].nome << std::endl;
std::cout << "valor: ";
std::cout << carrinho[i].valor << std::endl;
std::cout << "---------------------" << std::endl;
}
}

if (escolha == 0) {

break;
}
}

return 0;
}

--------------------------------------------------------------------------
------------------------------------------------

** EXERCÍCIO 3 **

#include <iostream>
#include <vector>

using namespace std;

void printChars(char palavra[]) {


std::cout << palavra << std::endl;
}

int main()
{
char palavra[] = "computador";

printChars(palavra);

return 0;
}

--------------------------------------------------------------------------
------------------------------------------------

** EXERCÍCIO 4 **

#include <iostream>
#include <vector>

using namespace std;

void minimoMaximo(int v[], int *max, int *min) {

for (int i = 0; i <= sizeof(*v); i++) {


if (v[i] > v[i + 1]) { v[i + 1] = v[i]; }
}

* max = v[sizeof(*v) - 1];


* min = v[0];
}

int main()
{
int numeros[] = {1, 2, 7, 5, 6};
int max;
int min;

minimoMaximo(numeros, &max, &min);

std::cout << max << std::endl;


std::cout << min << std::endl;

return 0;
}

--------------------------------------------------------------------------
----------------------------------------------

** EXERCÍCIO 5 **

#include <iostream>
#include <vector>
#include <string>

using namespace std;

struct Aluno {
string nome;
int idade;
};

void inverte(Aluno *v, int n) {

Aluno temp;
for(int i = 0; i<n/2; i++){
temp = v[i];
v[i] = v[n-i-1];
v[n-i-1] = temp;
}
}

int main()
{

Aluno alunos[] = {{nome: "gustavo", idade: 19}, {nome: "joao", idade:


19}, {nome: "yann", idade: 18} };

inverte(alunos, 3);

std::cout << alunos[0].nome << std::endl;


return 0;
}

--------------------------------------------------------------------------
-----------------------------------------------

** EXERCÍCIO 6 **

#include <iostream>
#include <math.h>

using namespace std;

void fracionar(float num, int *inteiro, float *frac) {


* inteiro = round(num);
* frac = num - round(num);
}

int main()
{

int inteiro;
float frac;

fracionar(12.345, &inteiro, &frac);

std::cout << inteiro << std::endl;


std::cout << frac << std::endl;

return 0;
}

Você também pode gostar