//this is class definition
class Some
{
public:
//this is methods declaration
void set();
void get();
//end of method declaration
};
//end of class definition
//this is methods definition
void Some::set()
{
std::cout << "Hi" << std::endl;
}
void Some::get()
{
std::cout << "I will get you!" << std::endl;
}
//end of method definition
thanks Shinigami. that helps a lot. but what if you're not just trying to output text? for instance, how would you initialize an array in the definition?
.h file:
#include <string>
usingnamespace std;
#ifndef bstore_H
#define bstore_H
class bstore
{
public:
bstore();
bstore(string);
string title();
string author();
string price();
private:
string name;
string money;
};
#endif
first cpp file:
#include "hw.h"
#include <string>
#include <iostream>
usingnamespace std;
bstore::bstore(){
}
string bstore::title()
{
cout<<"Title of book: "<<endl;
cin>> name;
return name;
}
string bstore::author()
{
cout<<"Name of Author: "<<endl;
cin>> name;
return name;
}
string bstore::price()
{
cout<<"Cost of Book: "<<endl;
cin>> money;
return money;
}
main code:
#include "hw.h"
#include <string>
#include <iostream>
usingnamespace std;
string bookinfo[8][3];
string k;
int l;
string changes;
int main()
{
bstore basicinfo;
string basicinfotitle;
string basicinfoauthor;
string basicinfoprice;
int j;
for(j=0;j<7;j++){
cout<<"book number "<<j<<endl;
basicinfotitle=basicinfo.title();
basicinfoauthor=basicinfo.author();
basicinfoprice=basicinfo.price();
bookinfo[j][0]=basicinfotitle;
bookinfo[j][1]=basicinfoauthor;
bookinfo[j][2]=basicinfoprice;
}
string yesno;
while(yesno!="q"){
cout<<"Type display to display a table of books. Type edit to edit a value."<<endl;
cout<<"Enter q to quit at any time"<<endl;
cin>>yesno;
if(yesno=="display"){
cout<<"book number"<<"\ttitle"<<"\tauthor"<<"\tprice"<<endl;
cout<<" "<<endl;
for(j=0;j<7;j++){
cout<<j<<"\t\t"<<bookinfo[j][0]<<"\t"<<bookinfo[j][1]<<"\t"<<bookinfo[j][2]<<endl;
}
}
if(yesno=="edit"){
cout<<"Which book would you like to edit?" <<endl;
cin>>j;
cout<<"Which part would you like to edit?(Enter T,A or M)"<<endl;
cin>>k;
if(k=="T"){
l=0;
}
elseif(k=="A"){
l=1;
}
elseif(k=="P"){
l=2;
}
cout<<"Make changes: "<<endl;
cin>> basicinfotitle;
bookinfo[j][l]=basicinfotitle;
cout<<bookinfo[j][l];
}
}
}
(Sorry, I put all three documents into the same code block above but you should be able to figure it out . one is a .h one is first .cpp file and the last main code )