Премини към съдържанието
Форумът в приложение

По-лесно сърфиране. Научи повече.

Kaldata.com - Форуми

Приложение на форума на цял екран с push известия, значки и други.

За да инсталирате това приложение на iOS и iPadOS
  1. Докоснете Иконата за споделяне в Safari
  2. Превъртете менюто и докоснете Добавяне към началния екран.
  3. Докоснете Добавяне в горния десен ъгъл.
За да инсталирате това приложение на Android
  1. Докоснете менюто с 3 точки (⋮) в горния десен ъгъл на браузъра.
  2. Докоснете Добавяне към началния екран или Инсталиране на приложение.
  3. Потвърдете, като докоснете Инсталиране.

Добре дошли!

Добре дошли в нашите форуми, пълни с полезна информация. Имате проблем с компютъра или телефона си? Публикувайте нова тема и ще намерите решение на всичките си проблеми. Общувайте свободно и открийте безброй нови приятели.

Моля, регистрирайте се за да публикувате тема и да получите пълен достъп до всички функции.

 

Трябва ми спешна помощ за задача на c++

Featured Replies

Здравейте имам да предам курсова работа утре ,но не мога да я реша , ще бъда изключително благодарен ако може някой да ми помогне.

Дефинирайте клас Телевизор, който да е родител на клас Самсунг и клас Сони. Клас Телевизор да има цена и брой продадени за година в сектор private. Класовете Самсунг и Сони да имат в сектор public функции за определяне на общата сума от продажби за година (цена * брой продадени за година). Всички класове да имат конструктори по подразбиране.
 

Благодаря предварително !

преди 9 часа, Georgi Kirchev написа:

Здравейте имам да предам курсова работа утре ,но не мога да я реша , ще бъда изключително благодарен ако може някой да ми помогне.

Дефинирайте клас Телевизор, който да е родител на клас Самсунг и клас Сони. Клас Телевизор да има цена и брой продадени за година в сектор private. Класовете Самсунг и Сони да имат в сектор public функции за определяне на общата сума от продажби за година (цена * брой продадени за година). Всички класове да имат конструктори по подразбиране.
 

Благодаря предварително !

#include <iostream>
#include <cstdlib>
using namespace std;
class TV
   {
   protected:
    float price;
    int quantity;
   public:
    TV();//constructor
    TV(float price, int quantity);
    void set_price(float);
    void set_quantity(int);
    float get_price();
    int get_quantity() const;
    float get_price() const;
   };
   TV::TV()
   {
       this->price=10;
       this->quantity=2;
   }
   TV::TV(float price, int quantity)
   {
       this->price=price;
       this->quantity=quantity;
   }
   float TV::get_price() const
   {
       return price;
   }
   int TV::get_quantity() const
   {
       return quantity;
   }
   class Sony:public TV
   {
       public:
           float calculate() const;
           Sony(); //construnctor
           Sony(float price, int quantity);
   };
   class Samsung:public TV
   {
       public:
           float calculate() const;
           Samsung(); //constructor
           Samsung(float price, int quantity);
   };
   Sony::Sony(float price, int quantity)
   {
       this->price=price;
       this->quantity=quantity;
   }
   Samsung::Samsung(float price, int quantity)
   {
       this->price=price;
       this->quantity=quantity;
   }
    float Sony::calculate()const
   {
       float price=get_price();
       int quantity=get_quantity();
       cout<<"Annual sellings"<<price*quantity<<endl;
   }
    float Samsung::calculate()const
   {
       float price=get_price();
       int quantity=get_quantity();
       cout<<"Annual sellings"<<price*quantity<<endl;
   }
int main()
{
  Samsung S1(10,5);
  S1.calculate();
}

 

  • Автор
преди 3 часа, Даскала написа:

#include <iostream>
#include <cstdlib>
using namespace std;
class TV
   {
   protected:
    float price;
    int quantity;
   public:
    TV();//constructor
    TV(float price, int quantity);
    void set_price(float);
    void set_quantity(int);
    float get_price();
    int get_quantity() const;
    float get_price() const;
   };
   TV::TV()
   {
       this->price=10;
       this->quantity=2;
   }
   TV::TV(float price, int quantity)
   {
       this->price=price;
       this->quantity=quantity;
   }
   float TV::get_price() const
   {
       return price;
   }
   int TV::get_quantity() const
   {
       return quantity;
   }
   class Sony:public TV
   {
       public:
           float calculate() const;
           Sony(); //construnctor
           Sony(float price, int quantity);
   };
   class Samsung:public TV
   {
       public:
           float calculate() const;
           Samsung(); //constructor
           Samsung(float price, int quantity);
   };
   Sony::Sony(float price, int quantity)
   {
       this->price=price;
       this->quantity=quantity;
   }
   Samsung::Samsung(float price, int quantity)
   {
       this->price=price;
       this->quantity=quantity;
   }
    float Sony::calculate()const
   {
       float price=get_price();
       int quantity=get_quantity();
       cout<<"Annual sellings"<<price*quantity<<endl;
   }
    float Samsung::calculate()const
   {
       float price=get_price();
       int quantity=get_quantity();
       cout<<"Annual sellings"<<price*quantity<<endl;
   }
