|
No problem. But please try and use the correct forum in future.
|
|
|
|
|
|
What does "mkdir" have to do with C++ managed or otherwise?
You can lead a developer to CodeProject, but you can't make them think.
The Theory of Gravity was invented for the sole purpose of distracting you from investigating the scientific fact that the Earth sucks.
|
|
|
|
|
Hi Guys,
I have to make a single bool array combining four integer arrays as follows. I'm not supposed to do as
connected = new bool [bl1 + bl2 + tr + ct];
because bl1, bl2,tr,ct are pointer to arrays. Can some one give a solution for this??
Here is my code:
class Protocol{
int baseline1[10],baseline2[10];
int catcht[20];
int training[120];
bool *connected;
public:
Protocol(int[10],int[10],int[120],int[20]);
};
<h1>include "protocol.h"</h1>
<h1>include "math.h"</h1>
Protocol::Protocol(int bl1[10], int bl2[10], int tr[120], int ct[20]){
int *baseline1 = bl1;
int *baseline2 = bl2;
int *training = tr;
int *catcht = ct;
connected = new bool [bl1 + bl2 + tr + ct];
}
Thank you!
|
|
|
|
|
You haven't explained what it means to "make a single bool array combining four integer arrays." Therefore, no one can help you yet.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Member 9350237 wrote:
connected = new bool [bl1 + bl2 + tr + ct];
because bl1, bl2,tr,ct are pointer to arrays.
That makes no sense, the value in brackets has to be the requested length of the array. So the new array needs to be long enough to contain the combined number of elements of the other arrays.
You also need to explain how you will convert from int to bool when you copy the elements of the arrays.
|
|
|
|
|
Thanks for responding!.
Sorry about my poor explanation..
I think I conveyed it a wrong way. I'm still in a confusion!
Let me try to explain the scenario..
Ultimately I need to make a bool array of length 10+120+20=150.This will be combinations of zeros and ones..
Out of which first 10 and last 20 positions are filled with '0'.
120 positions are divided into 10 sets of 12 members..
out of 12 positions 10 are ones and two zeros have to be randomly placed into this 12 locations..
for exp: Following are 1st and last set of 12 positions..
{1,1,1,1,0,1,1,1,1,0,1,1,.....1,1,0,1,1,1,0,1,1,1,1,1}
I'm bit stuck implementing this bool array...
As I mentined before
int baseline1[10], int baseline2[20] are 1st 10 and last 20 positions of the bool array which is basically '0', {0}..
int training[120] is to be assigend with zeros and ones in such a way that..
int catcht[20] array of zeros to be combined with array [120] as I mentioned before..
Sorry if my explanation is vague!
|
|
|
|
|
OK, so you know the length of the array, so you just allocate it as normal:
int arraySize = 10+120+20;
bool* boolArray = new bool[arraySize];
memset(boolArray, 0, sizeof(bool) * arraySize);
gives you an array with all elements set to zero. You now just need to add the code to set the various other items as required.
bool* pBool = boolArray + 10; for (int i = 0; i < 10; ++i) {
pBool += 12; }
|
|
|
|
|
Thanks a lot!!,
I'm wondering how to set random zeros and ones to pBool pointer!
you mean
pBool = rand()%2;
Still bit confused!
As I mentioned , for each set I have 12 numbers, out of which 10 numbers 'must' be 1 and 2 0s have to be put randomly into this block of ones, so total of 12: One set should be like this
{1,1,1,1,0,1,1,0,1,1,1,1,...} and in the 2nd set there must be 10 ones and 2 zeros , but position of zero will be different.
will be great if you can help me out on this!
|
|
|
|
|
I would do something like:
bool* pBool = boolArray + 10; srand( (unsigned)time( NULL ) ); for (int i = 0; i < 10; ++i) {
memset(pBool, 1, sizeof(bool) * 12); int rIndex = rand() % 12; pBool[rIndex] = 0; do
{
int rIndex2 = rand() % 12; pBool[rIndex2] = 0; } while (rIndex2 == rIndex);
pBool += 12; }
I have not tested this so you need to try it a few times to make sure it produces the desired results.
|
|
|
|
|
Thanks a lot!!
Now it's working fine
Many thanks again!!
|
|
|
|
|
|
My program is showing "Declaration Terminated incorrectly".Please help........
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<fstream.h>
#include<string.h>
#include<ctype.h>
void stock();
void billing();
class SBILL
{ int slno;
int itemcode;
char name[50];
float quantity;
float price;
float ttlprice;
float taxrate;
float amt;
public:
void subenter()
{ cout<<"\nEnter the following details:"
<<"\n\tItemCode\t:\n\t\t";
cin>>itemcode;
cout<<"\n\tName\t:\n\t\t";
gets(name);
cout<<"\n\tQuantity\t:\n\t\t";
cin>>quantity;
cout<<"\n\tTax rate\t:\n\t\t";
cin>>taxrate;
subcalculate();
}
void subdisplay()
{ cout<<"\n"<<slno<<"\t\t"<<name
<<"\t\t"<<quantity<<"\t\t"
="" <<price<<"\t\t"<<ttlprice
="" <<"\t\t"<<taxrate
="" <<"\t\t"<<amt;
="" }
="" void="" subcalculate()
="" {="" ttlprice="quantity*price;
" amt="((taxrate*ttlprice)/100)+ttlprice;
" int="" getcode()
="" return="" itemcode;
="" }
}sb;
class="" bills
{="" billcode;
="" char="" cusname[50];
="" float="" billamt;
="" public:
="" sbill="" sub;
="" enter()
="" cout<<"\nenter="" the="" following="" details:"
="" <<"\n\tbill="" code\t:\n\t\t";
="" cin="">>itemcode;
cout<<"\n\tCustomer name\t:\n\t\t";
gets(cusname);
void dis1()
{ cout<<"\nBILL CODE\t:"<<billcode
<<"\nname\t:"<<cusname
="" <<"\nslno.\t\t"<<"name\t\t"
="" <<"qty\t\t"<<"price\t\t"
="" <<"ttl\t\t"<<"txrt\t\t"<<"amt";
="" }
="" void="" dis2()
="" {="" cout<<"\n\n\t\tbill="" amount="" :"<<billamt;
="" calculatebamt(int="" x)
="" int="" i;
="" billamt="0;
" for(i="0;i<x;i++)
" getcode()
="" return="" code;
="" }
};
class="" stock
{="" slno;
="" sitemcode;
="" char="" sitemname[50];
="" float="" squantity;
="" sprice;
="" staxrate;
="" public:
="" enter()
="" cout<<"\nenter="" the="" following="" details:"
="" <<"\n\titem="" code\t:\n\t\t";
="" cin="">>sitemcode;
cout<<"\n\tItem Name\t:\n\t\t";
gets(sitemname);
cout<<"\n\tQuantity\t:\n\t\t";
cin>>squantity;
cout<<"\n\tPrice\t:\n\t\t";
cin>>sprice;
cout<<"\n\tTax rate\t:\n\t\t";
cin>>staxrate;
}
void display()
{ cout<<"\n"<<sitemcode<<"\t\t"<<sitemname
<<"\t\t"<<squantity<<"\t\t"
="" <<sprice<<"\t\t"<<staxrate;
="" }
="" void="" dis1()
="" {="" cout<<"\nslno.\t\t"<<"\ncde\t:"
="" <<"name\t\t"<<"qty\t\t"<<"price\t\t"
="" <<"txrt\t\t";
="" int="" getcode()
="" return="" sitemcode;
="" }
};
void="" main()
{="" clrscr();
="" choice;
="" char="" ch[5];
="" do
="" cout<<"\nplease="" enter="" your="" choice"
="" <<"\n\t1="" -="" stock"
="" <<"\n\t2="" billing";
="" cin="">>choice;
switch(choice)
{ case 1:stock();
break;
case 2:billing();
break;
default:cout<<"\nSome error occurred in your choice. Sorry for the inconvenience.\nPLEASE TRY AGAIN!!!";
}
cout<<"\n\nWould you like to continue? (Yes/No)";
cin>>ch;
ch=toupper(ch);
}while(ch=="YES");
getch();
}
void stock()
{ int stockchoice;
char chs[5];
do
{ STOCK ST,STK[30];
cout<<"\nPlease choose your operation"
<<"\n1 - To add stock"
<<"\n2 - To update details of a particular item"
<<"\n3 - To delete details of an existing item"
<<"\n4 - To display details of a particular item"
<<"\n5 - To display the entire bill details";
cin>>stockchoice;
switch(stockchoice)
{ case 1: ofstream fout;
int n,i;
fout.open("STOCK.DAT",ios::app||ios::binary);
cout<<"\nEnter the number of items";
cin>>n;
for(i=0;i<n;i++)
{="" stk[i].enter();
="" fout.write((char*)&stk[i],sizeof(stk[i]));
="" }
="" fout.close();
="" break;
="" case="" 2:="" fstream="" fout;
="" fout.open("stock.dat",ios::app||ios::binary);
="" int="" cde,flag="0;
" cout<<"\nenter="" the="" code="" of="" item="" whose="" details="" you="" want="" to="" update:\n";
="" cin="">>cde;
while(!fout.eof())
{ fout.read((char*)&ST,sizeof(ST));
if(getcode()==cde)
{ ST.enter();
fout.write((char*)&ST,sizeof(ST));
}
else
flag=1;
}
if(flag==1)
cout<<"\nSorry such an item does not exist";
fout.close();
break;
case 3: int cde,flag=0,i=0;
char nm[50];
fstream fin;
ofstream fout;
fin.open("STOCK.DAT",ios::in||ios::binary);
fout.open("TEMP.DAT",ios::out||ios::binary);
cout<<"\nEnter the name of the item you want to delete\n";
cin>>nm;
while(!fin.eof())
{ fin.read((*char)&ST,sizeof(ST));
if(ST.getname()==nm)
{ ST.dis1();
ST.slno=1;
ST.display();
fin.write((char*)&ST,sizeof(ST));
}
else
{ flag=1;
fout.write((char*)&ST,sizeof(ST));
}
}
if(flag==1)
cout<<"\nSorry the record was not found.";
fin.close();
fout.close();
remove("STOCK.DAT");
rename("TEMP.DAT","STOCK.DAT");
break;
case 4: int i=0;
char nm[50];
ifstream fin;
fin.open("STOCK.DAT",ios::in||ios::binary);
cout<<"\nEnter the item name you want to display\n";
cin>>nm;
while(!fin.eof())
{ fin.read((char*)&ST,sizeof(ST));
if(ST.getname()==nm)
{ ST.dis1();
ST.slno=1;
ST.display();
}
else
flag=1;
}
if(flag==1)
cout<<"\nSorry such an item does not exist.";
fin.close();
break;
case 5: ifstream fin;
fin.open("STOCK.DAT",ios::in||ios::binary);
fin.read((char*)&ST,sizeof(ST));
STK[0].slno=1;
ST.dis();
while(!fin.eof())
{ fin.read((char*)&ST,sizeof(ST));
ST.display();
ST.slno=ST.slno+1;
}
fin.close();
break;
default: cout<<"\nSome error occurred in your choice. Sorry for the inconvenience.\nPLEASE TRY AGAIN!!!";
}
cout<<"\nWould you like to continue? (Yes/No)";
cin>>chs;
}while(chs=="YES");
}
void billing()
{ int billchoice;
char chb[5];
do
{ BILLS BI;
BI.SUBBILL SUB,SB[10];
cout<<"\nPlease choose your operation"
<<"\n1 - To bill"
<<"\n2 - To search for an existing bill"
<<"\n3 - To display a bill"
<<"\n4 - To display the entire bill details";
cin>>billchoice;
switch(billchoice)
{ case 1: ofstream fout;
fout.open("BILL.DAT",ios::app||ios::binary);
int n;
cout<<"\nEnter the number of items";
cin>>n;
for(int i=0;i<n;i++)
{="" bi.sb[i].subenter();
="" bi.calculatebamt(n);
="" fout.write((char*)&bi,sizeof(bi));
="" }
="" fout.close();
="" break;
="" case="" 2:="" int="" cde,flag="0,i=0;
" ifstream="" fin;
="" fin.open("bill.dat",ios::in||ios::binary);
="" cout<<"\nenter="" the="" bill="" code="" you="" want="" to="" search\n";
="" cin="">>cde;
while(!fin.eof())
{ fin.read((char*)&BI,sizeof(BI));
if(BI.SUB.getcode()==cde)
{ BI.dis();
BI.SB[0].slno=1;
BI.SB[i].subdisplay();
}
else
flag=1;
}
if(flag==1)
cout<<"\nSorry the record was not found.";
fin.close();
break;
case 3: int cde;
ifstream fin;
fin.open("BILL.DAT",ios::in||ios::binary);
cout<<"\nEnter the bill code you want to display\n";
cin>>cde;
while(!fin.eof())
{ fin.read((char*)&BI,sizeof(BI));
if(BI.SB.getcode()==cde)
{ BI.SB.dis();
BI.SUB[0].slno=1;
BI.SB.subdisplay();
}
else
flag=1;
}
if(flag==1)
cout<<"\nSorry such a bill does not exist.";
fin.close();
break;
case 4: int cde,i=0;
ifstream fin;
fin.open("BILL.DAT",ios::in||ios::binary);
fin.read((char*)&BI,sizeof(BI));
BI.SB[0].slno=0;
BI.dis();
while(!fin.eof())
{ fin.read((char*)&BI,sizeof(BI));
BI.SB.display();
BI.SB.slno=SB.slno+1;
}
fin.close();
break;
default:cout<<"\nSome error occurred in your choice. Sorry for the inconvenience.\nPLEASE TRY AGAIN!!!";
}
cout<<"\nWould you like to add another bill? (Yes/No)";
cin>>chb;
chb=toupper(chb);
} while(chb=="YES");
}
|
|
|
|
|
Did you really think that it's necessary to dump your entire unformatted code base here and expect us to guess where you are getting this error message?
[Edit]
You have several problems going on here. You have many for statements that are simply
for (i = 0; i>cde; a couple of which appear to have no purpose.
Your nested class declaration is incomplete.
Your include statements are missing.
You are declaring functions inside other functions.
This has nothing to do with C++/CLI
probably others.
[/Edit]
You can lead a developer to CodeProject, but you can't make them think.
The Theory of Gravity was invented for the sole purpose of distracting you from investigating the scientific fact that the Earth sucks.
modified 27-Jul-15 16:45pm.
|
|
|
|
|
Well, thanks for bringing it to my notice.Actually when I copied it into the editor on the website, it looked fine, but after submission edges of the statements were cropped off so was the formatting
like the one u mentioned.I am not able to submit the complete statements.
|
|
|
|
|
You forgot the closing brace after function BILLS::enter() . If you formatted your code properly you would be able to spot such errors quite easily.
|
|
|
|
|
c++ code only
gym be performed by the system:
• Register members (data recorded for each member consists of membership ID, first name, surname, address, contact number and age)
• Update member details
• View member details
• Search for a member using membership ID as the key
|
|
|
|
|
|
We still don't provide code to order. You will have to either develop it yourself or resort to another site where you can hire developers. If you decide to develop it yourself and you encounter a specific problem, we'll probably be able to help. You've been told this before - please stop posting instructions.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Did you ever ask your professor? This stinks to the high heavens as homework....
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak
|
|
|
|
|
CREATE ONSCREEN HELP TO ASSIST THE USERS OF A COMPUTER PROGRAM.
|
|
|
|
|
Message Closed
modified 22-Jul-15 4:01am.
|
|
|
|
|
Despite the recent lounge discussion, I was tempted to flag your message. You may wish to reword or remove it.
|
|
|
|
|
It was a bit overboard, thanks for the gentle suggestion before hitting the nuke button.
Geek code v 3.12 {
GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- r++>+++ y+++*
Weapons extension: ma- k++ F+2 X
}
If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver
|
|
|
|
|
DON'T SHOUT!
Typing everything in upper-case on the Internet is considered extremely rude.
This is now the second time you've posted exactly the same instruction - presumably from your homework assignment - in this forum. Whilst the unpaid volunteers who answer questions here will be happy to help if you encounter a specific problem with code you've written, nobody here is going to write your code for you.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|