Mostrando entradas con la etiqueta desarrollo. Mostrar todas las entradas
Mostrando entradas con la etiqueta desarrollo. Mostrar todas las entradas

miércoles, 10 de julio de 2013

[Ejercicio resuelto c++ POO, Arreglos de objetos] Estudiantes aprobados y reprobados. – Abogado – Teleconferencias

Enunciado:
"Realizar un programa en el que se tenga como entrada: nombre, edad y 3 notas del estudiante con un menú en el que se pueda:
1 - Ingresar los datos de los estudiantes.
2 - Buscar datos del estudiante mediante su nombre.
3 - Informe de datos de los estudiantes ordenado por su nota de menor a mayor y mostrando si ha aprobado o reprobado.
4- Cantidad de estudiantes aprobados, reprobados y promedio de notas de la seccion.
Además guardar el informe y la cantidad de estudiantes aprobados y reprobados junto al promedio de notas en un archivo txt."

Clases:

Estudiante.h

#ifndef ESTUDIANTE_H_
#define ESTUDIANTE_H_

#include iostream
#include string.h
using namespace std;

class Estudiante {
private:
string nombre;
int edad;
float nota1;
float nota2;
float nota3;
public:
Estudiante();
void setnombre(string nom);
string getnombre();
void setedad(int eda);
int getedad();
float getNota1();
void setNota1(float not1);
float getNota2();
void setNota2(float not2);
float getNota3();
void setNota3(float not3);
float Calnotaf();
string CalApRp();
};

#endif /* ESTUDIANTE_H_ */



Estudiante.cpp

#include "Estudiante.h"

Estudiante::Estudiante() {
// TODO Auto-generated constructor stub
nombre = "";
edad = 0;
nota1 = 0;
nota2 = 0;
nota3 = 0;
}

void Estudiante::setnombre(string nom){
nombre = nom;
}

string Estudiante::getnombre(){
return nombre;
}

void Estudiante::setedad(int eda){
edad = eda;
}

int Estudiante::getedad(){
return edad;
}

float Estudiante::getNota1() {
return nota1;
}

void Estudiante::setNota1(float not1) {
nota1 = not1;
}

float Estudiante::getNota2() {
return nota2;
}

void Estudiante::setNota2(float not2) {
nota2 = not2;
}

float Estudiante::getNota3() {
return nota3;
}

void Estudiante::setNota3(float not3) {
nota3 = not3;
}

float Estudiante::Calnotaf() {
float notaf;
notaf = ((nota1 + nota2 + nota3) * 20) /100;
return notaf;
}

string Estudiante::CalApRp() {
string ApRp;
if(Calnotaf() = 10 && Calnotaf()= 20)
ApRp = "Aprobado";
else
if(Calnotaf() = 0 && Calnotaf() 10)
ApRp = "Reprobado";
else
ApRp = "Error al verificar nota";
return ApRp;
}

Seccion.h

#ifndef SECCION_H_
#define SECCION_H_

#include "Estudiante.h"

const int MAX=3;

class Seccion {
private:
int ptr;
Estudiante AEstudiante[MAX];
public:
Seccion();
int getptr();
void setAEstudiante(Estudiante elEstudiante);
Estudiante getAEstudiante(int i);
void OrdenarEstudiante();
int Buscar(string nombreB);
int Calcantap();
int Calcantrep();
float Calpromnot();
};

#endif /* SECCION_H_ */

Seccion.cpp

/*
* Seccion.cpp
*
* Created on: 23/02/2013
* Author: Francisco Velásquez
*/

#include "Seccion.h"

Seccion::Seccion() {
// TODO Auto-generated constructor stub
ptr = 0;
}

int Seccion::getptr(){
return ptr;
}

void Seccion::setAEstudiante(Estudiante elEstudiante){
AEstudiante[ptr] = elEstudiante;
ptr++;
}

Estudiante Seccion::getAEstudiante(int i){
return AEstudiante[i];
}

void Seccion::OrdenarEstudiante(){
Estudiante Aux;
int i, j;
for(i=0; iptr-1; i++){
for (j=i+1; jptr; j++){
if(AEstudiante[i].Calnotaf() AEstudiante[j].Calnotaf())
{
Aux = AEstudiante[i];
AEstudiante[i] = AEstudiante[j];
AEstudiante[j] = Aux;
}
}
}
}

int Seccion::Buscar(string nombreB) {
int i=0, enc = -1;
while(iptr && enc == -1){
if(AEstudiante[i].getnombre() == nombreB)
enc = i;
else i++;
}
return enc;
}

int Seccion::Calcantap() {
int cantap;
int contap=0;
for(int i=0; i ptr; i++){
if(AEstudiante[i].CalApRp() == "Aprobado")
contap++;
}
cantap = contap;
return cantap;
}

int Seccion::Calcantrep() {
int cantrep;
int contrep = 0;
for(int i=0; i ptr; i++){
if(AEstudiante[i].CalApRp() == "Reprobado")
contrep++;
}
cantrep = contrep;
return cantrep;
}

float Seccion::Calpromnot() {
float promnot;
float acum=0;
for(int i = 0; iptr;i++){
acum = acum + AEstudiante[i].Calnotaf();
}
promnot = acum/ptr;
return promnot;
}

Función principal

Principal.cpp

#include "Estudiante.h"
#include "Seccion.h"
#include stdlib.h
#include stdio.h
#include fstream

void IESeccion(Seccion & laSeccion);
void IS(Seccion laSeccion);
void IBuscar(Seccion laSeccion);
void Menu(Seccion laSeccion);
void Msjsalida(Seccion laSeccion);
void EstApRepProm(Seccion laSeccion);

int main(){
Seccion laSeccion;
Menu(laSeccion);
Msjsalida(laSeccion);
return 0;
}

void EstApRepProm(Seccion laSeccion){
cout "La cantidad de estudiantes aprobados es de: " laSeccion.Calcantap() endl;
cout "La cantidad de estudiantes reprobados es de: " laSeccion.Calcantrep() endl;
cout "El promedio de notas es de " laSeccion.Calpromnot() " ptos" endl;
ofstream archivo; // objeto de la clase ofstream
archivo.open("ARP.txt");

archivo "La cantidad de estudiantes aprobados es de: " laSeccion.Calcantap() endl;
archivo "La cantidad de estudiantes reprobados es de: " laSeccion.Calcantrep() endl;
archivo "El promedio de notas es de " laSeccion.Calpromnot() " ptos" endl;

archivo.close();

system("pausenull");
}

void Msjsalida(Seccion laSeccion){
cout endl;
cout endl;
cout endl;
cout endl;
cout endl;
cout endl;
cout endl;
cout endl;
cout endl;
cout endl;
cout " GRACIAS POR USAR FRANCVES SYSTEM" endl;
cout " @francves" endl;
}

void Menu(Seccion laSeccion){
system("cls");
int variable;
cout endl;
cout "BIENVENIDO AL MENU DE USUARIO, PORFAVOR INGRESE UNA DE LAS SIGUIENTES OPCIONES" endl;
cout "______________________________________________________________________________" endl;
cout "1 Ingresar datos (si ya ha ingresado datos anteriormente elija otra opcion)" endl;
cout "2 Buscar datos de estudiante a travez de su nombre" endl;
cout "3 Informe de estudiantes ordenados por su nota de menor a mayor" endl;
cout "4 Cantidad de estudiantes aprobados, reprobados y promedio de notas de la seccion" endl;
cout "0 SALIR" endl;
cin variable;
switch(variable){
case 1:
system("cls");
IESeccion(laSeccion);
Menu(laSeccion);
break;
case 2:
system("cls");
IBuscar(laSeccion);
Menu(laSeccion);
break;
case 3:
system("cls");
IS(laSeccion);
Menu(laSeccion);
break;
case 4:
system("cls");
EstApRepProm(laSeccion);
Menu(laSeccion);
break;
case 0:
system("cls");
Msjsalida(laSeccion);
break;
default:
cout endl;
cout "Porfavor solo ingrese opcion 1 - 2 - 3 - 4 - 0" endl;
break;
}
system("pausenull");
}

