HiveBrain v1.2.0
Get Started
← Back to all entries
patterncppMinor

C++ mock social networking program

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
socialmocknetworkingprogram

Problem

I'm currently working on my final project of my first semester of C++ (and programming in general). What my professor wants us to do is to make a mock social media program that has some basic functions such as:

  • Sign up



  • Sign in



  • Follow user



  • Write a post



  • View Activity – (Activity from friends)



  • View Profile – (Username, followers, people you follow, posts from you)



  • Sign Out



  • Exit



On the prompt it says that he:


"expects to see knowledge of the material, in particular Object Oriented Design - Classes".

I assume that means that we should be using classes properly.

That brings me to my general question about the code I have, which is whether or not I'm fulfilling that "requirement" of demonstrating knowledge of using classes (or objects or whatever he's probably expecting).

project02.cpp

```
#include
#include
#include
#include
#include "project02.h"

using namespace std;

ofstream fout;
ifstream fin;

void LoginScreen()
{
cout > fName;
setFirstName(fName);

cout > lName;
setLastName(lName);

cout > bYear;
setBirthYear(bYear);

cout > screenName;
isTaken = false;
fin.open("RegisteredUsers.txt");
while (!fin.eof())
{
getline(fin, line);
if ((offset = line.find(screenName, 0)) != string::npos)
{
isTaken = true;
cout > screen;
cout > screenName;
exists = true;
fin.open("RegisteredUsers.txt");
while (!fin.eof())
{
getline(fin, line);
if ((offset = line.find(screenName, 0)) == string::npos)
{
exists = false;
cout << endl;
cout << "User " << screenName << " does not exist!" << endl << endl;
cout << "Please enter an existing username to sign in: ";
}
}
fin.close();
} while (exists = false || exists !=

Solution

Namespaces

using namespace std; is considered bad practice. Short code is not a requirement in C++, clear code is preferred.

Return

return 0; is a legacy from C. In C++, it's no longer required to write this manually at the end of main. The compiler will take care of returning 'normal' if no errors where thrown or other returns (like -1) are encountered.

Naming

A project with a name like project02 will be hard to find if you need parts of it later. Try giving it a more meaningful name.

The following is confusing:

else if (input != '1' && input != '2' && input != '3' && input != '4')


Why is that not simply the latest else statement? If none of the other ifs are true, the input is and should be invalid.

Code Snippets

else if (input != '1' && input != '2' && input != '3' && input != '4')

Context

StackExchange Code Review Q#113119, answer score: 7

Revisions (0)

No revisions yet.