WMA IT - Soluções em Tecnologia - Assistência técnica de informática e redes de computadores em Uberlândia, Minas Gerais
Translate
quarta-feira, 4 de dezembro de 2013
Programa completo agenda usando arquivos em C++ cria, lê, busca, exclui
#include <fstream>
#include <string.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
void busca(){
char nome[100];
char nom_concat[100] = "Nome: ";
char nom_busca[205];
char *result;
int i;
char Linha[100];
FILE *agenda;
// Abre um arquivo TEXTO para LEITURA
agenda = fopen("j:\\Agenda.txt", "r+");
if (agenda == NULL) // Se houve erro na abertura
{ printf("Problemas na abertura do arquivo\n");
}
cout << "Digite o nome p/ buscar: ";
cin >> nome;
strcat( nome, "\n");
strcat( nom_concat, nome );
while (!feof(agenda))
{
// Lê uma linha (inclusive com o '\n')
result = fgets(Linha, 100, agenda);
// o 'fgets' lê até 99 caracteres ou até o '\n'
if(strcmp(Linha,nom_concat)==0){
printf("Usuário encontrado \n");
printf("Linha %d : %s",i,Linha);
getch();
}
}
fclose(agenda);
getch();
}
#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
void exclui(){
int r;
char sim[2];
FILE *agenda;
cout << "Deseja realmente excluir o arquivo? (s - n): ";
cin >> sim;
if(stricmp(sim,"s") == 0){
remove("j:\\Agenda.txt");
}
}
#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
void le(){
FILE *agenda;
char ch;
ifstream fin("j:\\Agenda.txt"); // Abre arquivo para leitura
// Enquanto não for fim de arquivo:
while(fin.get(ch)){ // lê um caracter do arquivo
cout << ch;}
}
#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <cstdlib>
#include <cstring>
#include <stdlib.h>
using namespace std;
struct contato{
char nome[40];
char end[100];
char tel[15];
};
void busca();
void le();
void exclui();
int main(int, char **) {
int opcao;
FILE *agenda;
do{
cout <<"\n\n|------------Menu de opções------------|\n\n";
cout <<"1 - Criar nova agenda\n";
cout <<"2 - Cadastrar um contato\n";
cout <<"3 - Excluir a agenda\n";
cout <<"4 - Buscar um contato pelo nome\n";
cout <<"5 - Imprimir a agenda\n";
cout <<"6 - Encerrar o programa\n\n";
cout <<"\n|--------------------------------------|\n\n\n";
cout <<"Informe uma opção: ";
cin >> opcao;
switch(opcao){
case 1:
agenda = fopen ("i:\\Agenda.txt", "w");
if (agenda == NULL) {
printf ("Houve um erro ao abrir o arquivo.\n");
return 1;
}
printf ("\n\nAgenda criada com sucesso!\n\n");
fclose(agenda);
break;
case 2:
int x;
agenda = fopen ("j:\\Agenda.txt", "a");
if (agenda == NULL) {
printf ("Houve um erro ao abrir o arquivo.\n");
return 1;
}
cout << "\nInforme a quantidade que deseja cadastrar: ";
cin >> x;
for(int i=0; i<x; i++){
contato cont[x];
cout<<"\nInforme o nome: ";
cin>> cont[i].nome;
cout<<"Informe o endereço: ";
cin>> cont[i].end;
cout<<"Informe o telefone: ";
cin>> cont[i].tel;
fprintf(agenda,"\nNome: %s\n",cont[i].nome);
fprintf(agenda,"Endereço: %s\n",cont[i].end);
fprintf(agenda,"Telefone: %s\n",cont[i].tel);
}
fclose (agenda);
break;
case 3:
exclui();
break;
case 4:
busca();
break;
case 5:
le();
break;
}
} while(opcao != 6);
cout << "\n\n\n\ Programa encerrado!";
}
Programa em C++ usando arquivos que cria e lê um arquivo
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
using namespace std;
struct contato{
char nome[40];
char end[100];
char tel[15];
};
void busca();
void le();
void exclui();
int main(int, char **) {
int opcao;
FILE *arquivo;
do{
cout <<"\n\n|------------Menu de opções------------|\n\n";
cout <<"1 - Criar um arquivo\n";
cout <<"2 - Ler um arquivo\n";
cout <<"3 - Encerrar o programa\n\n";
cout <<"\n|--------------------------------------|\n\n\n";
cout <<"Informe uma opção: ";
cin >> opcao;
switch(opcao){
case 1:
arquivo = fopen ("D:\\Arquivo.txt", "w");
if (arquivo == NULL) {
printf ("Houve um erro ao abrir o arquivo.\n");
return 1;
}
printf ("Arquivo criado com sucesso.\n");
fprintf(arquivo,"Teste gravação");
fclose (arquivo);
break;
case 2:
int c;
if((arquivo = fopen("D:\\arquivo.txt", "r")) == NULL)
{
perror("Erro: fopen");
exit(EXIT_FAILURE);
}
while((c = fgetc(arquivo)) != EOF)
printf("Caractere lido: %c\n", c);
fclose(arquivo);
break;
}
} while(opcao != 3);
cout << "\n\n\n\Programa encerrado!";
}
Metodo bolha de busca em c++ completo com menude opções
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#define qtde 8
using namespace std;
main()
{
int vetor[qtde], x = 0,
y = 0,
aux = 0;
int opcao;
FILE *agenda;
do{
cout <<"\n\n|------------Menu de opções------------|\n\n";
cout <<"1 - Criar o vetor\n";
cout <<"2 - Ordenar de forma cresceste\n";
cout <<"3 - Ordenar de forma decrescente\n";
cout <<"4 - Encerrar o programa\n\n";
cout <<"\n|--------------------------------------|\n\n\n";
cout <<"Informe uma opção: ";
cin >> opcao;
switch(opcao){
case 1:
for( x = 0; x < qtde; x++ )
{
printf("\nEntre com um inteiro para vetor[%d]: ",x);
scanf("%d",&aux);
vetor[x] = aux;
}
break;
case 2:
// coloca em ordem crescente (1,2,3,4,5...)
for( x = 0; x < qtde; x++ )
{
for( y = x + 1; y < qtde; y++ )
// sempre 1 elemento à frente
{
// se o (x > (x+1)) então o
//x passa pra frente (ordem crescente)
if ( vetor[x] > vetor[y] )
{
aux = vetor[x];
vetor[x] = vetor[y];
vetor[y] = aux;
}
}
} // fim da ordenação
// exibe elementos ordenados
printf("\n\n Elementos ordenados (Crescente):");
for( x = 0; x < qtde; x++ )
{
printf("\n vetor[%d] = %d",x,vetor[x]);
// exibe o vetor ordenado
}
break;
case 3:
// coloca em ordem decrescente (10,9,8,7...)
for( x = 0; x < qtde; x++ )
{
for( y = x + 1; y < qtde; y++ )
// sempre 1 elemento à frente
{
if ( vetor[y] > vetor[x] )
{
aux = vetor[y];
vetor[y] = vetor[x];
vetor[x] = aux;
}
}
} // fim da ordenação
// exibe elementos ordenados
printf("\n\n Elementos ordenados (Decrescente):");
for( x = 0; x < qtde; x++ )
{
printf("\n vetor[%d] = %d",x,vetor[x]);
// exibe o vetor ordenado
}
break;
}
} while(opcao != 4);
cout << "\n\n\n\ Programa encerrado!";
}
Programa quicksort c++ que gera o vetor aleatório ou definido e imprime completo com o main/separa/quicksort
QUICKSORT
segunda-feira, 18 de novembro de 2013
Cronometro / contador regressivo em HTML e CSS
Cronometro / contador regressivo
Começa a pisca trocar de cor quando faltar 10minCopia e cola o codigo html no Bloco de Notas e salva da seguinte forma:
nomedoarquivo.html
Copiar e cola o Código CSS los hum Documento Fazer Bloco de Notas e salva da seguinte forma:
estilo.css
Os Dois TEM Que Estar Salvo na MESMA pasta
Parte HTML
<DOCTYPE html PUBLIC "- / / W3C / / DTD XHTML 1.0 Transitional / / EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="estilo.css" type="text/css" rel="stylesheet" />
<title> Documento sem título </ title>
<script>
SEGUNDOS var = ;/ 70/1800; / / Inicio fazer cronometro
função formatatempo (segs) {
min = 0;
hr = 0;
/ *
se hr <10 então hr = "0" & hr
se min <10 min, em seguida = "0" & min
se segs <10 então segs = "0" e segs
* /
while (segs> = 60) {
if (segs> = 60) {
segs = segs-60;
min = min +1;
}
}
while (min> = 60) {
if (min> = 60) {
min = min-60;
hr = 1 hr;
}
}
if (FC <10) {hr = "0" + h}
if (min <10) {min = "0" + min}
if (segs <10) {segs = "0" + segs}
fin = h + ":" + min + ":" + segs
voltar fin;
}
<- Função Conta () {
<- SEGUNDOS -;
!.. <- Documento getElementById ("contador") innerHTML = formatatempo (SEGUNDOS);
<-!}
Conta função () {
SEGUNDOS -;
var ritmo = formatatempo (SEGUNDOS);
if (0 min ==) {
. document.getElementById ("contador") style.color = "vermelho";
document.getElementById ("contador") innerHTML =''.;
setTimeout (function () {
document.getElementById ("contador") innerHTML = ritmo.;
}, 500
);
if (SEGUNDOS == 0) {
alert ("Tempo de Apresentação esgotado!");
n ();
stop ();
}
} Else {
document.getElementById ("contador") innerHTML = ritmo.;
}
}
Inicia a função () {
if (SEGUNDOS == 0) {
alert ("Tempo de Apresentação esgotado!");
clearInterval (intervalo);
stop ();
} Else {
intervalo = setInterval ("Conta ();", 1000);}
}
função para () {
clearInterval (intervalo);}
função zera () {
clearInterval (intervalo);
SEGUNDOS = 1800;
. document.getElementById ("contador") style.color = "branco";
. document.getElementById ("contador") innerHTML = formatatempo (SEGUNDOS);
}
</ Script>
<- <script>
SEGUNDOS var = 1800
var VELOCIDADE = 1000;
var valor = 1;
função pisca () {
SEGUNDOS -;
if (valor == 1) {
counter.innerHTML = formatatempo (SEGUNDOS);
valor = 0;
} Else {
counter.innerHTML = "";
valor = 1;
}
setTimeout ("pisca ();", VELOCIDADE);
}
</ Script> ->
<script>
local var = "cronometro"
/ * VALORES = liga UO Desliga * /
var Alerta = "Desliga"
if (screen.width == 1280 && == Screen.Height 1024)
{This.location = local + '1280x1024. Html '}
if (screen.width == 1280 && == Screen.Height 960)
{This.location = local + '1280x960. Html '}
if (screen.width == 1280 && == Screen.Height 768)
{This.location = local + '1280x768. Html '}
if (screen.width == 1280 && == Screen.Height 720)
{This.location = local + '1280x720. Html '}
if (screen.width == 1152 && == Screen.Height 864)
{This.location = local + '1152x864. Html '}
if (screen.width == 1024 && == Screen.Height 768)
{Top.location = local + '1024x768. Html '}
if (screen.width == 848 && Screen.Height == 480)
{This.location = local + '848x480. Html '}
if (screen.width == 800 && Screen.Height == 600)
{This.location = local + '800x600. Html '}
if (screen.width == 640 && Screen.Height == 480)
{This.location = local + '640x480. Html '}
if (Alerta == 'liga') {
alert ('SUAS configurações de video FORAM detectadas com Êxito:' + screen.width + '×' + Screen.Height + 'pixels \ n \ nRedirecionando ...')}
else {}
</ Script>
</ Head>
<Onload corpo = "pisca ();" >
<div id="imagem" align="center">
<div id="a"> </ div>
<div id="b"> <img src="imagens/3 Oficina Engenharia.png" width="800" height="450" /> </ div>
<div id="a"> </ div>
</ Div>
<div id="dir">
<div id="logo">
</ Div>
<div id="cronometro" align="center">
<span id="counter" class="blink"> 00:30:00 </ span> <br />
<div> <input type="button" value="Parar" onclick="para();">
<input type="button" value="Iniciar" onclick="inicia();">
<input type="button" value="Recomeçar" onclick="zera();"> </ div>
</ Div>
</ Div>
</ Body>
</ Html>
Parte CSS
body {margin: 0px;
border: 0px;
altura: 100%;
background-size: 100%;
font-size: 110px;
fonte: Arial, Helvetica, sans-serif;
/ * Inicio se degradam do Corpo * /
background-color: # 2F2727;
background-image: url (images / radial_bg.png);
background-position: center;
background-repeat: no-repeat;
/ * Safari 4-5, 1-9 Chrome * / / * Não é possível especificar um tamanho de porcentagem? Laaaaaame. * /
background:-webkit-gradiente (radial, centro, 0, centro, 460, a partir de (# 1a82f7), para (# 2F2727));
/ * Safari 5.1 +, Chrome 10 + * /
background:-webkit-radial-gradiente (círculo, # 1a82f7, # 2F2727);
/ * Firefox 3.6 + * /
background:-moz-radial-gradiente (círculo, # 1a82f7, # 2F2727);
/ * IE 10 * /
fundo:-ms-radial-gradiente (círculo, # 1a82f7, # 2F2727);
/ * Fim se degradam do Corpo * /}
corpo, html {
altura: 100%;
width: 100%;
}
# Imagem {
width: 65%;
altura: 100%;
float: left;
vertical-align: central;
}
# Dir {width: 35%;
altura: 100%;
float: right;}
# {Cronometro
width: 100%;
altura: 20%;
font-size: 90px;
font-family: "Arial Black", Gadget, sans-serif;
color: # FFF;
line-height: 50px;
text-decoration: blink;
}
# {Logotipo
width: 100%;}
SEGUNDOS var = 3600 ;/ / 1800; / / Inicio Fazer cronometro
função formatatempo (segs) {
min = 0;
hr = 0;
/ *
se FC <10 entao hr = "0" e hr
Si min <10 min, em SEGUIDA = "0" & min
segs si <10 Segs entao = "0" E Segs
* /
while (segs> = 60) {
if (segs> = 60) {
segs = segs-60;
min = min +1;
}
}
while (min> = 60) {
if (min> = 60) {
min = min-60;
hr = 1 Hora;
}
}
if (FC <10) {hr = "0" + h}
if (min <10) {min = "0" + min}
if (segs <10) {segs = "0" + segs}
fin = h + ":" + min + ":" + Segs
voltar fin;
}
<- Função Conta () {
<- SEGUNDOS -;
! .. <- Documento getElementById ("contador") innerHTML = formatatempo (SEGUNDOS);
<-!}
Conta função () {
SEGUNDOS -;
var ritmo = formatatempo (SEGUNDOS);
if (SEGUNDOS <= 600) {
. document.getElementById ("contador") style.color = "# 2FFF2F";
document.getElementById ("contador") innerHTML =''.;
setTimeout (function () {
document.getElementById ("contador") innerHTML = ritmo.;
}, 500
);
if (SEGUNDOS <= 300) {
. document.getElementById ("contador") style.color = "# FFFA1A";
document.getElementById ("contador") innerHTML =''.;
setTimeout (function () {
document.getElementById ("contador") innerHTML = ritmo.;
}, 500
);
if (SEGUNDOS <= 150) {
. document.getElementById ("contador") style.color = "# FF0F09";
document.getElementById ("contador") innerHTML =''.;
setTimeout (function () {
document.getElementById ("contador") innerHTML = ritmo.;
}, 500
);
if (SEGUNDOS == 0) {
. document.getElementById ("contador") innerHTML = formatatempo (SEGUNDOS);
n ();
stop ();
}}}
} Else {
document.getElementById ("contador") innerHTML = ritmo.;
}
}
Inicia UMA função () {
if (SEGUNDOS == 0) {
alert ("Tempo de Apresentação esgotado!");
stop ();
}
Intervalo = setInterval ("Conta ();", 1000);
}
função para () {
if (SEGUNDOS == 0) {
clearInterval (Intervalo);
alert ("Tempo de Apresentação esgotado!")}
else {
clearInterval (Intervalo);}
}
função zera () {
clearInterval (Intervalo);
SEGUNDOS = 3600;
. document.getElementById ("contador") innerHTML = formatatempo (SEGUNDOS);
. document.getElementById ("contador") style.color = "Branco";
}
Script>
Head>
td>
Tr>
Table>
Div>
Tr>
Table>
Div>
Div>
Body>
Html>
body {
margin: 0px;
border: 0px;
Altura: 100%;
background-size: 100%;
font-size: 110px;
fonte: Arial, Helvetica, sans-serif;
/ * Inicio se degradam do Corpo * /
background-color: # 2F2727;
background-image: url (images / radial_bg.png);
background-position: center;
background-repeat: no-repeat;
/ * Safari 4-5, 1-9 Chrome * / / * Localidade: Não E Possível Localidade: Não Especificado hum tamanho de porcentagem? Laaaaaame. * /
background:-webkit-gradiente (radial, centro, 0, centro, 460, a Partir de (# 1a82f7), Pará (# 2F2727));
/ * Safari 5.1 +, Chrome 10 + * /
background:-webkit-radial-gradiente (Círculo, # 1a82f7, # 2F2727);
/ * Firefox 3.6 + * /
background:-moz-radial-gradiente (Círculo, # 1a82f7, # 2F2727);
/ * IE 10 * /
Fundo:-ms-radial-gradiente (Círculo, # 1a82f7, # 2F2727);
/ * Fim se degradam do Corpo * /}
Corpo, html {
Altura: 100%;
width: 100%;
}
# Imagem {
width: 100%;
Altura: 30%;
vertical-align: central;
}
# {Cronometro
width: 100%;
Altura: 50%;
font-size: 250px;
font-family: Arial Black, Gadget, sans-serif;
color: # FFF;
text-decoration: blink;
}
# {BOTOES
width: 100%;
font-size: 30px;
font-family: "Arial Black", Gadget, sans-serif;
color: # FFF;
text-decoration: blink;
}
# {Logotipo
width: 100%;
height: 70%;
}
# A {
width: 100%;
height: 2%;
}
# Contador {text-decoration: blink;}
div>
<- 00:30:00 -> span>
td>
Parte CSS