Descargar como pdf o txt
Descargar como pdf o txt
Está en la página 1de 8

EXAMEN FINAL PROGRAMACION ORIENTADA A OBJETOS

PROBLEMA 1
// problema 1 final.cpp : Defines the entry point for the console application.
//
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<time.h>
using namespace std;
class recta {
protected:
int x1, y1, x2, y2;
public:
recta();
recta(float, float, float, float);
void mostrar();
void pendiente();
float distancia();
};
recta::recta() {
x1 = rand()%10+1; y1 = rand() % 10 + 1;
x2 = rand() % 10 + 1; y2= rand() % 10 + 1;
}
recta::recta(float a, float b, float c, float d) {
x1 = a; y1 = b;
x2 = c; y2 = d;
}
void recta::pendiente() {
if ((x2 - x1)! = 0) {
float m;
m = float(y2 - y1) / (x2 - x1);
cout << "La pendiente de la recta es: " << m << endl;
cout << "La eucacion de la recta es: " << "mX+b=Y" << endl;
cout << "m= " << m << endl;
cout << "b= " << y1 - x1 * m << endl;
}
else
cout << "Es una recta vertical " << endl;

}
float recta::distancia() {
float d;
d= sqrtf(powf((x1 - x2), 2) + powf((y1 - y2), 2));
return(d);
}
void recta::mostrar() {
cout << "La primera coordenada es: " << "( " << x1 << " ; " << y1 << " )" << endl;
cout << "La segunda coordenada es: " << "( " << x2 << " ; " << y2 << " )" << endl;
}

class poligono :public recta {


protected:
int n;
public:
poligono();
poligono(int);
void genera();
};
poligono::poligono() {
n = 9;
}
poligono::poligono(int t) {
n = t;
}
void poligono::genera() {
float sp,area;
recta r1, r2, r3, r4, r5, r6, r7, r8, r9;
cout << "Los lados generados del heptagono son: " << endl;
cout << r1.distancia() << " " << r2.distancia() << " " << r3.distancia() << " " << r4.distancia()
<< " " << r5.distancia() << " " << r6.distancia() << " " << r7.distancia() " " << r8.distancia() << " " <<
r9.distancia() << endl;
sp = (r1.distancia() + r2.distancia() + r3.distancia() + r4.distancia() + r5.distancia() +
r6.distancia() + r7.distancia+ r8.distancia + r9.distancia ()) / 2.0;
cout << "El semiperimetro es: " << sp << endl;
}
void main() {
srand((unsigned)time(NULL));
recta r;
r.mostrar();
r.pendiente();
cout << "La distancia entre los puntos es: " << r.distancia() << endl;
poligono p;
p.genera();
system("pause");
}
PROBLEMA 2

static DWORD dwColor[9]={RGB(0,0,0),

RGB(255,0,0), RGB(0,255,0),

RGB(0,0,255), RGB(255,255,0),

RGB(255,0,255), RGB(0,255,255),

RGB(127,127,127), RGB(255,255,255)};

CPen n_pincel;

CPen *v_pincel;

CRect rect;

GetClientRect(rect);

int cx=(rect.right -rect.left);

int cy=(rect.bottom-rect.top);

dc.SetMapMode(MM_ANISOTROPIC);

dc.SetWindowExt(840,300);

dc.SetViewportOrg(cx,-cy);

dc.SetViewportExt(cx,-cy);

dc.SetViewportOrg(cx/2,cy/2);

double x,y,u;

for(int u=0;u<361;u++){

x=50*((u*3.141516/180)-sin(u*3.1416/180));

y=50*(1-cos(u*3.1416/180));

dc.SetPixel(x,y,RGB(0,0,255));}

dc.TextOut(120,40,_T("cicloide"));

n_pincel.CreatePen(PS_SOLID, 1,dwColor[0]);

v_pincel=dc.SelectObject(&n_pincel);
dc.MoveTo(0,-140);

dc.LineTo(0,140);

dc.TextOut(0,145,_T("Y"),1);

dc.SelectObject(v_pincel);

n_pincel.DeleteObject();

n_pincel.CreatePen(PS_SOLID, 1,dwColor[0]);

v_pincel=dc.SelectObject(&n_pincel);

dc.MoveTo(-100,0);

dc.LineTo(300,0);

dc.TextOut(305,0,_T("X"),1);

dc.SelectObject(v_pincel);

n_pincel.DeleteObject();

dc.Ellipse(0,10,280,300);

dc.Ellipse(0,20,260,290);

dc.Ellipse(0,30,240,280);

dc.Ellipse(0,40,220,270);

dc.Ellipse(0,50,200,260);

dc.Ellipse(0,60,180,250);

dc.Ellipse(0,70,160,240);

dc.Ellipse(0,80,140,220);

dc.Ellipse(0,90,120,210);

dc.Ellipse(0,100,100,200);
PROBLEMA 4

#include "stdafx.h"
#include "Problema4.h"
#include "Problema4Dlg.h"
#include "afxdialogex.h"
#include "Cconfigu.h"
#include "Cvalencia.h"
#include "Ccuantico.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CAboutDlg dialog used for App About

class CAboutDlg : public CDialogEx


{
public:
CAboutDlg();

// Dialog Data
enum { IDD = IDD_ABOUTBOX };

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

// Implementation
protected:
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)


{
CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()

// CProblema4Dlg dialog

CProblema4Dlg::CProblema4Dlg(CWnd* pParent /=NULL/)


: CDialogEx(CProblema4Dlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CProblema4Dlg::DoDataExchange(CDataExchange* pDX)


{
CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CProblema4Dlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_Salir, &CProblema4Dlg::OnBnClickedSalir)
ON_BN_CLICKED(IDC_RADIO_VerConfigu,
&CProblema4Dlg::OnBnClickedRadioVerconfigu)
ON_BN_CLICKED(IDC_RADIO_VerElectro,
&CProblema4Dlg::OnBnClickedRadioVerelectro)
ON_BN_CLICKED(IDC_RADIO_VerNumeroCuan,
&CProblema4Dlg::OnBnClickedRadioVernumerocuan)
END_MESSAGE_MAP()

// CProblema4Dlg message handlers

BOOL CProblema4Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.


ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);


if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here

return TRUE; // return TRUE unless you set the focus to a control
}

void CProblema4Dlg::OnSysCommand(UINT nID, LPARAM lParam)


{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.

void CProblema4Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND,
reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

// Center icon in client rectangle


int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon


dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}

// The system calls this function to obtain the cursor to display while the user
drags
// the minimized window.
HCURSOR CProblema4Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}

void CProblema4Dlg::OnBnClickedSalir()
{
// TODO: Add your control notification handler code here
PostQuitMessage(0);
}

void CProblema4Dlg::OnBnClickedRadioVerconfigu()
{
// TODO: Add your control notification handler code here

Cconfigu sistema;
sistema.Configuracion = "1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p5";
UpdateData(false);

sistema.DoModal();

void CProblema4Dlg::OnBnClickedRadioVerelectro()
{
// TODO: Add your control notification handler code here
Cvalencia sistema;
sistema.Electrones= 7;
UpdateData(false);

sistema.DoModal();
}

void CProblema4Dlg::OnBnClickedRadioVernumerocuan()
{
// TODO: Add your control notification handler code here
Ccuantico sistema;
sistema.cuantico=4;
UpdateData(false);

sistema.DoModal();
}
}
}
}

También podría gustarte