无题

来源:互联网 发布:c语言中mod是什么意思 编辑:程序博客网 时间:2024/05/29 15:30

// TestClass.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<stdlib.h>
#include <memory.h>
#include <windows.h>
#include <iostream>
using namespace std;
#define min(a , b)  a>=b ? b:a
#define swap(a,b) {a=a+b;b=a-b;a=a-b;}
class Shape  {
public:
 
// virtual int GetCircumference(){return 0;};
// virtual int GetArea(){return 0;};
 virtual float GetCircumference(){return 0;};
 virtual float GetArea(){return 0;};


};

 

class MyRound :public Shape
{
public:
 MyRound(int r){m_r = r; };
 float GetCircumference(){return m_r*3.14*2;};
 float GetArea(){return m_r*3.14*m_r;};
private:
 int m_r;
// MyRound(int r){m_r = r; };
 

};


class MyRect :public Shape
{
public:
 MyRect(int Width, int Height){m_Width=Width; m_Height=Height;};
 float GetCircumference(){return (m_Width+m_Height)*2;};
 float GetArea(){return m_Width*m_Height;};
private:
 int m_Width;
 int m_Height;

};

typedef struct SHAPELIST
{

 Shape *pAnyShape; 
 struct SHAPELIST *pNext; 
};//SHAPELIST,*PSHAPELIST;

char myChar[8];

 

 

int main(int argc, char* argv[])
{
  WORD *pW;
  DWORD *pD;
  char *pC;
 memset(myChar,0,8);

 pD= (unsigned long *)&myChar[0];
    *pD++ = 0x3435;
    *pD = 0x33;
 pW= (unsigned short *)&myChar[3];
 *pW = 0x3132;
 pC = &myChar[2];
 *pC = 0x33;
 pC = &myChar[5];
 *pC = 0x30;
    printf("%s/n",myChar);
 MyRect rc(2,3);
 MyRound rd(1);
 printf("MyRect::GetCircumference %f/n",rc.GetCircumference());
 printf("MyRect::GetArea %f/n",rc.GetArea());
 printf("MyRound::GetCircumference %f/n",rd.GetCircumference());
 printf("MyRound::GetArea %f/n",rd.GetArea());
 SHAPELIST * pHead;
 pHead = new SHAPELIST;
 pHead->pAnyShape = &rc ;
 pHead->pNext = new SHAPELIST;
    pHead->pNext->pAnyShape = &rd;
 pHead->pNext->pNext = NULL;

 printf("%f/n",pHead->pAnyShape->GetCircumference());
 printf("%f/n",pHead->pAnyShape->GetArea());
 printf("%f/n",pHead->pNext->pAnyShape->GetCircumference());
 printf("%f/n",pHead->pNext->pAnyShape->GetArea());

 printf("min(7,8):%d/n",min(7,8));
    int a[3][4]={{11,12,13,14},{21,22,23,24},{31,32,33,34}};
 int *p;
 p= &a[0][0];
 for(int i=0;i<12;i++)
 {
        printf("%d/n",*p);
  p++;
  
 }

/*    int (*parray)[4] = a;
 int j,k;
 cin>>j>>k;
 cout<<*(*(parray+j)+k)<<endl;
*/
  int a1=2;
 int b1 =3;
 swap(a1,b1);
   printf("swap(a1,b1): %d%d/n",a1,b1);
 system("pause");

 return 0;
}