void IEEstudiante(Estudiante & elEstudiante){
string nom;
int eda;
float not1, not2, not3;
cout "Ingrese el Nombre del estudiante" endl;
cin nom;
elEstudiante.setnombre(nom);
cout "Ingrese la edad del estudiante" endl;
cin eda;
elEstudiante.setedad(eda);
cout "Ingrese las 3 notas del estudiante una por una" endl;
cin not1;
elEstudiante.setNota1(not1);
cin not2;
elEstudiante.setNota2(not2);
cin not3;
elEstudiante.setNota3(not3);
}

void IESeccion(Seccion & laSeccion){
Estudiante elEstudiante;
for(int i=0; i MAX; i++){
IEEstudiante(elEstudiante);
laSeccion.setAEstudiante(elEstudiante);
laSeccion.OrdenarEstudiante();
}
cout endl;
cout "Se han ingresado todos los datos correctamente " endl;
cout "Presione cualquier tecla para ser redirigido al menu nuevamente" endl;
system("pausenull");
}

void IS(Seccion laSeccion){
int i;
cout " INFORME ESTUDIANTES DE LA SECCION " endl;
cout "__________________________________________________________________________" endl;
cout "Nombre Edad Nota Aprobado/Reprobado" endl;
for(i=0;iMAX;i++){
cout laSeccion.getAEstudiante(i).getnombre() " " laSeccion.getAEstudiante(i).getedad() " " laSeccion.getAEstudiante(i).Calnotaf() " " laSeccion.getAEstudiante(i).CalApRp() endl;
}
cout endl;
cout "Presione cualquiere tecla para regresar al menu" endl;

ofstream archivo;

archivo.open("reporte.txt");

archivo " INFORME ESTUDIANTES DE LA SECCION " endl;
archivo "__________________________________________________________________________" endl;
archivo "Nombre Edad Nota Aprobado/Reprobado" endl;
for(i=0;iMAX;i++){
archivo laSeccion.getAEstudiante(i).getnombre() " " laSeccion.getAEstudiante(i).getedad() " " laSeccion.getAEstudiante(i).Calnotaf() " " laSeccion.getAEstudiante(i).CalApRp() endl;
}
archivo endl;
archivo "Presione cualquiere tecla para regresar al menu" endl;

system("pausenull");
}

void IBuscar(Seccion laSeccion){
Seccion OSeccion;
Estudiante OEstudiante;
string nombreB;
int posi;
cout "Ingrese el nombre a buscar: " endl;
cin nombreB;
posi = laSeccion.Buscar(nombreB);
if(posi != -1){
cout "El nombre existe en la posicion: " posi endl;
cout "La edad es: " laSeccion.getAEstudiante(posi).getedad() endl;
cout "La nota es: " laSeccion.getAEstudiante(posi).Calnotaf() endl;
cout "El estudiante ha " laSeccion.getAEstudiante(posi).CalApRp() " la materia" endl;
}
else{
cout "No existen datos del estudiante " nombreB endl;}
cout endl;
cout "Presione cualquiere tecla para regresar al menu" endl;
system("pausenull");
}

lunes, 1 de julio de 2013

[Ejercicio resuelto c++ POO] Dinero en billetera. – Service – Abogado – Auto

Enunciado:
"Sabiendo cuantos billetes de 5000, 10000, 20000 y 50000 tiene una persona en su billetera, calcular la cantidad total de dinero con que cuenta."

Clases:

Billetera.h


#ifndef BILLETERA_H_
#define BILLETERA_H_

#include iostream

