ivan.setName("Ivan");
C++ (Qt)#include <QCoreApplication>#include <QTextStream> QTextStream cin(stdin);QTextStream cout(stdout); class Person {public: Person() {} Person(const QString& name) { mName = name; } void setName(const QString& name) { mName = name; } const QString& name() const { return mName; }private: QString mName;}; int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); Person ivan; ivan.setName("Ivan"); cout << ivan.name() << endl; cout.flush(); return a.exec();}
C++ (Qt) Person(const QString& name) { mName = name; }
C++ (Qt)Person(const QString& name) : mName(name) {}
C++ (Qt)QRect GetRect( ... some args..)
C++ (Qt)QRect R = GetRect(...); // вариант 1
C++ (Qt)QRect R;R = GetRect(...); // вариант 2
C++ (Qt)class Animal{public: Animal():alive(false){} ~Animal(){} bool isAlive(){return alive;} // жив ли ? void birth(){alive = true;} // рождение void death(){alive = false;} // смерть private: bool alive;}
C++ (Qt)class Vertebrates : public Animal{public: Vertebrates(int input)vertebras(inpupt), spine(ture){} ~Vertebrates(){} int getCountOfVertebras(){return vertebras;} // получить информацию о кол-ве позвонков bool hasSpine(){return spine;}private: int vertebras; bool spine;}
C++ (Qt)#include <QCoreApplication>#include <QTextStream>#include "shape.h"#include "circle.h"#include "rectangle.h" QTextStream cin(stdin);QTextStream cout(stdout); void printShapeInfo(Shape *ps) { cout << "p = " << ps->perimeter() << endl; cout.flush(); cout << "s = " << ps->area() << endl; cout.flush();} int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); Shape *pc = new Circle(3.0); cout << "static perimeter: " << Circle::perimeter(3.0) << endl; printShapeInfo(pc); delete pc; Shape *pr = new Rectangle(5, 10); printShapeInfo(pr); delete pr; return a.exec();}
C++ (Qt)#ifndef SHAPE_H#define SHAPE_H class Shape{public: Shape() {} virtual ~Shape() { } virtual double perimeter() const = 0; virtual double area() const = 0;}; #endif // SHAPE_H
C++ (Qt)#ifndef CIRCLE_H#define CIRCLE_H #include "shape.h"#include <cmath> class Circle : public Shape{public: Circle(double radius = 0.0) : m_radius(radius) { } static double perimeter(double radius) { return (2.0 * M_PI * radius); } static double area(double radius) { return (M_PI * radius * radius); } virtual double perimeter() const { return perimeter(m_radius); } virtual double area() const { return area(m_radius); } inline double radius() const { return m_radius; } inline void setRadius(double radius) { m_radius = radius; } private: double m_radius;}; #endif // CIRCLE_H
C++ (Qt)#ifndef RECTANGLE_H#define RECTANGLE_H #include "shape.h" class Rectangle : public Shape{public: Rectangle(double height = 0.0, double width = 0.0) : m_height(height), m_width(width) { } static double perimeter(double height, double width) { return 2.0 * (height + width); } static double area(double height, double width) { return height * width; } virtual double perimeter() const { return perimeter(m_height, m_width); } virtual double area() const { return area(m_height, m_width); } inline double height() const { return m_height; } inline double width() const { return m_width; } inline void setHeight(double height) { m_height = height; } inline void setWidth(double width) { m_width = width; } private: double m_height; double m_width;}; #endif // RECTANGLE_H
C++ (Qt)class Viewer : public QGLWidget{public: // ... void draw(const Shape &ps, int xOffset, int yOffset, int pointSize = 2); // ...}
C++ (Qt)const QString & filePath1(..) const;QString filePath2(..) const;QString & filePath3(..);
C++ (Qt)Circle *crcl = new Circle();crcl->draw(x, y, rad);
C++ (Qt)const QString & filePath1(..) const;
C++ (Qt)const QString & filePath1(..) const{ QString result = prefix() + m_filePath + postfix(); return result;}