Hey all! I'm currently learning C++ using Stephen Prata's
C++ Primer Plus and loving the adventure so far. Well.. for the most part. Anyway, one of the programming exercises for the chapter I just finished (on branching statements and logical operators) ask you to create a structure that holds the member information of member of the Benevolent Order of Programmers. This structure is supposed to include the members' names, titles, nicknames, and preference for which of those 3 they would like displayed. Then you are supposed to display a menu that allows you to choose how to display the information, either by name, title, nickname, or the member's preference. Anyway, I went a step further and also added a bit to allow the user to input that information manually, instead of through a structure initialization. This also included the user defining how many records they wanted to add. Anyway, here's the code I got so far. I'm sure there's little syntax errors in it, which I will clean up after I get the structure working properly:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
#include <iostream>
#include <string>
struct record
{
std::string str_Name;
std::string str_Title;
std::string str_Nickname;
int n_Pref;
};
int main()
{
std::cout << "How many records would you like to enter into the\n"
<< "BOP's database?\n"
<< std::endl;
int n_NumRecs = 0;
std::cin >> n_NumRecs;
record* p_Records;
p_Records = new record[n_NumRecs];
for (int i = 0; i < n_NumRecs; i++)
{
std::cout << "Enter the name for record " << i << ":";
getline(std::cin, p_Records[i].str_Name);
std::cout << "Enter the title for record " << i << ":";
getline(std::cin, p_Records[i].str_Title);
std::cout << "Enter the nickname for record " << i << ":";
getline(std::cin, p_Records[i].str_Nickname);
std::cout << "Enter the persons preference for name display\n (0 = Full Name, 1 = Title, 3 = Nickname): ";
std::cin >> p_Records[i].n_Pref;
}
std::cout << "Data entry complete.\n";
showmenu();
char c_MenuChoice;
std::cin >> c_MenuChoice;
while (c_MenuChoice != q)
{
switch (c_MenuChoice)
{
case 'a' :
{
for (int i = 0; i < n_NumRecs; i++)
std::cout << p_Records[i].str_Name;
}
case 'b' :
{
for (int i = 0; i < n_NumRecs; i++)
std::cout << p_Record[i].str_Title;
}
case 'c' :
{
for (int i = 0; i < n_NumRecs; i++)
std::cout << p_Record[i].str_Nickname;
}
case 'd' :
{
for (int i = 0; i < n_NumRecs; i++)
{
switch (p_Record[i].n_Pref)
{
case 0 : std::cout << p_Record[i].str_Name;
case 1 : std::cout << p_Record[i].str_Title;
case 2 : std::cout << p_Record[i].str_Nickname;
}
}
}
case 'q' :
break;
case default :
std::cout << "That wasn't a valid option you butt-munching anal-dweller.";
}
showmenu();
std::cin >> c_MenuChoice;
}
std::cout << "Bye!";
delete p_records;
return 0;
}
void showmenu()
{
std::cout << "Benevolent Order of Programmers Members Report\n"
<< "a. Display by name b. Display by title\n"
<< "c. Display by nickname d. Display by preference\n"
<< "q. Quit\n";
}
|
The problem I am running into is that on line 23 the compiler throws an error stating :
C:\Users\Raezzor\Desktop\Coding Projects\6.4\main.cpp|23|note: synthesized method 'record::record()' first required here |
I tried searching for this on google, but there were precious few results actually related to programming, and of those that were, most were talking about class constructors/destructors. IE, stuff over my head. From what I can see, I followed the correct method to declare the pointer for the dynamic array and all in this code:
1 2
|
record* p_Records;
p_Records = new record[n_NumRecs];
|
so I'm not sure what's going on. Any help is appreciated. And if needed I'll add comments where appropriate. I try to make my code as readable as possible, but I imagine some folks are used to other styles. :)