using namespace std;

class Billetera {
private:
int billete1;
int billete2;
int billete3;
int billete4;
int cantbi1;
int cantbi2;
int cantbi3;
int cantbi4;
public:
Billetera();
void setcantbi1(int bi1);
int getcantbi1();
void setcantbi2(int bi2);
int getcantbi2();
void setcantbi3(int bi3);
int getcantbi3();
void setcantbi4(int bi4);
int getcantbi4();
float CaldinTot();
};

#endif /* BILLETERA_H_ */



Billetera.cpp


/*
* Persona.cpp
*
* Created on: 14/12/2012
* Author: Soneview
*/

#include "Billetera.h"

Billetera::Billetera() {
// TODO Auto-generated constructor stub
billete1 = 5000;
billete2 = 10000;
billete3 = 20000;
billete4 = 50000;
cantbi1 = 0;
cantbi2 = 0;
cantbi3 = 0;
cantbi4 = 0;
}

void Billetera::setcantbi1(int bi1) {
cantbi1 = bi1;
}

int Billetera::getcantbi1() {
return cantbi1;
}

void Billetera::setcantbi2(int bi2) {
cantbi2 = bi2;
}

int Billetera::getcantbi2() {
return cantbi2;
}

void Billetera::setcantbi3(int bi3) {
cantbi3 = bi3;
}

int Billetera::getcantbi3() {
return cantbi3;
}

void Billetera::setcantbi4(int bi4) {
cantbi4 = bi4;
}

int Billetera::getcantbi4() {
return cantbi4;
}

float Billetera::CaldinTot() {
float dinTot;
dinTot = (cantbi1 * billete1) + (cantbi2 * billete2) + (cantbi3 * billete3) + (cantbi4 * billete4);
return dinTot;
}

Función principal:

#include "Billetera.h"

void IEBilletera(Billetera &laBilletera);
void IS(Billetera laBilletera);

int main()
{
Billetera laBilletera;
IEBilletera(laBilletera);
IS(laBilletera);
return 0;
}

void IEBilletera(Billetera &laBilletera)
{
int bi1;
int bi2;
int bi3;
int bi4;
cout "Ingrese la cantidad de billetes de 5000bsF: ";
cin (bi1);
laBilletera.setcantbi1(bi1);
cout "Ingrese la cantidad de billetes de 10000bsF: ";
cin (bi2);
laBilletera.setcantbi2(bi2);
cout "Ingrese la cantidad de billetes de 20000bsF: ";
cin (bi3);
laBilletera.setcantbi3(bi3);
cout "Ingrese la cantidad de billetes de 50000bsF: ";
cin (bi4);
laBilletera.setcantbi4(bi4);
}

void IS(Billetera laBilletera)
{
cout "El dinero total en la billetera de la persona es: " laBilletera.CaldinTot();
}

[Ejercicio resuelto c++ POO] Comisión empleado. – Donate – Seguro – Hosting

Enunciado:
"Si un empleado gana un sueldo básico y además se le asigna una comisión del 25% sobre las ventas que realizó, conociendo su sueldo y lo vendido, determinar cuánto cobrará el empleado."

Clases:

Empleado.h

#ifndef EMPLEADO_H_
#define EMPLEADO_H_

#include iostream

using namespace std;

class Empleado {
private:
float sueldoB;
float cantVentas;
public:
Empleado();
void setsueldoB(float sb);
float getsueldoB();
void setcantVentas(float cv);
float getcantVentas();
float CalsTotal();
};

#endif /* EMPLEADO_H_ */


Empleado.cpp


#include "Empleado.h"

Empleado::Empleado() {
// TODO Auto-generated constructor stub
sueldoB = 0;
cantVentas = 0;
}

void Empleado::setsueldoB(float sb) {
sueldoB = sb;
}

float Empleado::getsueldoB() {
return sueldoB;
}

void Empleado::setcantVentas(float cv) {
cantVentas = cv;
}

