The basics of programming in c++ for beginners

Tasks and Solutions: Classes C ++

Прошло немного времени после публикации вводного урока о классах в C . Теперь мы предлагаем вам попрактиковаться в решении достаточно простых задач с применением классов. Старайтесь решать самостоятельно.

1. Create classTiles (кафель), который будет содержать поля с открытым доступом: brandsize_hsize_wprice class and methodgetData(). В главной функции объявить пару объектов класса и внести данные в поля. Затем отобразить их, calling methodgetData().

2. Determine the class Children, which contains the following fields(class members): закрытые – имя ребенка, фамилию и возраст , публичные – методы ввода данных и отображения их на экран. Объявить два объекта класса, внести данные и показать их.

3. Преобразовать строки двумерного массива в столбцы. Например было: 

tasks and solutions, c ++ classes, c++ classes for beginners, privat and public access specifiers, class methods

стало:

tasks and solutions, c ++ classes, c++ classes for beginners, privat and public access specifiers, class methods

Класс будет содержать два метода: один заполнит массив значениями, второй произведет замену значений строк на значения столбцов.

38 thoughts on “Tasks and Solutions: Classes C ++

  1. I did on Garcia 2 task
    #include
    #include”windows.h”
    #include

    using namespace std;
    class Children{
    private:
    string name;
    string fleam;
    float vik;
    public:
    Children(): bay(0)
    { }
    Children(string r1,string w2,float w3): name(r1),fleam(W2),bay(w3)
    { }
    void foma();
    void dota();

    };
    void Children::foma(){
    cout<<"Добрий день "<<endl<<"Ведіть імя фімілію і рік"<>bay;
    // cout<<"Імя "<<name<<endl<<"Фамілія "<<fleam<<endl<<"Рік"<<bay<<endl;
    }
    void Children::dota(){
    cout<<"Імя "<<name<<endl<<"Фамілія "<<fleam<<endl<<"Рік "<<bay<<endl;
    }
    int main(){
    SetConsoleCP(1251);
    SetConsoleOutputCP(1251);
    cout<<"Привіт !1!";
    Children ee1;
    ee1.foma();
    ee1.dota();

    return 0;
    }

      1. I have a question, dear experts!

        In the example of the third problem solutions, we have created a temporary matrix tempMatrix new configuration, copied into it one by one all the elements, then freed memory, occupied matrix matrixInClass, identified new memory matrixInClass, alternately copied all the elements and freed memory, occupied temporary matrix.

        I went a little bit different way, shorter. Everything works without error, but I want to know, can I missing something(knowingly cut). Your code flooded on codepad –> http://codepad.org/vAuUf5pO

        I am doing so:

        Create a temporary matrix tempMatrix new configuration, I copied into it from the elements of the matrix matrixInClass, freed memory, occupied matrixInClass.
        everything exactly up to this point as well.

        And now I just assign a value to a pointer matrixInClass tempMatrix so:

        matrixInClass = tempMatrix;
        tempMatrix = 0;

        Then matrixInClass started to point to a memory portion, occupied tempMatrix. So now we do not need perevydelyat memory matrixInClass, as in the example, then copy the element by element array and free memory.

        Question I have the following: It may be a reason you did so, how did, I suppose somewhere in a memory leak??? Thanks in advance for your reply!

  2. Help solve the problem!
    The challenge for the interaction among the classes. Razrabotat Systems 'depot'. Manager distributes applications for flights between the driver and assigns for this Car. The driver can make a request for repair. Manager may remove the driver from the work. The driver makes a note of the flight and the condition of the car.

  3. My second task of data entry for the second child passes to enter a name, right to the name. Why? Exactly the same code, but instead “char” – “string”.

      1. in string 39 cin.get();
        I wrote it?
        This is done, to clear the input buffer output from the keyboard. Sometimes in this buffer may remain some data.

    1. in string 39

      I wrote it?
      This is done, to clear the input buffer output from the keyboard. Sometimes in this buffer may remain some data.

  4. The third task in a row 25 array incorrectly filled

    I was his task to fill the array like this

    1. In string 25 – This designer matrix, which is filled by any of its rules.
      A 11, 22, 33 … in the condition shown both “for example”.
      A task – on the transposition of a matrix. Perhaps, it was not written in the best way, but all show – correctly.

  5. help to solve the problem:
    Describe the class of "USE".
    Each entry contains the form number, surname and initials of the student, Completion year, name items and evaluation.
    Provide for the possibility of formation: list from the keyboard and from file, Print the entire list; list of documents, where the average score below the CSE (higher) secondary; list of documents, The maximum score for a given discipline

  6. Goal number 2
    #include
    #include

    using namespace std;

    class MyClass
    {
    char name[32];
    char sourcename[32];
    int age;
    public:
    void Set_MyClass()
    {
    cout <> this->name;
    cout <> this->sourcename;
    cout <> this->age;
    }
    void Get_MyClass()
    {
    cout << "Name " << name << endl;
    cout << "Source " << sourcename << endl;
    cout << "Age " << age << endl;
    }
    };

    int main()
    {
    setlocale(LC_ALL, "Ukrainian");
    system("color A");

    MyClass first;
    MyClass second;

    cout << "Enter your date" << endl;
    first.Set_MyClass();
    second.Set_MyClass();
    cout << "\tYour date" << endl;
    first.Get_MyClass();
    second.Get_MyClass();

    _getch();
    return 0;
    }

  7. There must be a method. Somehow, when some threw garbage reflected
    void Set_MyClass()
    {
    cout <> this->name;
    cout <> this->sourcename;
    cout <> this->age;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *