six_storm
03-19-07, 02:02 AM
Hey guys. I've never really asked for any programming help so here goes. Here is my code:
// Jonathan Andrew Scott
// CSCI 2010 - Jiang Li
// Assignment 5
// Deque Assignment
#include <iostream>
#include <string>
#include <deque>
using namespace std;
struct Student // data type to store information
{
string name;
char category;
};
struct Advisor
{
int advcode;
string name;
int nstuadv; // number of students seen
};
int main()
{
deque<Student> req[4]; // deques to store request information
Student stu; // struct to hold info for one student
Advisor adv[4]; // structs to store advisor information
adv[0].advcode = 2918;
adv[0].name = "Higgins";
adv[0].nstuadv = 0;
adv[1].advcode = 4502;
adv[1].name = "Beard";
adv[1].nstuadv = 0;
adv[2].advcode = 3408;
adv[2].name = "Watson";
adv[2].nstuadv = 0;
adv[3].advcode = 5644;
adv[3].name = "Sherwood";
adv[3].nstuadv = 0;
// Initialize advisor information
// e.g. adv[0].advcode = 2918;
// adv[0].name = "Higgins";
// adv[0].nstuadv = 0;
char reqcode;
int advcode;
bool isValid;
cout << endl << "Request Code: ";
cin >> reqcode;
reqcode = toupper(reqcode);
while (reqcode != 'Q') // exit if request code is Q
{
if (reqcode == 'R') // request to see an advisor
{
cout << "Student Name: ";
getline(cin, stu.name);
cout << endl;
cout << "Category: ";
cin >> stu.category;
// 1. input student's name and category, e.g.,
// Student Name: Brown, Susan
// Category: O
if(stu.category == 'S')
{
req[0].push_back(stu);
}
else if(stu.category == 'W')
{
req[1].push_back(stu);
}
else if(stu.category == 'O')
{
req[2].push_back(stu);
}
else if(stu.category == 'T')
{
req[3].push_back(stu);
}
else
{
cout << "Invalid Category" << endl;
cout << "Category: ";
cin >> stu.category;
}
// 2. put (push_back) student's request into the appropriate deque
// based on the student's category
} // end if
else if (reqcode == 'A') // advisor available to see a student
{
cout << "Advisor Code: ";
cin >> advcode;
// 1. input advisor code
if(advcode == '2918')
{
stu = req[0].front();
cout << adv[0].name << " is advising " << stu.name << ". /n";
req[0].pop_front();
}
else if(advcode == '4502')
{
stu = req[1].front();
cout << adv[1].name << " is advising " << stu.name << ". /n";
req[1].pop_front();
}
else if(advcode == '3408')
{
stu = req[2].front();
cout << adv[2].name << " is advising " << stu.name << ". /n";
req[2].pop_front();
}
else if(advcode == '5644')
{
stu = req[3].front();
cout << adv[3].name << " is advising " << stu.name << ". /n";
req[3].pop_front();
}
else
{
cout << "Invalid Advisor Code, Try Again" << endl;
cout << "Advisor Code: ";
cin >> advcode;
}
// 2. Use this code to find the advisor, e.g., adv[2],
// then check req[2] (because req[i] holds requests for adv[i])
// If a student is waiting to see the advisor, i.e., adv[2] is not empty
// print the student's name and the advisor's name,
// and remove (pop_front) that student from the deque.
} // end else if
else
cout << "Invalid Request Code" << endl;
cout << endl << "Request Code: ";
cin >> reqcode;
reqcode = toupper(reqcode);
} // end while
// Print out information after receiving input 'Q'
for (int i=0; i<4; i++)
{
if (!req[i].empty())
{
stu=req[i];
cout << "The following students are waiting for advisor " << adv[i].name << endl;
cout << stu.name << endl;
// print students who are waiting to see an advisor in each deque
}
// print the total number of students seen by each advisor
cout << endl << adv[i].name << " has seen " << req[i].size() << "student(s).";
cout << endl;
}
}
I'm having trouble trying to figure out a few things. Actually, I just need to find out why I can't compile my code. Notice anything? Guess two sets of eyes are better than one. My compiler notices problems around the bolded areas jsyk.
// Jonathan Andrew Scott
// CSCI 2010 - Jiang Li
// Assignment 5
// Deque Assignment
#include <iostream>
#include <string>
#include <deque>
using namespace std;
struct Student // data type to store information
{
string name;
char category;
};
struct Advisor
{
int advcode;
string name;
int nstuadv; // number of students seen
};
int main()
{
deque<Student> req[4]; // deques to store request information
Student stu; // struct to hold info for one student
Advisor adv[4]; // structs to store advisor information
adv[0].advcode = 2918;
adv[0].name = "Higgins";
adv[0].nstuadv = 0;
adv[1].advcode = 4502;
adv[1].name = "Beard";
adv[1].nstuadv = 0;
adv[2].advcode = 3408;
adv[2].name = "Watson";
adv[2].nstuadv = 0;
adv[3].advcode = 5644;
adv[3].name = "Sherwood";
adv[3].nstuadv = 0;
// Initialize advisor information
// e.g. adv[0].advcode = 2918;
// adv[0].name = "Higgins";
// adv[0].nstuadv = 0;
char reqcode;
int advcode;
bool isValid;
cout << endl << "Request Code: ";
cin >> reqcode;
reqcode = toupper(reqcode);
while (reqcode != 'Q') // exit if request code is Q
{
if (reqcode == 'R') // request to see an advisor
{
cout << "Student Name: ";
getline(cin, stu.name);
cout << endl;
cout << "Category: ";
cin >> stu.category;
// 1. input student's name and category, e.g.,
// Student Name: Brown, Susan
// Category: O
if(stu.category == 'S')
{
req[0].push_back(stu);
}
else if(stu.category == 'W')
{
req[1].push_back(stu);
}
else if(stu.category == 'O')
{
req[2].push_back(stu);
}
else if(stu.category == 'T')
{
req[3].push_back(stu);
}
else
{
cout << "Invalid Category" << endl;
cout << "Category: ";
cin >> stu.category;
}
// 2. put (push_back) student's request into the appropriate deque
// based on the student's category
} // end if
else if (reqcode == 'A') // advisor available to see a student
{
cout << "Advisor Code: ";
cin >> advcode;
// 1. input advisor code
if(advcode == '2918')
{
stu = req[0].front();
cout << adv[0].name << " is advising " << stu.name << ". /n";
req[0].pop_front();
}
else if(advcode == '4502')
{
stu = req[1].front();
cout << adv[1].name << " is advising " << stu.name << ". /n";
req[1].pop_front();
}
else if(advcode == '3408')
{
stu = req[2].front();
cout << adv[2].name << " is advising " << stu.name << ". /n";
req[2].pop_front();
}
else if(advcode == '5644')
{
stu = req[3].front();
cout << adv[3].name << " is advising " << stu.name << ". /n";
req[3].pop_front();
}
else
{
cout << "Invalid Advisor Code, Try Again" << endl;
cout << "Advisor Code: ";
cin >> advcode;
}
// 2. Use this code to find the advisor, e.g., adv[2],
// then check req[2] (because req[i] holds requests for adv[i])
// If a student is waiting to see the advisor, i.e., adv[2] is not empty
// print the student's name and the advisor's name,
// and remove (pop_front) that student from the deque.
} // end else if
else
cout << "Invalid Request Code" << endl;
cout << endl << "Request Code: ";
cin >> reqcode;
reqcode = toupper(reqcode);
} // end while
// Print out information after receiving input 'Q'
for (int i=0; i<4; i++)
{
if (!req[i].empty())
{
stu=req[i];
cout << "The following students are waiting for advisor " << adv[i].name << endl;
cout << stu.name << endl;
// print students who are waiting to see an advisor in each deque
}
// print the total number of students seen by each advisor
cout << endl << adv[i].name << " has seen " << req[i].size() << "student(s).";
cout << endl;
}
}
I'm having trouble trying to figure out a few things. Actually, I just need to find out why I can't compile my code. Notice anything? Guess two sets of eyes are better than one. My compiler notices problems around the bolded areas jsyk.