Академический Документы
Профессиональный Документы
Культура Документы
2) problema de sobrecarga
#include<iostream>
using namespace std;
//Definiendo las funciones
void PrimeraClase(int x[],int n,int &may,int &p)
{ int i;
for(i=0,may=-100000;i<n;i++)
if(x[i]>may)
{ may=x[i];
p=i;
}
}
bool PrimeraClase(char t)
{if((t>='A' && t<='Z') ||(t>='a' && t<='z'))
return true;
else
return false;
}
void PrimeraClase(int n,int &m)
{int d; m=0;
for(;n>0;n=n/10)
{ d=n%10;
if(d%2!=0)
m=m+d;
}
}
void LeerDatos(int x[],int &n, int &n1,char &z)
{ int i;
cout<<"Cuantos elementos del vector:";
cin>>n;
for(i=0;i<n;i++)
{ cout<<"A["<<i<<"]=";
cin>>x[i];
}
cout<<"\nIng. numero entero:";cin>>n1;
cout<<"Ingrese caracter:";cin>>z;
}
void Mostrar(int may,int p,bool t,int d)
{ cout<<"Elemento mayor:"<<may<<endl;
cout<<"La posicion es:"<<p<<endl;
cout<<"Suma de digitos impares es:"<<d<<endl;
if(t==true)
cout<<"Es alfabetico"<<endl;
else
cout<<"No es alfabetico"<<endl;
}
//Funcion principal
int main()
{int a[100],ne,mayor,pos,nu,si;
char car;
bool q;
LeerDatos(a,ne,nu,car);
PrimeraClase(a,ne,mayor,pos);
q=PrimeraClase(car);
PrimeraClase(nu,si);
Mostrar(mayor,pos,q,si);
}
Problema propuesto
%%%%%%%%%%
% %
% %
%%%%%%%%%%
b) void Semestre2018-1(float c[],int n,float prom, int k).-En c recibe las co
mpras hecha por una empresa, n indica la cantidad de compras. En prom retorna
el promedio de compras y en k la cantidad de compras que sean inferiores al p
romedio de compras.
*/
#include<iostream>
using namespace std;
#define HORAS_T 40
#define PROGRAMA int main()
#define INICIO {
#define FIN }
#define ESCRIBIR(s) cout<<s
#define LEER(nh,th) cin>>nh>>th
#define SI(nh,th) if(nh>HORAS_T)\
pago=HORAS_T*th+(nh-HORAS_T)*th*1.3;\
else\
pago=nh*th;
#define DECLARAR float nh,th,pago
//Programa principal
PROGRAMA
INICIO
DECLARAR;
ESCRIBIR("Ingrese horas trabajadas y tarifa:");
LEER(nh,th);
SI(nh,th)
ESCRIBIR("El pago es = ");
ESCRIBIR(pago);
FIN
Aplicación de directiva preprocesador con libreria-pago trabajador
#include<iostream>
using namespace std;
#include "MiLiber.h"
//Programa principal
PROGRAMA
INICIO
DECLARAR;
ESCRIBIR("Ingrese horas trabajadas y tarifa:");
LEER(nh,th);
SI(nh,th)
ESCRIBIR("El pago es = ");
ESCRIBIR(pago);
FIN
SEMANA 2
SEMANA 3