A Nother Question What Are Classes And Is It Possible To Use A Class For Macking Pictures Or Shapes That You Can See?

Dani AI

Generated

A short, practical guide and a runnable example that shows how a C++ class can represent a visible shape. started this thread with the basic idea; that is useful. ’s point about image file formats applies when saving or decoding image files, but it is not required just to represent or render shapes on the screen.

The simplest way to see how a class models a shape is to start in the console. The example below defines a small Square class with a draw() method that prints a square of characters. Save as square.cpp and compile with g++ -std=c++11 -o square square.cpp.

#include <iostream>

class Square {
public:
    explicit Square(int s) : size(s) {}
    void draw() const {
        for (int r = 0; r < size; ++r) {
            for (int c = 0; c < size; ++c) std::cout << '#';
            std::cout << '\n';
        }
    }
private:
    int size;
};

int main() {
    Square s(6);
    s.draw();
    return 0;
}

For actual windowed graphics (real visible shapes rather than text), use a graphics library (examples: SDL2, SFML, Qt, Win32 GDI, OpenGL). Typical design: keep shape data (position, size, color) inside the class and give it a draw(Renderer&) or render() method that invokes the library’s drawing calls. Key practical notes: many libraries treat (0,0) as the top-left; coordinates can be integer or float; a main event loop and a valid drawing context are required; linking and headers are necessary when moving off-console.

Quick troubleshooting: if the example fails to compile, check the file extension is .cpp, ensure #include <iostream> is present, and compile with a modern standard (e.g., -std=c++11). Start with the console example to verify class basics, then move to a library tutorial and port the draw() method to call real drawing functions.

Recommended Answers

All 4 Replies

A Nother Question What Are Classes

A class is defined by using the keyword class followed by a programmer-specified name followed by the class definition in braces. The class definition contains the class members, its data, and the class methods, its functions.

Is It Possible To Use A Class For Macking Pictures Or
Shapes That You Can See?

Yes.

well then what does it do how does it work. what is the prosess of making a simple square? could u pleas give me an exampl of the santyx and code for it and ill examin it and see how it works then compile and run it?

well then what does it do how does it work. what is the prosess of making a simple square? could u pleas give me an exampl of the santyx and code for it and ill examin it and see how it works then compile and run it?

So many questions...
You better read this basic tutorial

http://www.cprogramming.com/tutorial/lesson12.html

Note: Read the rules of the forum before posting again.

u can do it only if u know entire file structure formats and the encoding and decoding algorithms of images

try this site to know the algorithms..
www.funducode.com

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.