int main()
{
  Samsung S1(10,5);
  S1.calculate();
}

 

благодаря за положения труд но за жалост не работи при мен и ми изписва следните грешки :
1>c:\users\pc\documents\visual studio 2013\projects\consoleapplication2\consoleapplication2\consoleapplication2.cpp(72): error C4716: 'Sony::calculate' : must return a value
1>c:\users\pc\documents\visual studio 2013\projects\consoleapplication2\consoleapplication2\consoleapplication2.cpp(78): error C4716: 'Samsung::calculate' : must return a value

преди 14 минути, Georgi Kirchev написа:

благодаря за положения труд но за жалост не работи при мен и ми изписва следните грешки :
1>c:\users\pc\documents\visual studio 2013\projects\consoleapplication2\consoleapplication2\consoleapplication2.cpp(72): error C4716: 'Sony::calculate' : must return a value
1>c:\users\pc\documents\visual studio 2013\projects\consoleapplication2\consoleapplication2\consoleapplication2.cpp(78): error C4716: 'Samsung::calculate' : must return a value

Аз не ползвам Visual Studio, а Code Blocks. Програмата работи, компилатора на Микромеките се цупи.
Пиши функцията calculate като VOID и виж дали ще тръгне компилацията.

п.п И на коде блока дава известие, че функцията не връща.
Пиши в public-а на децата void calculate и след това долу в описанието на функицията извън класа отново void.
 

#include <iostream>
#include <cstdlib>
using namespace std;
class TV
   {
   protected:
    float price;
    int quantity;
   public:
    TV();//constructor
    TV(float price, int quantity);
    void set_price(float);
    void set_quantity(int);
    float get_price();
    int get_quantity() const;
    float get_price() const;
   };
   TV::TV()
   {
       this->price=10;
       this->quantity=2;
   }
   TV::TV(float price, int quantity)
   {
       this->price=price;
       this->quantity=quantity;
   }
   float TV::get_price() const
   {
       return price;
   }
   int TV::get_quantity() const
   {
       return quantity;
   }
   class Sony:public TV
   {
       public:
           void calculate() const;
           Sony(); //construnctor
           Sony(float price, int quantity);
   };
   class Samsung:public TV
   {
       public:
           void calculate() const;
           Samsung(); //constructor
           Samsung(float price, int quantity);
   };
   Sony::Sony(float price, int quantity)
   {
       this->price=price;
       this->quantity=quantity;
   }
   Samsung::Samsung(float price, int quantity)
   {
       this->price=price;
       this->quantity=quantity;
   }
    void Sony::calculate()const
   {
       float price=get_price();
       int quantity=get_quantity();
       cout<<"Annual sellings"<<price*quantity<<endl;
   }
    void Samsung::calculate()const
   {
       float price=get_price();
       int quantity=get_quantity();
       cout<<"Annual sellings"<<price*quantity<<endl;
   }
int main()
{
  Samsung S1(10,5);
  S1.calculate();
}

 

Ето резултата от компилирането:
 

-------------- Build: Debug in klas (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -fexceptions -g  -c D:\cc\klas\main.cpp -o obj\Debug\main.o
mingw32-g++.exe  -o bin\Debug\klas.exe obj\Debug\main.o   
Output file is bin\Debug\klas.exe with size 1.50 MB
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))
 

-------------- Run: Debug in klas (compiler: GNU GCC Compiler)---------------

Checking for existence: D:\cc\klas\bin\Debug\klas.exe
Executing: "C:\Program Files (x86)\CodeBlocks/cb_console_runner.exe" "D:\cc\klas\bin\Debug\klas.exe"  (in D:\cc\klas\.)
Process terminated with status -1073741510 (0 minute(s), 2 second(s))

 

  • Автор
преди 16 часа, Даскала написа:

Аз не ползвам Visual Studio, а Code Blocks. Програмата работи, компилатора на Микромеките се цупи.
Пиши функцията calculate като VOID и виж дали ще тръгне компилацията.

п.п И на коде блока дава известие, че функцията не връща.
Пиши в public-а на децата void calculate и след това долу в описанието на функицията извън класа отново void.
 


#include <iostream>
#include <cstdlib>
using namespace std;
class TV
   {
   protected:
    float price;
    int quantity;
   public:
    TV();//constructor
    TV(float price, int quantity);
    void set_price(float);
    void set_quantity(int);
    float get_price();
    int get_quantity() const;
    float get_price() const;
   };
   TV::TV()
   {
       this->price=10;
       this->quantity=2;
   }
   TV::TV(float price, int quantity)
   {
       this->price=price;
       this->quantity=quantity;
   }
   float TV::get_price() const
   {
       return price;
   }
   int TV::get_quantity() const
   {
       return quantity;
   }
   class Sony:public TV
   {
       public:
           void calculate() const;
           Sony(); //construnctor
           Sony(float price, int quantity);
   };
   class Samsung:public TV
   {
       public:
           void calculate() const;
           Samsung(); //constructor
           Samsung(float price, int quantity);
   };
   Sony::Sony(float price, int quantity)
   {
       this->price=price;
       this->quantity=quantity;
   }
   Samsung::Samsung(float price, int quantity)
   {
       this->price=price;
       this->quantity=quantity;
   }
    void Sony::calculate()const
   {
       float price=get_price();
       int quantity=get_quantity();
       cout<<"Annual sellings"<<price*quantity<<endl;
   }
    void Samsung::calculate()const
   {
       float price=get_price();
       int quantity=get_quantity();
       cout<<"Annual sellings"<<price*quantity<<endl;
   }
int main()
{
  Samsung S1(10,5);
  S1.calculate();
}

 

Ето резултата от компилирането:
 


-------------- Build: Debug in klas (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -fexceptions -g  -c D:\cc\klas\main.cpp -o obj\Debug\main.o
mingw32-g++.exe  -o bin\Debug\klas.exe obj\Debug\main.o   
Output file is bin\Debug\klas.exe with size 1.50 MB
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))
 

-------------- Run: Debug in klas (compiler: GNU GCC Compiler)---------------

Checking for existence: D:\cc\klas\bin\Debug\klas.exe
Executing: "C:\Program Files (x86)\CodeBlocks/cb_console_runner.exe" "D:\cc\klas\bin\Debug\klas.exe"  (in D:\cc\klas\.)
Process terminated with status -1073741510 (0 minute(s), 2 second(s))

 

още веднъж ОГРОМНО благодаря за положения труд , но за жалост така и не успях да подкарам твоят вариант , а останах да се мъча цяла вечер и в крайна сметка измъдрих това решение , но не знам как да изкарам резултата като едно цяло от TV , а не поотделно от Sony и Samsung.



 

#include "stdafx.h"
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

class TV{
private:
    int sales;
    double price;
public:
};

class Sony :public TV{
private:
    int sales;
    double price;
public:
    void set(int, double);
    void print();
};

void Sony::set(int arg1, double arg2){
    sales = arg1;
    price = arg2;
}
void Sony::print(){
    cout << (price * sales) << endl;

}
class Samsung : public TV{
private:
    int sales;
    double price;
public:
    void set(int, double);
    void print();
};

void Samsung::set(int arg3, double arg4){
    sales = arg3;
    price = arg4;
}
void Samsung::print(){
    cout << (sales * price) << endl;

}
int main()
{
    Sony w1;
    w1.set(400, 30);
    w1.print();
    Samsung w2;
    w2.set(300, 40);
    w2.print();
}

Понеже нямам Visual Studio, дай какви грешки дава от втория ми вариант. Интересно ми е 

Архивирана тема

Темата е твърде стара и е архивирана. Не можете да добавяте нови отговори в нея, но винаги можете да публикувате нова тема, в която да продължи дискусията. Регистрирайте се или влезте във вашия профил за да публикувате нова тема.

Разглеждащи това в момента 0

  • Няма регистрирани потребители разглеждащи тази страница.

Дарение

  • Подкрепи съществуването на форума - направи дарение
    26%
    Дарени 256.00 EUR от нужните 1,000.00 EUR

Бюлетин

Получавайте известие, когато има важна промяна или новина свързана с форума.

Профил

Навигация

Търсене

Търсене

Конфигуриране на push известия в браузъра

Chrome (Android)
  1. Докоснете иконата на катинар до адресната лента.
  2. Докоснете Разрешения → Известия.
  3. Променете предпочитанията си.
Chrome (Desktop)
  1. Кликнете върху иконата на катинар в адресната лента.
  2. Изберете Настройки на сайта.
  3. Намерете Известия и коригирайте предпочитанията си.