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
|
//make a file for input
void make_input(ifstream &fin,string &filename)
{
cout<<"Input File: ";
getline(cin,filename);
//Open the file
fin.open(filename);
//if file doesnt open
if(!fin)
cout<<"\nFile not open";
}
void make_output(ofstream &fout,string &filename2)
{
cout<<"\n\tOutput File Name: ";
getline(cin,filename2);
//Open the output file
fout.open(filename2);
}
//input cow in file
void Put_cow(string &findcow, ifstream &in)
{
getline(in,findcow);
}
void Read_File(string cow, int size, int &counter)
{
int rightcow=0;
counter=0;
for (int i=1;i<=size;i++)
{
if (cow[i-1]==')' && cow[i]==')')
{
counter=counter+rightcow;
}
else if (cow[i-1]=='(' && cow[i]=='(')
rightcow=1;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
cout<<"Hello";
cout.flush();
//Declare variables for ifstream and ofstream
ifstream in;
ofstream out;
string name_Input_File;
string name_Output_File;
string find_cow;
int length;
//Call the function to open input file
make_input(in,name_Input_File);
//Call funtion to open output file
make_output(out,name_Output_File);
//read the file while file is open
Put_cow(find_cow,in);
//Find the length of string
length=find_cow.length();
//Total posilbity of cow
int total_Cow;
Read_File(find_cow,length,total_Cow);
cout<<"\n\n\t" <<total_Cow;
|