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");
}

california law lemon New social media platforms Live casino lease management software Hire php developer DONATE YOUR CAR SACRAMENTO personal injury lawyer sarasota fl structured settlement annuity companies peritoneal mesothelioma anti spam appliance Seo companies Mobile casino Casino reviews Dayton Freight Lines auto accident attorney google adsense Criminal lawyer Online casino mesothelioma attorneys Home Phone Internet Bundle Computer science classes online Best social media platforms for business CHEAP AUTO INSURANCE IN VA accident lawyers in los angeles auto insurance yuba city ca ONLINE MOTOR INSURANCE QUOTES mesothelioma litigation Casino Mortgage Adviser Psychic for free NEUSON Criminal defense lawyer Health Records Personal Health Record Tech school Make money online Australia Bankruptcy lawyer dallas mesothelioma lawyer DONATE YOUR CAR FOR MONEY DUI lawyer DONATE A CAR IN MARYLAND Hire php developers mesothelioma suit MOTOR REPLACEMENTS Hire php programmers Better conferencing calls Car Insurance Quotes ANNUITY SETTLEMENT Italian cooking school buy structured settlements Virtual Data Rooms How to Donate A Car in California Business finance group Dwi lawyer Service business software Learning adobe illustrator personal injury law firm Online College Course Mortgage Donating a car in Maryland Php programmers for hire FORENSICS ONLINE COURSE Car Insurance Quotes PA motor replacements mesothelioma settlements personal injury accident lawyer Social media campaigns forensics online course Car insurance quotes Utah mesothelioma information Holland Michigan College Best Seo company Php programmers Online Christmas cards structured settlement broker Better Conference Calls World Trade Center Footage DONATING USED CARS TO CHARITY car insurance quotes WordPress theme designers Car Accident Lawyers Social media platforms Online Stock Trading Seo services AUTOMOBILE ACCIDENT ATTORNEY webex costs Best social media platforms Social media platforms for business Custom WordPress theme designer structured settlement brokers DONATING A CAR IN MARYLAND Social media examiner virtual data rooms donate your car for money refinance with poor credit Motor replacements Business management software attorney lawyer mesothelioma Data Recovery Raid Seo company Html email houston motorcycle accident lawyer Auto Accident Attorney holland michigan college Car Insurance Companies Adobe illustrator classes Structures Annuity Settlement Asbestos Lung Cancer mesothelioma charities Donate your car Sacramento online colledges Custom Christmas cards Photo Christmas cards PHD on Counseling Education WordPress themes for designers Motor Replacements Donate Cars Illinois WordPress hosting Psd to WordPress Dallas Mesothelioma Attorneys Car Insurance in South Dakota dallas mesothelioma attorneys Neuson Social media management mesothelioma lawyer virginia DONATE OLD CARS TO CHARITY colorado mesothelioma lawyers business voip solutions cheap car insurance in virginia mesothelioma attorneys california DAYTON FREIGHT LINES criminal defense attorneys florida Christmas cards Proud Italian cook Psd to html mesothelioma lawyer asbestos cancer lawsuit selling structured settlement Donate Car to Charity California semi truck accident lawyers donate old cars to charity domain yahoo buyers of structured settlements HOLLAND MICHIGAN COLLEGE PSYCHIC FOR FREE Cheap Car Insurance for Ladies MESOTHELIOMA LAW FIRM structured settlement investments asbestos mesothelioma lawsuit Social media strategies Annuity Settlements Social media tools Futuristic Architecture Mesothelioma Law Firm DONATE CARS ILLINOIS Royalty free images stock Car Insurance Quotes Utah personal injury solicitor sell your structured settlement payments Insurance Companies EMAIL BULK SERVICE Donate Old Cars to Charity Best Criminal Lawyers in Arizona Donate Car for Tax Credit REGISTER FREE DOMAINS Donate Cars in MA Donate Your Car Sacramento st louis mesothelioma attorney Sell Annuity Payment new york mesothelioma law firm average mesothelioma settlement mesothelioma lawyer dallas supportpeachtreecom mesothelioma Donate Your Car for Kids MASSAGE SCHOOL DALLAS TEXAS tennessee mesothelioma lawyer mesothelioma help fortis health insurance temporary Asbestos Lawyers hosted predictive dialers bus accident attorneys Car Insurance Quotes Colorado better conferencing calls CAR ACCIDENT LAWYERS best accident attorneys Nunavut Culture Hard drive Data Recovery Services Donate a Car in Maryland PAPERPORT PROMOTIONAL CODE CAR INSURANCE QUOTES UTAH Webex Costs Cheap Auto Insurance in VA domain name yahoo Cheap Domain Registration Hosting Donating a Car in Maryland Insurance Personal Injury Lawyers cheaper insurance companies Criminal Defense Attorneys Florida Online Colleges Massage School Dallas Texas Low credit line credit cards Life Insurance Co Lincoln Auto Mobile Insurance Quote Online Motor Insurance Quotes annuity payment Dedicated Hosting Dedicated Server Hosting Paperport Promotional Code Online Classes mesothelioma law suit paperport promotional code state of california car insurance Psychic for Free criminal defense federal lawyer Low Credit Line Credit Cards Car Insurance Quotes MN Donate your Car for Money Met Auto Donate a car in Maryland Claim Forensics Online Course Donating Used Cars to Charity asbestos lawyers miami personal injury lawyer mesothelioma lawyer houston Home phone internet bundle cash out annuity Royalty Free Images Stock Email Bulk Service Online classes firm law mesothelioma Cheap Car Insurance in Virginia Register Free Domains structured settlement buyer buying structured settlements Car Donate sell structured settlement calculator what is structured settlement Automobile Accident Attorney insurance medical temporary accident attorneys orange county truck accident attorney los angeles home phone internet bundle miami personal injury attorney Criminal lawyer Miami mesothelioma attorney illinois Motor Insurance Quotes mesothelioma ct mesothelioma lawyer texas mesothelioma cases Injury Lawyers

No hay comentarios:

Publicar un comentario