witam,
mam pewien kłopot nie umiej Sobie z nim poradzić, bo nie wiem na czym polega błąd. t ma być program obiektowy c++, ma obliczać średnią podanych ocen i zamieniać ocenę na zadanej pozycji (tego nie wiem jak zaimplementować w kalsach), czy ktoś mi pomoże:
// subject.cpp : Ten plik zawiera funkcję „main”. W nim rozpoczyna się i kończy wykonywanie programu.
//
#include <iostream>
#include <ctime>
using namespace std;
class subject
{
public:
subject(int nr_indeksu, int l_rating);
~subject();
double calcRating(); // oblicza srednia arytmetyczna ocen
bool success(); // okresla czy student otrzyma zaliczenie
void getRating(double rat); // dodaje nowa ocene
void chanRating(double rat, int id); // zmienia ocene
void get(); // wypisuje na ekranie informacje
protected:
private:
double* rating; // oceny studenta
int n_index; // numer indeksu studenta
int n_rating; // liczba wprowadzonych ocen
int l_rating; // maksymalna liczba ocen
};
int main()
{
cout << "Wtiamy w programie do obliczania sredniej oceny!\n";
int ix, nR;
double R;
cout << "podaj nr indeksu: ";
cin >> ix;
cout << "Ile ocen bedziemy brali pod uwage: ";
cin >> nR;
subject cr(ix, nR);
srand(time(NULL));
for (int i = 0; i < nR; i++)
cr.calcRating(rand() % 5);
cout << "Srednia ocen " << cr.calcRating() << endl;
if (cr.success())
cout << "Zaliczone" << endl;
else
cout << "Nie zaliczone" << endl;
cr.chanRating(3.0, nR);
cout << "Srednia ocen " << cr.calcRating() << endl;
if (cr.success())
cout << "Zaliczone" << endl;
else
cout << "Nie zaliczone" << endl;
cr.get();
return 0;
}
// Uruchomienie programu: Ctrl + F5 lub menu Debugowanie > Uruchom bez debugowania
// Debugowanie programu: F5 lub menu Debugowanie > Rozpocznij debugowanie
subject::subject(int n_index, int l_rating) : n_index(n_index), l_rating(l_rating) {
rating = new double[l_rating];
}
subject::~subject() {
delete[] rating;
}
double subject::calcRating() {
double average = 0;
for (int i = 0; i < n_rating; i++)
average += rating[i];
return average / n_rating;
}
bool subject::success() {
double average = calcRating();
if (average >= 3.0)
return true;
else
return false;
}
void subject::getRating(double rat) {
if (n_rating >= l_rating)
std::cout << "Za duzo ocen" << std::endl;
rating[n_rating++] = rat;
}
void subject::chanRating(double rat, int id) {
if (id > n_rating)
std::cout << "Nieprawidlowy indeks" << std::endl;
rating[id] = rat;
}
void subject::get() {
std::cout << "Student legitymacja nr = " << n_index << std::endl;
std::cout << "W semestrze otrzymal nastepujace oceny : ";
for (int i = 0; i < n_rating; i++)
std::cout << rating[i] << ", ";
std::cout << std::endl;
std::cout << "Srednia ocen = " << calcRating() << std::endl;
if (success())
std::cout << "Semestr zaliczony" << std::endl;
else
std::cout << "Semestr nie zaliczony" << std::endl;
}