SVG
// svg.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <list>
#include <conio.h>
 
class TShape{
public:
    TShape(){};
    virtual void InitKonsol(){};
    virtual void InitKonsol(int n){};
    virtual void Draw(std::ofstream &file){};
};
 
class TRect : public TShape{
public:
    int x,y,width,height,rx,ry;
    TRect(){};
    TRect(int w,int h,int xx,int yy,int rrx, int rry):y(yy),x(xx),width(w),height(h),rx(rrx),ry(rry){};
    TRect(int w,int h,int xx,int yy,int rr=0):y(yy),x(xx),width(w),height(h),rx(rr),ry(rr){};
    TRect(int w,int h,int z=0):y(z),x(z),width(w),height(h),rx(z),ry(z){};
    virtual void InitKonsol(){
        std::cout<<"Podaj szerokosc ";
        std::cin>>width;
        std::cout<<"Podaj wysokosc ";
        std::cin>>height;
        std::cout<<"Podaj x ";
        std::cin>>x;
        std::cout<<"Podaj y ";
        std::cin>>y;
        std::cout<<"Podaj rx ";
        std::cin>>rx;
        std::cout<<"Podaj ry ";
        std::cin>>ry;
    };
    virtual void Draw(std::ofstream &file){
        file<<"<rect x=\"";
        file<<x;
        file<<"\" y=\"";
        file<<y;
        file<<"\" width=\"";
        file<<width;
        file<<"\" height=\"";
        file<<height;
        file<<"\" rx=\"";
        file<<rx;
        file<<"\" ry=\"";
        file<<ry;
        file<<"\" />"<<std::endl;
    };
};//*/
 
class TCircle : public TShape{
public:
    int cx,cy,r;
    TCircle(){};
    TCircle(int rr,int ccx,int ccy):cx(ccx),cy(ccy),r(rr){};
    TCircle(int rr,int cc):cx(cc),cy(cc),r(rr){};
    virtual void InitKonsol(std::ofstream &file){
        std::cout<<"Podaj promien ";
        std::cin>>r;
        std::cout<<"Podaj x ";
        std::cin>>cx;
        std::cout<<"Podaj y ";
        std::cin>>cy;
    };
    virtual void Draw(std::ofstream &file){
        file<<"<circle cx=\"";
        file<<cx;
        file<<"\" cy=\"";
        file<<cy;
        file<<"\" r=\"";
        file<<r;
        file<<"\" />"<<std::endl;
    };
};
 
class TEllipse : public TShape{
public:
    int cx,cy,rx,ry;
    TEllipse(){};
    TEllipse(int rrx, int rry,int ccx,int ccy): cx(ccx),cy(ccy),rx(rrx),ry(rry){};
    TEllipse(int rrx, int rry,int cc=0): cx(cc),cy(cc),rx(rrx),ry(rry){};
    virtual void InitKonsol(){
        std::cout<<"Podaj szerokosc ";
        std::cin>>rx;
        std::cout<<"Podaj wysokosc ";
        std::cin>>ry;
        std::cout<<"Podaj x ";
        std::cin>>cx;
        std::cout<<"Podaj y ";
        std::cin>>cy;
    };
    virtual void Draw(std::ofstream &file){
        file<<"<ellipse cx=\"";
        file<<cx;
        file<<"\" cy=\"";
        file<<cy;
        file<<"\" rx=\"";
        file<<rx;
        file<<"\" ry=\"";
        file<<ry;
        file<<"\" />"<<std::endl;
    };
 
};
 
class TLine : public TShape{
public:
    int x1,y1,x2,y2;
    TLine(){};
    TLine(int xx1,int yy1,int xx2,int yy2):x1(xx1),y1(yy1),x2(xx2),y2(yy2){};
    virtual void InitKonsol(){
        std::cout<<"Podaj x1 ";
        std::cin>>x1;
        std::cout<<"Podaj y1 ";
        std::cin>>y1;
        std::cout<<"Podaj x2 ";
        std::cin>>x2;
        std::cout<<"Podaj y2 ";
        std::cin>>y2;
    };
    virtual void Draw(std::ofstream &file){
        file<<"<line x1=\"";
        file<<x1;
        file<<"\" y1=\"";
        file<<y1;
        file<<"\" x2=\"";
        file<<x2;
        file<<"\" y2=\"";
        file<<y2;
        file<<"\" />"<<std::endl;
    };
 
};
 
class TPolyline : public TShape{
public:
    int *z,n;
    TPolyline(){
        z=new int[0];
        n=0;
    };
    TPolyline(int *zz,int n){
        z = new int[2*n-2];
        for(int i=0;i<n-1;++i) z[i]=zz[i];
    };
    ~TPolyline(){
         delete[] z; 
         n=0;
    };
    virtual void InitKonsol(){
        delete[] z;
        std::cout<<"Podaj ilosc punktow";
        std::cin>>n;
        z =new int[2*n];
        for(int i=0;i<n;++i){
            std::cout<<"Podaj x"<<(i+1)<<" ";
            std::cin>>z[2*i];
            std::cout<<"Podaj y"<<(i+1)<<" ";
            std::cin>>z[2*i+1];
        };
    };
    virtual void Draw(std::ofstream &file){
        file<<"<polyline points=\"";
        if(n>0) file<<z[0]<<","<<z[1]<<" ";
        for(int i=1;i<n;++i) file<<z[2*i]<<","<<z[2*i+1]<<" ";
        file<<"\" />"<<std::endl;
    };
};
 
class TPolygon : public TShape{
public:
    int *z,n;
    TPolygon(){
        z=new int[0];
        n=0;
    }
    TPolygon(int xx1,int yy1,int xx2,int yy2,int xx3,int yy3){
        z=new int[6];
        z[0]=xx1;
        z[1]=yy1;
        z[2]=xx2;
        z[3]=yy2;
        z[4]=xx3;
        z[5]=yy3;
        n=3;
    };
    TPolygon(int *zz,int nn){
        z = new int[2*n];
        for(int i=0;i<2*n;++i) z[i]=zz[i];
    };
    ~TPolygon(){
         n=0;
         delete[] z; 
    };
    virtual void InitKonsol(){
        delete []z;
        std::cout<<"Podaj ilosc punktow ";
        std::cin>>n;
        z = new int[2*n];
        for(int i=0;i<n;++i){
            std::cout<<"Podaj x"<<(i+1)<<" ";
            std::cin>>z[2*i];
            std::cout<<"Podaj y"<<(i+1)<<" ";
            std::cin>>z[2*i+1];
        };
    };
    virtual void InitKonsol(int nn){
        delete []z;
        n=nn;
        z = new int[2*n];
        for(int i=0;i<n;++i){
            std::cout<<"Podaj x"<<(i+1)<<" ";
            std::cin>>z[2*i];
            std::cout<<"Podaj y"<<(i+1)<<" ";
            std::cin>>z[2*i+1];
        };
    };
    virtual void Draw(std::ofstream &file){
        file<<"<polygon points=\"";
        if(n>0) file<<z[0]<<","<<z[1]<<" ";
        for(int i=1;i<n;++i) file<<" "<<z[2*i]<<","<<z[2*i+1];
        file<<"\" />"<<std::endl;
    };
};
 
class TFile{
public: 
    int width,height,x,y;
    std::list< TShape* > List;
    TFile():width(0),height(0),x(0),y(0){};
    TFile(int w,int h,int xx, int yy):width(w),height(h),x(xx),y(yy){};
    void InitKonsol(){
        std::cout<<"Podaj szerokosc ";
        std::cin>>width;
        std::cout<<"Podaj wysokosc ";
        std::cin>>height;
        std::cout<<"Podaj x ";
        std::cin>>x;
        std::cout<<"Podaj y ";
        std::cin>>y;
    };
 
    void Add(TShape *PShape){
        List.push_back(PShape);
    };
    void Draw(char s[]){
        std::ofstream file(s);
        file<<"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>"<<std::endl;
        file<<"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">"<<std::endl;
        file<<"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"";
        file<<width;
        file<<"\" height=\"";
        file<<height;
        file<<"\" x=\"";
        file<<x;
        file<<"\" y=\"";
        file<<y;
        file<<"\">"<<std::endl;
        for(std::list<TShape* >::iterator i=List.begin(); i!=List.end(); ++i) (*i)->Draw(file);
            //i->*Draw(file);
        file<<"</svg>"<<std::endl;
        file.close();
    };
 
};
 
int main(int argc, _TCHAR* argv[])
{
    TFile OFile(10000,5000,500,250);
    TShape *PShape;
 
    char c=' ';
    while(c!='0'){
    std::cout<<"Menu\n";
        std::cout<<"1.Prostokat\n";
        std::cout<<"2.Kolo\n";
        std::cout<<"3.Elipsa\n";
        std::cout<<"4.Linia\n";
        std::cout<<"5.Lamana\n";
        std::cout<<"6.Wielokat\n";
        std::cout<<"7.Trojkat\n";
        std::cout<<"9.Generuj przyklad\n";
        std::cout<<"0.Wyjscie"<<std::endl;
        //c=getchar();
        std::cin>>c;
        switch(c){
case '1':{PShape = new TRect();
    PShape->InitKonsol();
        OFile.Add(PShape);
         };
    break;
case '2':{PShape = new TCircle();
    PShape->InitKonsol();
        OFile.Add(PShape);
         };
    break;
case '3':{PShape = new TEllipse();
    PShape->InitKonsol();
        OFile.Add(PShape);
         };
    break;
case '4':{PShape = new TLine();
    PShape->InitKonsol();
        OFile.Add(PShape);
         };
    break;
case '5':{PShape = new TPolyline();
    PShape->InitKonsol();
        OFile.Add(PShape);
         };
    break;
case '6':{PShape = new TPolygon();
    PShape->InitKonsol();
        OFile.Add(PShape);
         };
    break;
case '7':{PShape = new TPolygon();
    PShape->InitKonsol(3);
        OFile.Add(PShape);
         };
case '9':{
    int i0,i1,i2,i3,i4,i5,min=100,max=600;
        i0=rand()%min;
        i1=rand()%min;
        i2=rand()%max;
        i3=rand()%max;
        i4=rand()%max;
        i5=rand()%max;
    PShape = new TRect(i0,i1,i2,i3,0,0);
    OFile.Add(PShape);
        i0=rand()%min;
        i1=rand()%max;
        i2=rand()%max;
    PShape = new TCircle(i0,i1,i2);
    OFile.Add(PShape);
        i0=rand()%min;
        i1=rand()%min;
        i2=rand()%max;
        i3=rand()%max;
    PShape = new TEllipse(i0,i1,i2,i3);
    OFile.Add(PShape);
        i0=rand()%max;
        i1=rand()%max;
        i2=rand()%max;
        i3=rand()%max;
    PShape = new TLine(i0,i1,i2,i3);
    OFile.Add(PShape);
        i0=rand()%max;
        i1=rand()%max;
        i2=rand()%max;
        i3=rand()%max;
        i4=rand()%max;
        i5=rand()%max;
    PShape = new TPolygon(i0,i1,i2,i3,i4,i5);
    OFile.Add(PShape);
         };
    break;
        };
    };
    OFile.Draw("svg.svg");
    return 0;
}
O ile nie zaznaczono inaczej, treść tej strony objęta jest licencją Creative Commons Attribution-ShareAlike 3.0 License