how to solve this error ? when i run the program after i enter the userlist capacity and enter the user informartion it gives me this error in the delete_scalar.cpp file.
I am beginner so Any help would be apprciated. This my code i will list the cpp files below :
user .cpp:
enter code here
#include "user.h"
#include <iostream>
using namespace std;
User::User()
{
name = "";
age = 0;
email = "";
password = "";
++Count;
id = Count;
}
User::User(string name1, int age1, string email1, string password1)
{
name = name1;
age = age1;
email = email1;
password = password1;
++Count;
id = Count;
}
User::User(const User& u)
{
name = u.name;
age = u.age;
email = u.email;
password = u.password;
++Count;
id = u.id;
}
void User::setName(string name1)
{
name = name1;
}
string User::getName()const
{
return name;
}
void User::setPassword(string password1)
{
password = password1;
}
string User::getPassword()const
{
return password;
}
void User::setEmail(string Email1)
{
email = Email1;
}
string User::getEmail()const
{
return email;
}
void User::setAge(int age1)
{
age = age1;
}
int User::getAge()const
{
return age;
}
void User::setId()
{
id = Count;
Count++;
}
int User::getId()const
{
return id;
}
bool User::operator==(const User& u)
{
bool status;
if (name == u.name && age == u.age && email == u.email && id == u.id)
{
status = true;
}
else
{
status = false;
}
return status;
}
ostream& operator<<(ostream& os, const User& u)
{
os << endl << "User name : " << u.name << " User id " << u.id << " User age " << u.age << " User email " << u.email << endl;
return os;
}
istream& operator>>(istream& is, User& u)
{
is >> u.name >> u.age >> u.email >> u.password;
return is;
}
book.cpp:
#include "book.h"
book::book()
{
title = "";
isbn = "";
++Count1;
id = Count1;
category = "";
averageRating = 0;
}
book::book(string title1, string isbn1, string category1, User author1)
{
title = title1;
isbn = isbn1;
category = category1;
author = author1;
++Count1;
id = Count1;
}
book::book(const book& b)
{
title = b.title;
isbn = b.isbn;
category = b.category;
author = b.author;
++Count1;
id = Count1;
}
void book::setTitle(string title1)
{
title = title1;
}
string book::getTitle()const
{
return title;
}
void book::setIsbn(string isbn1)
{
isbn = isbn1;
}
string book::getIsbn()const
{
return isbn;
}
void book::setCategory(string category1)
{
category = category1;
}
string book::getCategory()const
{
return category;
}
void book::setAuthor(User author1)
{
author = author1;
}
User book::getAuthor()const
{
return author;
}
void book::rateBook(int rating)
{
++numRates;
sumRates += rating;
averageRating = sumRates / numRates;
}
bool book:: operator ==(const book& b)
{
bool status;
if (title == b.title && isbn == b.isbn && category == b.category && author == b.author && id == b.id)
{
status = true;
}
else
{
status = false;
}
return status;
}
ostream& operator<<(ostream& os, const book& b)
{
os << endl << "book title : " << b.title << " book id " << b.id << " book isbn " << b.isbn << " book category " << b.category << " book average rating " << b.averageRating << endl;
return os;
}
istream& operator>>(istream& is, book& b)
{
is >> b.title >> b.isbn >> b.category;
return is;
}
Userlist.cpp:
#include "UserList.h"
#include <iostream>
using namespace std;
UserList::UserList(int capacity1)
{
capacity = capacity1;
users = new User[capacity];
usersCount = 0;
User userdef;
for (int i = 0; i < capacity; i++)
{
users[i] = userdef;
}
}
void UserList::addUser(User u)
{
users[usersCount] = u;
++usersCount;
}
User& UserList::searchUser(string name)
{
cin >> name;
for (int i = 0; i < capacity; i++)
{
if (name==users[i].getName() )
{
return users[i];
}
}
}
User& UserList::searchUser(int id)
{
cin >> id;
for (int i = 0; i < capacity; i++)
{
if (id = users[i].getId())
{
return users[i];
}
}
}
void UserList::deleteUser(int id)
{
cin >> id;
int i;
for ( i =0; i < usersCount; i++)
{
break;
}
for (i;i<usersCount;i++)
{
users[i + 1] = users[i];
}
usersCount--;
}
UserList::~UserList()
{
delete users;
}
ostream& operator<<(ostream& output, UserList& userList)
{
int capacity2=userList.capacity;
for (int i = 0; i < capacity2; i++)
{
output << userList.users[i]<<endl;
}
return output;
}
source.cpp:
#include <iostream>
using namespace std;
#include "User.h"
#include "book.h"
#include "UserList.h"
int User::Count = 0;
int book::Count1 = 0;
int main()
{
int capacity1;
cout << "enter capacity" << endl;
cin >> capacity1;
UserList u(capacity1);
User u1;
cout << "Let's add a user" << endl;
cout << "Enter the user info in this order" << endl;
cout << "Name || Age || Email || Password" << endl;
cin>> u1;
u.addUser(u1);
cout << u;
return 0;
}
output screen: