Advertisement
irmantas_radavicius

Untitled

May 7th, 2024
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <vector>
  5. #include <cmath>
  6. #include <cctype>
  7. #include <array>
  8.  
  9. using namespace std;
  10.  
  11. class Part{
  12.     string Name;
  13.     int Sn;
  14.     double Weight;
  15.     string Type;
  16.  
  17.     public:
  18.         string setType(double weight) {
  19.             return (weight > 50) ? "heavy" : "light";
  20.         }
  21.     private:
  22.         void init(string name, int Sn, int Weight){
  23.             Name = name;
  24.             this->Sn = Sn;
  25.             this->Weight = Weight;
  26.             Type = setType(Weight);
  27.         }
  28.     public:
  29.         Part(){
  30.             init("unknown part", 0, 0);
  31.         }
  32.         Part(string Name){
  33.             init(Name, 0, 0);
  34.         }
  35.         Part(string name, int Sn, int Weight){
  36.             init(Name, Sn, Weight);
  37.         }
  38.  
  39.         void setParam(int sn, int weight){
  40.             init(Name, sn, weight);
  41.         }
  42.  /*  //////////////////////////////////////// kaip padaryti, kad pagal varda grazintu Sn?
  43.         double getSn(string name){
  44.             ...
  45.             return Sn;
  46.         }
  47. */  ///////////////////////////////////////
  48.         void getPartInf(){
  49.             cout << Name << "|" << Sn << "|" << Weight << "|" << Type << endl;
  50.         }
  51.  
  52. };
  53.  
  54. int main(){
  55.     Part p1(), p2("stumoklis"), p3("piston", 2546, 32);
  56.  
  57.     p3.getPartInf();
  58.  
  59.     p2.setParam(3567, 55);
  60.     p2.getPartInf();
  61.  
  62.     return 0;
  63. }
  64.  
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement