Skip to content

Instantly share code, notes, and snippets.

@mesaque
Last active October 14, 2018 19:03
Show Gist options
  • Save mesaque/6e4b7d3c4e1bf5a8beb34198c92a9098 to your computer and use it in GitHub Desktop.
Save mesaque/6e4b7d3c4e1bf5a8beb34198c92a9098 to your computer and use it in GitHub Desktop.
fael discursiva programacao estruturada
#include <stdio.h>
#include <conio.h>
#define TAM 20
struct tad_pilha
{
char nome[TAM];
};
struct tad_pilha p[10];
void empilhar(int);
void exibir(int);
void main()
{
int n = 1;
while (true)
{
empilhar(n);
exibir(n);
n++;
}
_getch();
}
void empilhar(int n)
{
printf("Adicione um nome: ");
gets_s(p[n].nome);
}
void exibir(int o)
{
int n = 1;
printf("\nPilha == topo: ");
while (n <= o)
{
printf_s("%s, ", p[n].nome);
n++;
}
printf(":fundo\n");
}
################
#include <stdio.h>
#include <conio.h>
#include <string>
#define TAM 30
#define TAM_CX 10
struct tad_carrinho
{
int id;
char nome[TAM];
int prod;
double vtotal;
};
struct tad_fila
{
struct tad_carrinho carrinho;
};
struct tad_fila caixa1[TAM_CX];
struct tad_fila caixa2[TAM_CX];
struct tad_fila caixa3[TAM_CX];
void insert(tad_carrinho, int, int);
void inicializa();
void remove(int, int);
void total(int);
void main()
{
int n = 1;
struct tad_carrinho c1;
c1.id = 1;
strcpy_s( c1.nome , "Francisco");
c1.prod = 5;
c1.vtotal = 24.4;
struct tad_carrinho c2;
c2.id = 12;
strcpy_s(c2.nome, "Pedro");
c2.prod = 3;
c2.vtotal = 32.8;
struct tad_carrinho c3;
c3.id = 18;
strcpy_s(c3.nome, "Antunes");
c3.prod = 8;
c3.vtotal = 90.0;
struct tad_carrinho c4;
c4.id = 5;
strcpy_s(c4.nome, "Jose");
c4.prod = 2;
c4.vtotal = 10.0;
struct tad_carrinho c5;
c5.id = 9;
strcpy_s(c5.nome, "Joao");
c5.prod = 7;
c5.vtotal = 16.3;
insert(c1, 1, 0);
insert(c2, 1, 1);
insert(c3, 1, 2);
insert(c4, 1, 3);
insert(c5, 1, 4);
insert(c1, 2, 0);
insert(c2, 2, 1);
insert(c3, 2, 2);
insert(c4, 2, 3);
insert(c5, 2, 4);
insert(c1, 3, 0);
insert(c2, 2, 1);
insert(c3, 3, 2);
insert(c4, 3, 3);
insert(c5, 3, 4);
remove(2, 1);
total(1);
_getch();
}
void insert(tad_carrinho carrinho, int cx, int pos)
{
switch (cx)
{
case 2:
caixa2[pos].carrinho = carrinho;
break;
case 3:
caixa3[pos].carrinho = carrinho;
break;
default:
caixa1[pos].carrinho = carrinho;
break;
}
}
void inicializa()
{
struct tad_fila caixa_vazio[10];
caixa1[10] = caixa_vazio[10];
caixa2[10] = caixa_vazio[10];
caixa2[10] = caixa_vazio[10];
}
void remove(int pos, int cx)
{
struct tad_carrinho client_vazio;
client_vazio.id = 0;
switch (cx)
{
case 2:
caixa2[pos].carrinho = client_vazio;
break;
case 3:
caixa3[pos].carrinho = client_vazio;
break;
default:
caixa1[pos].carrinho = client_vazio;
break;
}
}
void total(int cx)
{
int n = 0;
float total = 0;
float temp =0;
switch (cx)
{
case 2:
while (n < TAM_CX)
{
total = caixa2[n].carrinho.vtotal + total;
n++;
}
break;
case 3:
while (n < TAM_CX)
{
total = caixa3[n].carrinho.vtotal + total;
n++;
}
break;
default:
while (n < TAM_CX)
{
total = caixa1[n].carrinho.vtotal + total;
n++;
}
break;
}
printf_s("Total: %.2f R$\n", total);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment