Hi All.. New here..
I'm not going to lie. This is an assignment for c++ subject in my school. I'm basically an amateur in c++. I can understand all the basic stuffs in c++, but have some problems with the pointer.. and my lecturer here.. well. She's quite poor and really she skips lots of stuffs and teaches simple things and asks us to do hard things.
I just post a summary from the assignment and my tries on that.. i need your help. Please. Not the exact solution. Just tell me an overview/ how to do it. It will be really helpful for me. And trust me i will remember your help forever. biggrin.gif
Ok here's the summary of 1st Q..
1) split a string using delimiters.
like..
19, St.John's street, Valley Lane becomes
unit no = 19
street address = st.jhons street
town = Valley Lane
and 18/24, greenwich
becomes unit no = 18, street address = 24, town = greenwich
delimiter canbe (/ , space, tab)
Here's my attempt ( a poor one)
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main ()
{
char str[200];
char * add;
cout<<"Enter a String"<<flush<<endl;
cin>>add;
while (add != NULL)
{
cout<<"string is:"<<add<<endl;
add = strtok (NULL, " ,.-");
}
system ("pause");
return 0;
}
2) linked list..
(we only need to use linked list and struct for this)..
there is a student struct with 3 attributes (studentId, name, major)..
and we need to enrol the student into subjects.. a student only can take 4 subjects at a time. the subjects has 4 attributes (section number, start time, start date and room number)..
there's another thing called course here, where the subjects will be offered. which means course ---> subjects ---> students
this is really confusing because i would have finished it had it been only one structure on it, now i'm confused because i don't know whether i have to use one struct for students (a must) or two for students and subjects..
Do i have to go through a normal linked list method or have to adapt doubly linked list method???
ok here's my effort..
#include <iostream>
using namespace std;
struct Student
{
char name [30];
char studentId [30];
char major [30];
Student *next;
};
struct CourseSection
{
char sectionNumber [20];
int startTime;
int startDate;
int roomNumber;
};
struct Node
{
Student stud;
CourseSection cs;
Node *next;
void add (char name[], char studentId[], char major[]);
int main()
{
struct student n1;
n1.name == "JOHN";
n1.next->name;
cout<<"Name:"<<n1.name<<endl;
n1.studentId == "ITV678";
n1.next->studentId;
n1.major == "Engineering";
n1.next->major;
add (name, studentId, major)
cout<<"Student Id:"<<n1.studentId<<endl;
cout<<"Major:"<<n1.major<<endl;
system("pause");
return 0;
void add (char name[20], char studentId[20], char major[20])
{
courseSection *temp1, *temp2;
temp new student;
cout<<"Enter the name of the student:"<<flush;
cin>>temp->student.name;
temp->next = NULL;
}
};
i know it's easier when i use class instead of structures.. but the assignment requires (forces) structure to be used..
(i've gone though the assignment/homework rule here.. well i don't want the exact solution.. just give me an idea how to start with that. or some examples)..
thanks in advance..