dimanche 22 février 2015

How to use vector member functions and valid emails?


I'm not exactly sure how to go on with my program from here. I'm new to vectors and not sure if this is the correct use of vectors. My program asks to use a member function (append) that would read and add lines of text to the message one line at a time. Is my append function correct? Also how would I validate passed email addresses in the constructor? If there is no provided email, do I use break? How can I end my input with char "."? This program doesn't use external files. This is my program so far:



#include <iostream>
#include <string>
#include <vector>
#include <ctime>

using namespace std;

class Message{

private:
string sender;
string recipient;
string subject;
vector <string> message;

struct tstamp{
int tm_mday;
int tm_wday;
int tm_mon;
int tm_year;
int tm_hour;
int tm_min;
int tm_sec;
};
public:
Message();
Message(string, string, string);
void setSender(string);
void setRecipient(string);
void setSubject(string);
string getSender();
string getRecipient();
string getSubject();
void append(vector <string>);
};


Message::Message(){
sender="?";
recipient="?";
subject="?";
}
Message::Message(string sent, string recip, string sub){
sender=sent;
recipient=recip;
subject=sub;
}
void Message::setSender(string sent){
sent="powerrangersa@gmail.com";
sender=sent;
}
void Message::setRecipient(string recip){
recip="uknowwhoitsfrom@yahoo.com";
recipient=recip;
}
void Message::setSubject(string sub){
sub="Questions on c++";
subject=sub;
}
void Message::append(vector <string>){
messages.push_back("Hello Professor;");
messages.push_back("There's something I want to discuss with you.");
messages.push_back("How should I use vectors?");
messages.push_back("What is tm structure?");
messages.push_back("Is there a way to not use end of file?");

for(int i=0; i<messages.size();i++){
cout<<messages[i]<<" ";
}
cout<<endl;
}
string Message::getSender(){
return sender;
}
string Message::getRecipient(){
return recipient;
}
string Message::getSubject(){
return subject;
}

void printmail(Message &a){

Message note;
string sender1;
string recipient1;
string subject1;
vector <string> messages;

note.setSender(sender1);
note.setRecipient(recipient1);
note.setSubject(subject1);
time_t now=time(0);
char*dt=ctime(&now);
cout<<"Date: "<<dt;
cout<<"To: "<<note.getRecipient()<<endl;
cout<<"Subject: "<<note.getSubject()<<endl;
cout<<"From: "<<note.getSender()<<endl;
note.append(messages);

void printmail(Message&);

int main(){

Message note;
printmail(note);
return 0;
}



Aucun commentaire:

Enregistrer un commentaire