Pozdrav svima
Imam problem jedan. Poceo sam da radim na nekom domacem za skolu ali imam problem. Nigde ne mogu da nadjem kako da radim sa Class-ama i Array's
Ovo ispod je prost primer
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
// defining a class
class human{
private:
int empNo;
char name[32];
char address[32];
float salary;
public:
void enterEmployee(int);
void listEmployee(int);
};
void human::enterEmployee(int i)
{
empNo = i;
cout << "\nEmployee No: " << empNo << endl;
cout << "Name: "; cin >> name;
cout << "Address: "; cin >> address;
cout << "Salary: "; cin >> salary; cout << endl;
cout << endl;
}
void human::listEmployee(int i)
{
cout << "Employee No: " << empNo << endl;
cout << "Name: " << name << endl;
cout << "Address: " << address << endl;
cout << "Salary: " << salary << endl;
cout << "-----------------" << endl;
}
// starting w/ main function
int main()
{
int i=0;
human emp1, emp2, emp3;
cout << "\n Enter the following information !" << endl;
emp1.enterEmployee(1);
emp2.enterEmployee(2);
emp3.enterEmployee(3);
cout << "\n List of Employees" << endl;
emp1.listEmployee(1);
emp2.listEmployee(2);
emp3.listEmployee(3);
return 0;
}
ovo sam samo probao da vidim da li ce da mi radi. vidite i sami da je glupo odradjeno. e sad, ja znam kako da uradim ovo u drugom jeziku ali ne i u C++.
sta u stvari hocu da uradim ?
hocu da imam array recimo
human name_array[5];
i da kasnije zovem funkciju fillArray
koja bi glasila nesto tipa
human::fillArray( E sad ne znam sta ovde da stavim)
{
// sta se sad ovde pise. jel nesto tipa ?
human[ i ].name = ........;
// ili
name_array[ i ].name = ....... ;
// ili nesto sasvim peto.
}
Ajde pomagajte ako mozete. Nadam se da ste me razumeli.
Znaci ovaj program sto sam gore napisao,hocu uprosten koristeci array's ali ne znam sintaksu.
Radim u VC++ (Win 2k).
Hvala
Uros
Imam problem jedan. Poceo sam da radim na nekom domacem za skolu ali imam problem. Nigde ne mogu da nadjem kako da radim sa Class-ama i Array's
Ovo ispod je prost primer
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
// defining a class
class human{
private:
int empNo;
char name[32];
char address[32];
float salary;
public:
void enterEmployee(int);
void listEmployee(int);
};
void human::enterEmployee(int i)
{
empNo = i;
cout << "\nEmployee No: " << empNo << endl;
cout << "Name: "; cin >> name;
cout << "Address: "; cin >> address;
cout << "Salary: "; cin >> salary; cout << endl;
cout << endl;
}
void human::listEmployee(int i)
{
cout << "Employee No: " << empNo << endl;
cout << "Name: " << name << endl;
cout << "Address: " << address << endl;
cout << "Salary: " << salary << endl;
cout << "-----------------" << endl;
}
// starting w/ main function
int main()
{
int i=0;
human emp1, emp2, emp3;
cout << "\n Enter the following information !" << endl;
emp1.enterEmployee(1);
emp2.enterEmployee(2);
emp3.enterEmployee(3);
cout << "\n List of Employees" << endl;
emp1.listEmployee(1);
emp2.listEmployee(2);
emp3.listEmployee(3);
return 0;
}
ovo sam samo probao da vidim da li ce da mi radi. vidite i sami da je glupo odradjeno. e sad, ja znam kako da uradim ovo u drugom jeziku ali ne i u C++.
sta u stvari hocu da uradim ?
hocu da imam array recimo
human name_array[5];
i da kasnije zovem funkciju fillArray
koja bi glasila nesto tipa
human::fillArray( E sad ne znam sta ovde da stavim)
{
// sta se sad ovde pise. jel nesto tipa ?
human[ i ].name = ........;
// ili
name_array[ i ].name = ....... ;
// ili nesto sasvim peto.
}
Ajde pomagajte ako mozete. Nadam se da ste me razumeli.
Znaci ovaj program sto sam gore napisao,hocu uprosten koristeci array's ali ne znam sintaksu.
Radim u VC++ (Win 2k).
Hvala
Uros