Компьютерный форум NoWa.cc

Компьютерный форум NoWa.cc (https://nowa.cc/index.php)
-   Visual C++ / С/C++ (https://nowa.cc/forumdisplay.php?f=302)
-   -   помогите пожалуста c программой на с++(сдавать срочно) (https://nowa.cc/showthread.php?t=152180)

XXXAlex 18.03.2008 10:04

помогите пожалуста c программой на с++(сдавать срочно)
 
только начинаю осваивать Visual C++, написал часть программы - не знаю как доделать

Проект нужно сдавать через пару дней а я не знаю как завершить прогу, помогите кто может:wow:
Заранее большое спасибо!!!! :sos:


Задание:


-The class is called “Worker”.

-It has 3 private members: name (char type), age (integer type), salary(double type).

-It has two constructors:

one has no arguments and it initializes name with 'C', age with 20, and salary with 100.00;
the other takes two arguments (char char1, int var_age) and it initializes name with char1’s value, age with var_age’s value,

and salary with 200.00.

-The class also has a member function access which outputs name’s value, age’s value, and salary’s value to screen.

-The class has a friend function overloading operator == so that it will return true when comparing two objects of the same

class Worker. For example, if wk1 and wk2 are two objects of class Worker and their 3 private members are same, (wk1= =wk2)

will return true.

-Write a main program to test your class implementation.

Код:



//Worker.cpp

#include "Worker.h"
#include <iostream>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
 
Worker:Worker(char char1, int var_age)
// determine if two Worker are equal and return true, otherwise return false

  bool Worker::operator ==( const Worker &right,const Worker &left) const
  {
      if ((right.getChar != left.getChar) && (right.getAge != left.getAge))
        return false;
          else     
            return true;
  } // end function operator==



Код:


//Header file

#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <iostream>

#ifndef Worker_H
#define Worker_H

class Worker //time
{
public:
  Worker( char = 'C'; age = 20; salary = 100.00 ); // constructor
  Worker(char char1, int var_age); //constructor
  worker=char1;
  age=var_age;
  salary=200.00;       
private:
  char worker;
  int age;
  double salary;

friend bool operator==(const Worker &)const;

    // inequality operator; returns opposite of == operator   
    bool operator!=( const Worker &right,const Worker &left) const               
    {                                                         
        return ! ((*this == right)&&(*this == left); // invokes Worker::operator==
    } // end function operator!=                               

}; // end class Time

#endif



Код:


// prj33.cpp
#include "stdafx.h"
#include "Worker.h"
using std::cout;
using std::cin;
using std::endl;

int main()
{
        Worker cc1('A',13)
       
       
       
        return 0;
}


stich 18.03.2008 12:58

Ответ: помогите пожалуста c программой на с++(сдавать срочно)
 
я б так написал...


#include <iostream>
#include <cstdio>

using namespace std;

class Worker {
char worker;
int age;
double salary;

public:
Worker(): worker('C'), age(20), salary(100.00) {}
Worker(char char1, int var_age): worker(char1), age(var_age), salary(200.00) {}
void output() {
cout << "----------" << endl << "wolker: " << worker <<
endl << "age: " << age << endl << "salary: " << salary << endl;
}

friend bool operator==(const Worker&, const Worker&);
};

bool operator==(const Worker &w1, const Worker &w2) {
return w1.age == w2.age && w1.worker == w2.worker && w1.salary == w2.salary;
}

bool operator!=(const Worker &w1, const Worker &w2) { return !(w1 == w2); }

int main() {

Worker w1;
Worker w2('A', 30);

w1.output();
w2.output();

cout << endl;
if (w1 == w2) cout << "equal"; else cout << "not equal";
cout << endl;

return EXIT_SUCCESS;
}

XXXAlex 19.03.2008 05:30

Ответ: помогите пожалуста c программой на с++(сдавать срочно)
 
stich
друг спасибо большое:super:. сижу разбираюсь.


Текущее время: 20:58. Часовой пояс GMT +3.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2026, vBulletin Solutions, Inc. Перевод: zCarot
Copyright ©2004 - 2025 NoWa.cc

Время генерации страницы 0.01932 секунды с 9 запросами