int main () { double vel0[3]; double dt =1e-3; vel0[0]=vel0[1]=vel0[2]=1.0; double w0[3]; w0[0]=w0[1]=w0[2]=0.0; w0[2]=1; Physics::Obliquous ob(Physics::Vector3D(), Physics::Vector3D(vel0), Physics::Vector3D(w0), 6e-3, 4e-4, dt); { ob.pos = Physics::Vector3D(); ob.vel = Physics::Vector3D(vel0); std::ofstream saida("RK1.dat"); while(ob.pos.GetElem(2) >= 0) { ob.RK1(); saida << ob.pos << std::endl; } } { ob.pos = Physics::Vector3D(); ob.vel = Physics::Vector3D(vel0); std::ofstream saida("RK2.dat"); while(ob.pos.GetElem(2) >= 0) { ob.RK2(); saida << ob.pos << std::endl; } } { ob.pos = Physics::Vector3D(); ob.vel = Physics::Vector3D(vel0); std::ofstream saida("RK4.dat"); while(ob.pos.GetElem(2) >= 0) { ob.RK4(); saida << ob.pos << std::endl; } } { ob.pos = Physics::Vector3D(); ob.vel = Physics::Vector3D(vel0); std::ofstream saida("VelocityVerlet.dat"); while(ob.pos.GetElem(2) >= 0) { ob.VelocityVerlet(); saida << ob.pos << std::endl; } } }
int main(int argc, char **argv) { char **matrix; /* Matriz auxiliar */ /* Verifica se um argumento foi passado na * linha de comando */ if(argc != 2) { printf("\n%s\n", usage_message); return EXIT_FAILURE; } /* Recebe entrada a partir do nome do arquivo */ if((matrix = entrada(argv[1])) == NULL) { printf("\n%s\n", error_message); return EXIT_FAILURE; } /* Converte mneumônicos do HIPO em código de * máquina a partir da sintaxe correta */ if((matrix = analyse_convert(matrix)) == NULL) { printf("\n%s\n", error_message); return EXIT_FAILURE; } /* Cria o arquivo de saída (extensão .hip) */ saida(matrix, last_line, argv[1]); return EXIT_SUCCESS; }
void ListaGeometria::salvar () { ofstream saida ("./geometrias.dat", ios::out); if (!saida) { cout << "Arquivo nao pode ser aberto." << endl; cout << "Pressione uma tecla para continuar." << endl; cout << ">> "; cin.get (); return; } if (lista.size() > 0) { list<Geometria *>::const_iterator it; //string s = writer->write ((*it)->getGeometria()); for (it = lista.begin(); it != lista.end(); it++) { saida << (*it)->getTipo() << writer->write ((*it)->getGeometria()) << endl; } cout << endl << "Gravacao encerrada com sucesso." << endl; } else { cout << endl << "Nenhuma geometria cadastrada." << endl; } saida.close(); cout << endl << "Pressione uma tecla para continuar." << endl; cout << ">> "; cin.get (); return; }
bool ClassificadorAdaboostM1::gravarConhecimento( string arquivo ) { //return false; ofstream saida(arquivo.c_str()); if(!saida.is_open()) { return false; } for (unsigned int i = 0; i < valores.size() - 1; i++) saida << '"' << valores[i] << "\" "; saida << '"' << valores[valores.size() - 1] << '"' << endl; int iteracoes = betas.size(); saida << iteracoes << ' '; for (int i = 0; i < iteracoes - 1; i++) { saida << betas[i] << ' '; } saida << betas[iteracoes-1] << endl; saida << typeid(*(classificadores[0])).name(); string extensao = arquivo.substr(arquivo.rfind("."),arquivo.length()); arquivo = arquivo.substr(0, arquivo.rfind(".")); for (int i = 0; i < iteracoes; i++) { ostringstream os; os << arquivo << i << extensao; classificadores[i]->gravarConhecimento(os.str()); } return true; }
void trata_sinal (int sinal) { if (sinal != 15) printf ("\nRecebi sinal: %d\n",sinal); else // Quando receber um SIGTERM, o processo termina normalmente atexit(saida()); }
/*Faz o parse na string de entrada*/ int parse(char *input){ /*Testa se a string esta vazia = enter limpo*/ if(input[0]=='\n') return 5; /*Amputa o \n. Aponta pro input */ input[strlen(input)-1]=0; char *s = input; /*Setta flag de processo em background = 0*/ bgflag=0; int countsize, narg = 0; int i = 0; /*Roda ate o fim dos parametros ou numero max_par atingido*/ for (narg = 0; narg < MAX_PAR; narg++){ char tmp[MAX_PAR_SIZE] = {}; countsize = 0; /*Ignora espaços repetidos*/ while (s[i] == ' ') i++; if ((s[i] == '&')){ /*Se encontrou &, ignora e setta flag pra nao dar wait no executa_processo*/ if (i==0) return 3; bgflag=1; i++; } while(s[i] != ' '){ if ((s[i] == '\0')) break; if ((s[i] != '&')){ strncat(tmp, &s[i],1); i++; countsize++; } else { /*Se encontrou & grudado em comando, setta flag*/ bgflag=1; break; } } /*Se estourou tamanho maximo de parametros*/ if (countsize > MAX_PAR_SIZE) return 1; /*Se tmp = \0. Se caiu no caso do & no final da string*/ if (!strcmp(tmp, "\0")) { iovet = saida(narg-1); if(iovet){ iorflag=1; } return 0; } /*Checa integridade de argv[] e aloca*/ if(args[narg] == NULL) args[narg] = malloc(strlen(tmp)+1); else bzero(args[narg], strlen(args[narg])); /*Copia parametro lido pra args[]*/ strncpy(args[narg], tmp, strlen(tmp)); strncat(args[narg], "\0", 1); } if (narg >= MAX_PAR) return 2; return 0; }
void Mapa::GeraSaida() { int ind = 1 + ( rand() % (getTam() - 3)); Posicao saida(ind, getTam() - 1); setPosSaida(saida); int x = getPosSaida().getX(); int y = getPosSaida().getY(); int pos = ind * getTam() + (getTam() - 1); getCasa()[pos].setSprite(SAIDA_SPRITE); getCasa()[pos].setTipo(SAIDA_TIPO); }
void main (void){ leitura(); if ( N <= 0 ) { printf("A QUANTIDADE DE TERMOS DEVE SER MAIOR QUE ZERO"); } else { processamento(); saida(); } }
//----------------------------------------------------------- void ConfBaseWidget::salvarConfiguracao(const QString &id_conf) { QString buf, //Configura o nome do arquivo de modelo (esquema) de configuração nome_arq_sch=AtributosGlobais::DIR_CONFIGURACOES + AtributosGlobais::SEP_DIRETORIO + AtributosGlobais::DIR_ESQUEMAS + AtributosGlobais::SEP_DIRETORIO + id_conf + AtributosGlobais::EXT_ESQUEMA, //Configura o nome do arquivo de configuração nome_arq=AtributosGlobais::DIR_CONFIGURACOES + AtributosGlobais::SEP_DIRETORIO + id_conf + AtributosGlobais::EXT_CONFIGURACAO; QFile saida(nome_arq); map<QString, QString> atribs; map<QString, map<QString, QString> >::iterator itr, itr_end; try { itr=params_config.begin(); itr_end=params_config.end(); while(itr!=itr_end) { atribs.insert((itr->second).begin(), (itr->second).end()); itr++; } //Gera o modelo de configuração com base nos parâmetros atuais buf=ParserEsquema::obterDefinicaoObjeto(nome_arq_sch, atribs); //Abre o arquivo de configuração para gravação saida.open(QFile::WriteOnly); //Caso não consiga abrir o arquivo para gravação if(!saida.isOpen()) throw Excecao(Excecao::obterMensagemErro(ERR_PGMODELER_ARQNAOGRAVADO).arg(QString::fromUtf8(nome_arq)), ERR_PGMODELER_ARQNAOGRAVADO,__PRETTY_FUNCTION__,__FILE__,__LINE__); //Grava o buffer gerado no arquivo saida.write(buf.toStdString().c_str(), buf.size()); saida.close(); } catch(Excecao &e) { if(saida.isOpen()) saida.close(); throw Excecao(Excecao::obterMensagemErro(ERR_PGMODELER_ARQNAOGRAVADODEFINV).arg(QString::fromUtf8(nome_arq)), ERR_PGMODELER_ARQNAOGRAVADODEFINV,__PRETTY_FUNCTION__,__FILE__,__LINE__, &e); } }
void save( char file[]) { ofstream saida( file); for( num k=0; k<size()-1; k++) { for( num t=k+1; t<size(); t++) { if( connected(k,t)) { saida << node(k).real() << " " << node(k).imag() << endl; saida << node(t).real() << " " << node(t).imag() << endl; saida << endl; } } } }
void BD::salvaVet(QVector<float> vet, QString arquivo) { QFile _arq(arquivo); #ifdef DEBUG std::cerr << "BD::salvaVet(): salvando " << arquivo.toStdString() << "..." << std::endl; #endif if (!_arq.open(QIODevice::WriteOnly | QIODevice::Text)) { std::cerr << "BD::salvaVet(vet, " << arquivo.toStdString() << "): erro ao abrir o arquivo par escrita." << std::endl; return; } QDataStream saida(&_arq); saida << vet; _arq.close(); }
BD::~BD() { #ifdef DEBUG std::cerr << "BD::~BD() (arq = " << arq.fileName().toStdString() << "):" << std::endl; std::cerr << "\tfdist = " << fDist << std::endl; std::cerr << "\tfext(hist) = " << usaHistograma << std::endl; std::cerr << "\tfext(matco) = " << usaMatrizCoOcorrencia << std::endl; for (auto it = imagens.begin(); it != imagens.end(); it++) std::cerr << "\t\t" << (*it).toStdString() << std::endl; #endif arq.seek(0); arq.resize(0); QTextStream saida(&arq); saida << "fdist = "; switch (fDist) { case 1: saida << "Minkowski"; break; case 2: saida << "ItakuraSaito"; break; case 3: saida << "KullbackLeibler"; break; case 4: saida << "Cosseno"; break; } saida << '\n'; saida << "fext = "; if (usaHistograma) saida << "hist"; if (usaHistograma && usaMatrizCoOcorrencia) saida << ","; if (usaMatrizCoOcorrencia) saida << "matco"; saida << '\n'; for (auto it = imagens.begin(); it != imagens.end(); it++) saida << *it << '\n'; saida.flush(); arq.close(); }
void escreverSaida() { ofstream saida(arq->output.c_str(), ios::out,ios::trunc); saida << "P3" << "\n"; saida << arq->size[0] << " " << arq->size[1] << "\n"; saida << 255 << "\n"; for(int i = 0; i < arq->size[0]; i++){ for(int j = 0; j < arq->size[1]; j++){ double r = (int)(tela[(i*arq->size[1]) + j].x * 255); double g = (int)(tela[(i*arq->size[1]) + j].y * 255); double b = (int)(tela[(i*arq->size[1]) + j].z * 255); saida << r << " " << g << " " << b << "\n"; } } saida.close(); }
void load_entrada_saida(FUNDO*pf,FILE*fp,DATA data, int val,char*op) { int j=0; float valor=0; char str1[MAX]="", str2[MAX]=""; JOGADOR *paux=(JOGADOR*)malloc(sizeof(JOGADOR)*val); for(j=0;j<val;j++) { fscanf(fp,"%[^,] , %[^\n]\n",str1,str2); //o formato %[^,] faz com que a string seja lida até que apareça a vírgula. O formato %[^\n] faz o mesmo até que apareça o new line (paux+j)->nome=(char*)malloc(strlen(str1)+1); strcpy((paux+j)->nome,str1); (paux+j)->clube=(char*)malloc(strlen(str2)+1); strcpy((paux+j)->clube,str2); } if(strcmp(op,"ENTRAM")==0) { insert_string(paux,val-1); //FUNÇÃO QUE ORDENA O BLOCO DE JOGADOR A SER INSERIDO NA ESTRUTURA pf->plantel_ativo+=val; entra(pf,paux,data,val); //REALIZA A INCLUSÃO DOS NOVOS JOGADOR NA ESTRUTURA DEFINITIVA imprime_txt(paux,"ENTRAM",val,data); //IMPRIME EM TXT O RESUMO DA OPERAÇÃO REALIZADA imprime_bin(paux,"ENTRAM",val,data); } else if(strcmp(op,"SAEM")==0) { valor=pf->mealheiro/pf->plantel_ativo; for(j=0;j<val;j++) { saida(pf,(paux+j)->nome,data,valor); } pf->plantel_ativo-=val; imprime_txt(paux,"SAEM",val,data); imprime_bin(paux,"SAEM",val,data); } }
void sonora::salvar_arquivo(QString caminho) { try { if (!Composicao_Criada) throw(Erros(parent,Erros::ErroComposicaoInexistente)); QFile *Arquivo = new QFile(caminho); try { if (!(Arquivo->open(QIODevice::WriteOnly | QIODevice::Text))) throw(Erros(parent,Erros::ErroArquivoInacessivel)); QTextStream saida(Arquivo); saida << Num_Notas << "\n"; for (int i=0;i<Num_Notas;i++) { saida << Musica[i][0] << "\n" << Musica[i][1] << "\n" << Musica[i][2] << "\n"; } } catch (Erros E) { E.mostra_msg(); } } catch (Erros E) { E.mostra_msg(); } }
void load_entrada_saida_bin(FUNDO*pf,FILE*fp,DATA data, int val,char*op) { int j=0,size1=0,size2=0,n=0; float valor=0; JOGADOR *paux=(JOGADOR*)malloc(sizeof(JOGADOR)*val); for(j=0;j<val;j++) { //fscanf(fp,"%[^,] , %[^\n]\n",str1,str2); //o formato %[^,] faz com que a string seja lida até que apareça a vírgula. O formato %[^\n] faz o mesmo até que apareça o new line n=fread(&size1,sizeof(int),1,fp); if(n==1) { (paux+j)->nome=(char*)malloc(size1); } else { printf("load_entrada_saida_bin():ocorreu erro ao tentar copiar o tamanho do nome do jogador\n"); return; } n=fread((paux+j)->nome,sizeof(char)*size1,size1,fp); if(n!=size1) { printf("load_entrada_saida_bin():ocorreu erro ao tentar copiar o nome do jogador\n"); return; } n=fread(&size2,sizeof(int),1,fp); if(n==1) { (paux+j)->clube=(char*)malloc(size2); } else { printf("load_entrada_saida_bin():ocorreu erro ao tentar copiar o tamanho do nome do clube\n"); return; } n=fread((paux+j)->clube,sizeof(char)*size2,size2,fp); if(n!=size1) { printf("load_entrada_saida_bin():ocorreu erro ao tentar copiar o nome do jogador\n"); return; } } if(strcmp(op,"ENTRAM")==0) { insert_string(paux,val-1); //FUNÇÃO QUE ORDENA O BLOCO DE JOGADOR A SER INSERIDO NA ESTRUTURA pf->plantel_ativo+=val; entra(pf,paux,data,val); //REALIZA A INCLUSÃO DOS NOVOS JOGADOR NA ESTRUTURA DEFINITIVA imprime_txt(paux,"ENTRAM",val,data); //IMPRIME EM TXT O RESUMO DA OPERAÇÃO REALIZADA imprime_bin(paux,"ENTRAM",val,data); } else if(strcmp(op,"SAEM")==0) { valor=pf->mealheiro/pf->plantel_ativo; for(j=0;j<val;j++) { saida(pf,(paux+j)->nome,data,valor); } pf->plantel_ativo-=val; imprime_txt(paux,"SAEM",val,data); imprime_bin(paux,"SAEM",val,data); } }
int main() { int in1[16] = {0,1,0,0,0,0,0,1,0,1,0,0,1,0,0,0}; //2.640625 - 0100000101001000 int in2[16] = {1,1,0,0,0,0,0,1,0,1,0,0,1,0,0,0}; //2.640625 - 0100000101001000 int out[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int i = 0, j = 0, k = 0; //Variaveis e A int a[11] = {1,0,0,0,0,0,0,0,0,0,0}; int expoente_binario_a[5]; int expoente_a = 0; int sinal_a = 0; //Variaveis de B int b[11] = {1,0,0,0,0,0,0,0,0,0,0}; int expoente_binario_b[5]; int expoente_b = 0; int sinal_b = 0; int deslocamento = 0; int normalizar = 0; int result[11] = {0,0,0,0,0,0,0,0,0}; int formato_saida[10] = {0,0,0,0,0,0,0,0}; int expoente_result[5]; int sinal_result = 0; //Verificar se é Infinito ou Zero int qtd1 = 0; int qtd0 = 0; sinal_a = in1[0]; sinal_b = in2[0]; /****CALCULO DO EXPOENTE A e B*********/ for(j = 1; j <= 5; j++) { expoente_binario_a[i] = in1[j]; i++; } expoente_a = Binario_para_decimal(expoente_binario_a); printf ("Expoente A: %d", expoente_a); i = 0; for(j = 1; j <= 5; j++) { expoente_binario_b[i] = in2[j]; i++; } expoente_b = Binario_para_decimal(expoente_binario_b); printf ("Expoente B: %d\n", expoente_b); /****************************************/ /****SEPARANDO OS DADOS DE ENTRADA PARA A E B*********/ i = 1; for(j = 6; j <= 15; j++) { a[i] = in1[j]; i++; } printf ("Dado a: "); imprimir(a, 11); i = 1; for(j = 6; j <= 15; j++) { b[i] = in2[j]; i++; } printf ("Dado b: "); imprimir(b,11); /***************************************************/ /****CALCULO DO EXPOENTE PARA DESLOCAMENTO*********/ deslocamento = expoente_a - expoente_b; if(deslocamento > 0) shift(b, deslocamento); else if(deslocamento < 0) shift(a, deslocamento); /*************************************************/ /****COMPLEMENTO, SOMA E NORMALIZAÇÃO*********/ if(sinal_b == 1) complemento(b); printf("\nComplemento de B: "); imprimir(b, 11); normalizar = soma(a,b,result); printf("\nNoraliza: %d\n", normalizar); printf ("Resultado da soma: "); imprimir(result, 11); printf("\n"); if(expoente_a >= expoente_b) { for(i = 0; i < 5; i++) expoente_result[i] = expoente_binario_a[i]; } else { for(i = 0; i < 5; i++) expoente_result[i] = expoente_binario_b[i]; } if(normalizar) somaExpoente(expoente_result, normalizar); j = 1; for(i = 0; i < 10; i++) { formato_saida[i] = result[j]; j++; } if(sinal_a == sinal_b) sinal_result = sinal_a; else sinal_result = 1; printf("\nExpoente Result: "); imprimir(expoente_result, 5); /*************************************************/ /*************VERIFICAR INFINITO OU ZERO**********/ for(i = 0; i < 10; i++) { if(formato_saida[i] == 0) qtd0++; } if(qtd0 == 10) { for(i = 0; i < 5; i++) if(expoente_result[i]) qtd1++; if(qtd1 == 5) printf("Infinito"); else printf("0"); } /*************************************************/ else { /****************SAIDA NORMALIZADA*****************/ saida(sinal_result, expoente_result, formato_saida, out); printf("\nOut: "); imprimir(out, 16); }/*************************************************/ return 0; }