// Filename: MATHMENU.CPP
// Uses a switch statement to perform
// menu actions for the user
#include <iostream.h>
void main()
{
const int PI = 3.14159;
int menu; // Will hold menu result
int num; // Will hold user's numeric value
float result; // Will hold computed answer
cout << "Math Calculations" << endl << endl;
cout << "Please enter a number from 1 to 30: ";
cin >> num;
if ( (num < 1) && (num > 30));
{
return; // Exit if bad input
}
cout << "Here are your choices:" << endl << endl;
cout << "\t1. Calculate the absolute value" << endl;
cout << "\t2. Calculate the square" << endl;
cout << "\t3. Calculate the cube" << endl;
cout << "\t4. Calculate a circle's area" << endl;
cout << "\t using your radius" << endl;
cout << endl << "What do you want to do? ";
cin >> menu;
switch (menu)
{
case (1) :
{
result = ((num < 0)? -num : num);
break;
}
case (2) :
{
result = num * num;
break;
}
case (3) :
{
result = num * num * num;
break;
}
case (4) :
{
result = PI * (num * num);
break;
}
default :
{
cout << "You did not enter 1, 2, 3, or 4" << endl;
return; // Terminate the whole program
// No need for a break
}
}
cout << endl << "Here is your computed value: "
<< result << endl;
return;
}
==================================
// File Name : MFC.CPP
// A very simple Windows program
//
// To compile and run this, you will need to
// use the MFC.MAK project included with the
// source. Choose Project | Open | MFC.MAK
//
#include<afxwin.h> // This lives in a different include
// directory
//------------------------------------------------------------
// SimpleApp is a class that hides the Windows equivalent
// of main()
//
class SimpleApp:public CWinApp
{
public:
BOOL InitInstance() // A virtual function - trust me!
{
CString title("Hello World"); // A string class
title += "!"; // Classes can define operators too.
// Define the addition to concatenate
// a string.
// Make a window object with a frame border
CFrameWnd* mainWindow = new CFrameWnd;
// Tell Windows to make a window
mainWindow->Create(0,title);
// Assign the window to the application
m_pMainWnd = mainWindow;
// Tell Windows to show the window
m_pMainWnd->ShowWindow(m_nCmdShow);
// Tell Windows to make sure that the window
// is properly drawn.
m_pMainWnd->UpdateWindow();
// Tell the base application that we successfully
// made a window
return TRUE;
}
};
SimpleApp SimpleApp; // This makes a global object
// which includes a main()
// that Windows can find
=========================================
# Microsoft Visual C++ generated build script - Do not modify
PROJ = MFC
DEBUG = 0
PROGTYPE = 0
CALLER =
ARGS =
DLLS =
D_RCDEFINES = -d_DEBUG
R_RCDEFINES = -dNDEBUG
ORIGIN = MSVC
ORIGIN_VER = 1.00
PROJPATH = C:\WORD6\VC12\SOURCE\
USEMFC = 1
CC = cl
CPP = cl
CXX = cl
CCREATEPCHFLAG =
CPPCREATEPCHFLAG =
CUSEPCHFLAG =
CPPUSEPCHFLAG =
FIRSTC =
FIRSTCPP = MFC.CPP
RC = rc
CFLAGS_D_WEXE = /nologo /G2 /W3 /Zi /AM /Od /D "_DEBUG" /FR /GA /Fd"MFC.PDB"
CFLAGS_R_WEXE = /nologo /G2 /W3 /AM /O1 /D "NDEBUG" /FR /GA
LFLAGS_D_WEXE = /NOLOGO /ONERROR:NOEXE /NOD /PACKC:61440 /CO /ALIGN:16 /STACK:10240
LFLAGS_R_WEXE = /NOLOGO /ONERROR:NOEXE /NOD /PACKC:61440 /ALIGN:16 /STACK:10240
LIBS_D_WEXE = mafxcwd oldnames libw commdlg shell olecli olesvr mlibcew
LIBS_R_WEXE = mafxcw oldnames libw commdlg shell olecli olesvr mlibcew
RCFLAGS = /nologo
RESFLAGS = /nologo
RUNFLAGS =
DEFFILE = MFC.DEF
OBJS_EXT =
LIBS_EXT =
!if "$(DEBUG)" == "1"
CFLAGS = $(CFLAGS_D_WEXE)
LFLAGS = $(LFLAGS_D_WEXE)
LIBS = $(LIBS_D_WEXE)
MAPFILE = nul
RCDEFINES = $(D_RCDEFINES)
!else
CFLAGS = $(CFLAGS_R_WEXE)
LFLAGS = $(LFLAGS_R_WEXE)
LIBS = $(LIBS_R_WEXE)
MAPFILE = nul
RCDEFINES = $(R_RCDEFINES)
!endif
!if [if exist MSVC.BND del MSVC.BND]
!endif
SBRS = MFC.SBR
all: $(PROJ).EXE $(PROJ).BSC
MFC.OBJ: MFC.CPP $(MFC_DEP)
$(CPP) $(CFLAGS) $(CPPCREATEPCHFLAG) /c MFC.CPP
$(PROJ).EXE:: MFC.OBJ $(OBJS_EXT) $(DEFFILE)
echo >NUL @<<$(PROJ).CRF
MFC.OBJ +
$(OBJS_EXT)
$(PROJ).EXE
$(MAPFILE)
c:\msvc\lib\+
c:\msvc\mfc\lib\+
$(LIBS)
$(DEFFILE);
<<
link $(LFLAGS) @$(PROJ).CRF
$(RC) $(RESFLAGS) $@
run: $(PROJ).EXE
$(PROJ) $(RUNFLAGS)
$(PROJ).BSC: $(SBRS)
bscmake @<<
/o$@ $(SBRS)
<<
Tidak ada komentar:
Posting Komentar