float Empleado::getcantVentas() {
return cantVentas;
}

float Empleado::CalsTotal() {
float sTotal;
sTotal = sueldoB + (cantVentas * 0.25);
return sTotal;
}

Función principal:


#include "Empleado.h"

void IEEmpleado(Empleado &elEmpleado);
void IS(Empleado elEmpleado);

int main()
{
Empleado elEmpleado;
IEEmpleado (elEmpleado);
IS(elEmpleado);
return 0;
}

void IEEmpleado(Empleado &elEmpleado)
{
float sb;
float cv;
cout "Ingrese el sueldo base: " endl;
cin (sb);
elEmpleado.setsueldoB(sb);
cout "Ingrese la cantidad de ventas: " endl;
cin (cv);
elEmpleado.setcantVentas(cv);
}

void IS(Empleado elEmpleado)
{
cout "El sueldo total del empleado es: " elEmpleado.CalsTotal() "BsF";
}



domingo, 30 de junio de 2013

Sistema de login en c++ – Accident – Service – Shipping

Lo siguiente es un sistema de login hecho en c++ el cual lo pueden utilizar en las aplicaciones que ustedes mismo realicen.

/*
* main.cpp
*
* Created on: 30/06/2013
* Author: francves
*/

#include iostream
#include stdlib.h

using namespace std;

void login();

int main(){
login();
return 0;
}

void login(){
string nombre;
string pass;
int i;
for(i=1; i4; i++){
system("cls");
cout endl;
cout " BIENVENIDO AL SISTEMA DE LOGIN " endl;
cout "___________________________________________" endl;
cout endl;
cout "Por favor ingrese su informacion de usuario" endl;
cout endl;
cout "¿Nombre de usuario?" endl;
cin nombre;
if(nombre == "admin"){
cout "Nombre de usuario correcto, por favor ingrese su contrasena:" endl;
cin pass;
if(pass == "admin123"){
cout endl;
cout "Contrasena correcta, bienvenido, sera redirigido a la aplicacion" endl;
system("pausenull");
exit(0);
}
else
if(pass != "admin123"){
cout "Contrasena incorrecta, por favor ingrese un usuario y contrasena valida" endl;
system("pausenull");
}
}
else
if(nombre != "admin"){
cout "Nombre de usuario incorrecto, por favor ingrese su nombre de usuario nuevamente" endl;
system("pausenull");
}

if(i 0){
cout endl;
cout "Ha realizado " i "/3 intentos" endl;
cout endl;
system("pausenull");
}
if(i == 3){
cout endl;
cout "Ha realizado 3 intentos, por seguridad el programa se cerrara..." endl;
system("pausenull");
exit(0);
}
}

}


Donde están las instrucciones if y else podrán cambiar el usuario "admin" y la contraseña "admin123" por las que ustedes deseen.


if(nombre == "admin"){
cout
"Nombre de usuario correcto, por favor ingrese su contrasena:" endl;
cin pass;
if(pass == "admin123"){
cout endl;
cout
"Contrasena correcta, bienvenido, sera redirigido a la aplicacion" endl;
system(
"pausenull");
exit(
0);
}
else
if(pass != "admin123"){
cout
"Contrasena incorrecta, por favor ingrese un usuario y contrasena valida" endl;
system(
"pausenull");
}
}
else
if(nombre != "admin"){
cout
"Nombre de usuario incorrecto, por favor ingrese su nombre de usuario nuevamente" endl;
system(
"pausenull");
}

El contador de intentos nos asegura que el usuario se puede equivocar solo 3 veces, y de hacerlo, la aplicación se cerrará exit(0).


if(i  0){
cout endl;
cout "Ha realizado " i "/3 intentos" endl;
cout endl;
system("pausenull");
}
if(i == 3){
cout endl;
cout "Ha realizado 3 intentos, por seguridad el programa se cerrara..." endl;
system("pausenull");
exit(0);
}