NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

reporte
#include <iostream>
#include <fstream>
using namespace std;
typedef char String[31];
struct Reg{
int Cod;
String Nomb;
float pp;
int ep;
int ef;
};
//Función promedio
float prom(Reg r){
return((r.pp+r.ep+r.ef)/3);
}
int main(){
Reg dato;
ifstream ent;
int i,n,ind;
ent.open("ALUMNOS.DAT");
if(!ent){
cout<<"Error al abrir el archivo..."<<endl;
}
else{
ent.seekg(0,ent.end);
n=ent.tellg()/sizeof(Reg);
ent.seekg(0);
ifstream e;
e.open("INDICE.DAT");
if(!e){
cout<<"Error al abrir el archivo de indices...";
}
else{
for(i=0; i<n; i++){
e.seekg(i*sizeof(int));
e.read((char*)&ind,sizeof(int));
ent.seekg(ind*sizeof(Reg));
ent.read((char*)&dato,sizeof(Reg));
cout<<dato.Cod<<"t"<<dato.Nomb<<"t"<<prom(dato)<<endl;
}
e.close();
}
ent.close();
}
return 0;
}
/*Ordenar el archivo ALUMNOS.DAT mediante un archivo de índices*/
#include <iostream>
#include <fstream>
using namespace std;
typedef char String[31];
struct Reg{
int Cod;
String Nomb;
float pp;
int ep;
int ef;
};
//Función promedio
float prom(Reg r){
return((r.pp+r.ep+r.ef)/3);
}
int main(){
Reg d1,d2;
int i,j,i1,i2,n;
ifstream ent;
ent.open("ALUMNOS.DAT");
if(!ent){
cout<<"Error al arbrir el archivo...";
}
else{
ent.seekg(0,ent.end);
n=ent.tellg()/sizeof(Reg);
ent.seekg(0);
ofstream sal;
sal.open("INDICE.DAT");
if(!sal){
cout<<"Error al crear el archivo...";
}
else{
for(i=0; i<n; i++){
sal.write((char*)&i,sizeof(int));
}
sal.close();
}
//ordenando mediante el archivo de índices
fstream indice;
indice.open("INDICE.DAT",ios::in | ios::out);
if(!indice){
cout<<"Error al arbrir el archivo...";
}
else{
for(i=0; i<n-1; i++){
for(j=i+1; j<n; j++){
indice.seekg(i*sizeof(int));
indice.read((char*)&i1,sizeof(int));
indice.seekg(j*sizeof(int));
indice.read((char*)&i2,sizeof(int));
ent.seekg(i1*sizeof(Reg));
ent.read((char*)&d1,sizeof(Reg));
ent.seekg(i2*sizeof(Reg));
ent.read((char*)&d2,sizeof(Reg));
if(prom(d1)<prom(d2)){
indice.seekp(i*sizeof(int));
indice.write((char*)&i2,sizeof(int));
indice.seekp(j*sizeof(int));
indice.write((char*)&i1,sizeof(int));
}
}
}
indice.close();
}
ent.close();
}
return 0;
}
crea archivo
#include <iostream>
#include <stdio.h>
#include <fstream>
using namespace std;
typedef char String[31];
struct Reg{
int Cod;
String Nomb;
float pp;
int ep;
int ef;
};
int main(){
Reg dato;
String g;
ofstream sal;
int i,n;
cout<<"# de datos:"; cin>>n;
sal.open("ALUMNOS.DAT");
if(!sal){
cout<<"Error al crear el archivo"<<endl;
}
else{
for(i=1; i<=n; i++){
cout<<"Dato #"<<i<<":"<<endl;
cout<<"Codigo:"; cin>>dato.Cod;gets(g);//lee el fin de linea
cout<<"Nombre:"; gets(dato.Nomb);
cout<<"Promedio de practica:"; cin>>dato.pp;
cout<<"Examen parcial:"; cin>>dato.ep;
cout<<"Examen final:"; cin>>dato.ef;
//escribir en el archivo
sal.write((char *)&dato, sizeof(Reg));
}
sal.close();
}
return 0;
}
crea recorre cola
/*Creación y Recorrido de una Cola*/
#include <iostream>
using namespace std;
//Creación del Nodo
struct Nodo{
int Cod;
float pf;
Nodo *punt;
};
Nodo *Cola;
//Función rea Nodo
Nodo *Crea_Nodo(int Cod, float pf){
Nodo *p;
p=new Nodo;
p->Cod=Cod;
p->pf=pf;
p->punt=NULL;
return (p);
}
//Proceso que Crea la Cola
void Crea_Cola(Nodo *&p){
int i,n,Cod;
float pf;
Nodo *q,*r;
cout<<"# de datos:"; cin>>n;
for(i=1; i<=n; i++){
cout<<"Dato #"<<i<<":"<<endl;
cout<<"Codigo:"; cin>>Cod;
cout<<"Promedio final:"; cin>>pf;
if(p==NULL){
p=Crea_Nodo(Cod,pf);
r=p;
}
else{
q=Crea_Nodo(Cod,pf);
r->punt=q;
r=q;
}
}
}
//proceso recorre la Cola
void Recorre(Nodo *p){
while(p!=NULL){
cout<<p->Cod<<"t"<<p->pf<<endl;
p=p->punt;
}
}
int main(){
Cola=NULL;
//llamar a Crea Cola
Crea_Cola(Cola);
//llamar a Recorre
Recorre(Cola);
return 0;
}
/*Creación y recorrido de una lista en forma recursiva*/
#include <iostream>
using namespace std;
//Creación del Nodo
struct Nodo{
int Cod;
float pf;
Nodo *punt;
};
Nodo *Lista;
//Proceso que crea nodo
void Crea_Nodo(Nodo *&p, int Cod, float pf){
if(p==NULL){
p=new Nodo;
p->Cod=Cod;
p->pf=pf;
p->punt=NULL;
}
else{
Crea_Nodo(p->punt,Cod,pf);
}
}
//Proceso de Recorre Lista
void Recorre(Nodo *p){
if(p!=NULL){
cout<<p->Cod<<"t"<<p->pf<<endl;
Recorre(p->punt);
}
}
int main(){
Lista=NULL;
int i,n,Cod;
float pf;
cout<<"# de datos:"; cin>>n;
for(i=1; i<=n; i++){
cout<<"Dato #"<<i<<":"<<endl;
cout<<"Codigo:"; cin>>Cod;
cout<<"Promedio final:"; cin>>pf;
//Llamar a Crea Nodo
Crea_Nodo(Lista,Cod,pf);
}
//llamra a Recorre
Recorre(Lista);
return 0;
}
/*Creación y recorrido de una PILA*/
#include <iostream>
using namespace std;
//Creación del Nodo
struct Nodo{
int Cod;
float pf;
Nodo *punt;
};
Nodo *p, *q;
int main(){
int i, n;
int Cod;
float pf;
p=NULL;
//Creación de la Pila
cout<<"# de datos:"; cin>>n;
for(i=1; i<=n; i++){
cout<<"Dato #"<<i<<":"<<endl;
cout<<"Codigo:"; cin>>Cod;
cout<<"Promedio final:"; cin>>pf;
if(p==NULL){
p=new Nodo;
p->Cod=Cod;
p->pf=pf;
p->punt=NULL;
}
else{
q=new Nodo;
q->Cod=Cod;
q->pf=pf;
q->punt=p;
p=q;
}
}
//Recorrido de la Pila
while(p!=NULL){
cout<<p->Cod<<"t"<<p->pf<<endl;
p=p->punt;
}
return 0;
}
/*Creación y recorrido de una PILA, empleando subrogramas*/
#include <iostream>
using namespace std;
//Creación del Nodo
struct Nodo{
int Cod;
float pf;
Nodo *punt;
};
Nodo *Pila;
//Función rea Nodo
Nodo *Crea_Nodo(int Cod, float pf){
Nodo *p;
p=new Nodo;
p->Cod=Cod;
p->pf=pf;
p->punt=NULL;
return (p);
}
//Proceso que crea la Pila
void Crea_Pila(Nodo *&p){
int i,n,Cod;
float pf;
Nodo *q;
cout<<"# de datos:"; cin>>n;
for(i=1; i<=n; i++){
cout<<"Dato #"<<i<<":"<<endl;
cout<<"Codigo:"; cin>>Cod;
cout<<"Promedio final:"; cin>>pf;
if(p==NULL){
p=Crea_Nodo(Cod,pf);
}
else{
q=Crea_Nodo(Cod,pf);
q->punt=p;
p=q;
}
}
}
//proceso recorre la Pila
void Recorre(Nodo *p){
while(p!=NULL){
cout<<p->Cod<<"t"<<p->pf<<endl;
p=p->punt;
}
}
int main(){
Pila=NULL;
//llamar a Crea Pila
Crea_Pila(Pila);
//llamar a Recorre
Recorre(Pila);
return 0;
}



     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.