home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 1723
Discussions: 188,402, Posts: 2,243,609, Members: 232,632
Old May 12th, 2005, 05:22 AM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Mar 2005
Posts: 8
i am stuck in my c++ assignment, pls help

i have an assignment and i am not good enough about c++. I wrote below directly question:

Compress data:
to compress/encode data, you should recognise repeatead digits and replace the runs of repetition with a number representingthe repetition lenght.( data have to be biniary data(0/1))

ex. 000011100111 can be written as 4323 coz there are 4 zeros, 3 ones, 2 zeros, 3 ones.

I tried to write code as like this but compress section doesn't work and i have no idea how can i write it!!! ( in addition i am just begginer prgmer so coding should be understandable by me )

int value[size+1];
int z=0;
cout << "Enter a list of "<< size <<" digits binary data and press"
<<" the ENTER key after each entry."<< endl<<endl;


for (int i=0; i<size; i++)
{
cout<<"Enter "<< i+1 <<". binary data"<<endl;
cin>>value[i];

while (!((value[i]==0)||(value[i]==1)))
{
cout<<"ERROR: It is not a binary data" << end l<<"Please ENTER a new binary data"<<endl;
cin>>value[i];
}

}

//compress data
for(int x=0; x<size; x++)

if (value[x]!=value[x+1])
cout<<(x+1);

thnx for everything

Tayfun is offline   Reply With Quote
Old May 12th, 2005, 12:49 PM     #2 (permalink)
Ultimate Member
 
Rootstonian's Avatar
 
Join Date: Mar 2005
Location: Out of my mind
Posts: 2,792
Send a message via AIM to Rootstonian
You have been given an assignment, so I'm assuming that it is for some type of class or training. You are a beginning programmer; quite understandable. This is not a hard assignment.

Use whatever reference you have and try to work on this. Try coding it without the error check. (HINTS: display your input data from the array...make sure it coming in right. This probably should be character data instead of int)

Draw it on paper...go through it like you would without a program. Try to translate this to C code. This is more a logic problem vs. a technical program challenge. You can do it

Rootstonian is offline   Reply With Quote
Old May 14th, 2005, 06:13 PM     #3 (permalink)
Member
 
Join Date: Feb 2004
Posts: 59
I agree. This assignment isn't too difficult. Looks like you should probably look for a counter variable in your reference books. I don't want to give too much away, but I hope that brings up something that you've heard in class.

Ignore the code for a moment, and take out a piece of paper. Write down the steps you would do, as a person, to figure out this thing. They can be as obvious as you want. If you need more help, just post again, and maybe I'll drop another hint. Or post what your written version looks like, and I'll try to help you with your logic if necessary.

crobat is offline   Reply With Quote
Old May 14th, 2005, 06:47 PM     #4 (permalink)
Ultimate Member
 
elmers's Avatar
 
Join Date: Sep 2003
Location: Philadelphia
Posts: 1,462
^^^^ Really the only way to learn is by actually doing something yourself, and the assignment isnt that hard.

The basic algorithm is as follows:

Count the number of same consecutive digits. When a different digit comes in write the count to an output.

Repeat until EOL.

And if noone else welcomed you to TIMO the let me be the first to say


WELCOME
__________________
Buy the ticket, take the ride.
- Hunter S. Thompson
elmers is offline   Reply With Quote
Old May 15th, 2005, 05:17 AM     #5 (permalink)
Junior Member
 
Join Date: Mar 2005
Posts: 8
program's problem

Thank u for your kindly caring about that. After studying more on the prg. , i achieved it ( actually, think so)

At the moment i tried to write the codes as follows but there is some problems which are not being solved and also i couldn't find out where is that...Program is not working after runing normally working in the first case which is in the "main" but after entering input it is not switch to case2 which is "compress"... if u can find out please inform me.....

My program is as belows:

#include <iostream>
#include <string>
using namespace std;


//Define array size
const int maxsize=5;
int size=5;
char value[maxsize]="\0"; //Array Definition
int selection;


//Function prototype
void menuselection(char selection);
void getvalue(char value[maxsize]);
void compress(char value[maxsize]);
void display(char value[maxsize]);
//void decompress(char value[maxsize]);



//Menu Selection
void menuselection(char selection)
{
cout<<"COMPRESSING AND DECOMPRESSING DATA APPLICATION"<<endl
<<"Select from the menu below:"<<endl<<endl
<<"1 - Read data"<<endl
<<"2 - Compress"<<endl
<<"3 - Decompress"<<endl
<<"0 - Exit"<<endl;

cout<<endl<<"Please enter your selection ==> ";
cin>>selection;

}



//Reading Data
void getvalue (char value[maxsize])
{

cout << "Enter a list of "<< size <<" digits binary data and press"
<<" the ENTER key after each entry."<< endl<<endl;


for (int i=0; i<size; i++) //entering data
{
cout<<"Enter "<< i+1 <<". binary data : ";
cin>>value[i];

while (!((value[i]=='0')||(value[i]=='1'))) //checking data
{
cout<<endl<<"ERROR: It is not a binary data"<<" Please ENTER a new binary data"<<endl<<endl
<<"Enter "<< i+1 <<". binary data : ";
cin>>value[i];
}

}
cout<<selection<<endl;
}


//Copmressing value (something wrong in here!!!!)
void compress (char value[maxsize])
{
getvalue(value);

int count=1,
j=1;
char output[14]="\0";


for (int w=0; w<size; w++)
{
if (value[w]=value[w+1])
{
count=+1;
output[j]=count;
j++;
}

else
{
count=1;
count=+1;
output[j]=count;
j++;
}
}

// count++;
/*else
{
output[j]=countchar;
j++;
}*/


cout<<endl<<"The compressed data is ==> ";
for (int k=0; k<14;k++)
cout<<output[k];
}


//Decompressing data
void decompress()
{

char decompressinput[30];
int k=0,i=0,DecompressOut[100];

cout<<"Input for Decompression : ";
cin.getline(decompressinput,30);
//cout<<endl<<endl<<decompressinput;


for(int a=0;a<30;(a+2))
{
if(decompressinput[a]!='\0')
{

for(int j=decompressinput[a];j>0;j--)
{

DecompressOut[k]=0;
k++;
}

for(j=decompressinput[a+1];j>0;j--)
{

DecompressOut[k]=1;
k++;
}
}
else
{

cout<<"The Output is : ";
for (int z=0;z<30;z++)
{

cout<<DecompressOut[z];
}

break;
}

}

}




//main function(menu function doesnt work!!!!!)
int main()
{

menuselection(selection);
cout<<selection<<endl;
//int selection=1;
while(selection!='0')
{

switch(selection)
{

case 1: getvalue(value);
break;

case 2: compress(value);
break;

case 3: decompress();
break;

case 0: return 0;
break ;

default: cout<<endl<<"Unknown Menu Selection";
}
}

}

Last edited by Tayfun : May 15th, 2005 at 05:25 AM.
Tayfun is offline   Reply With Quote
Old May 15th, 2005, 09:13 AM     #6 (permalink)
Ultimate Member
 
Rootstonian's Avatar
 
Join Date: Mar 2005
Location: Out of my mind
Posts: 2,792
Send a message via AIM to Rootstonian
Yeah, ok All I can say right now is "wow" LOL

Did the assignment include doing a menu?

How is decompress supposed to work? (from the assignment, not "your" translation). Say I enter "4331". How do you know what to output??? Is that 4 "ones" or 4 "zeroes" etc, etc. The only way a decompress could work was for the user to enter a string of ones and zeroes. Then you would have to store that in a two-dimensional array for later decompression (or a linked list or a b-tree or....). I don't think you're quite ready for that.

This program, assuming you don't need a menu and a decompress function, should be about 20 - 30 lines of code (give or take). It's a basic if/else structure (with some thought)!

Good Luck.
Rootstonian is offline   Reply With Quote
Old May 15th, 2005, 09:34 AM     #7 (permalink)
Junior Member
 
Join Date: Mar 2005
Posts: 8
urgently usefull advice, last a few days to go

Hi everybody,

firstly,The menu of prg. is necessary for the assigment. And swiching between "read", "compress", and "decompress" will be with that menu. On the other hand "decompress" works that for decimal data ex. 2344 means 0011100001111 , something like that. so prg will understand 2 means 2 zeros 3 means 3 ones. so decompress will start to output just 1 or 0.

Meanwhile, i need urgently help with coding or recorrection of my codes. Coz my codes should be correct but if u run the codes in c++ u can find out where is the prb. I am still on that work but unsurprisingly i haven't in my hand.

So if u can me give more usefull advice such as additional codes or correstion will be gratefull for me...

Thnx everybody,

ambitious programmer
Tayfun is offline   Reply With Quote
Old May 15th, 2005, 10:29 AM     #8 (permalink)
Ultimate Member
 
Rootstonian's Avatar
 
Join Date: Mar 2005
Location: Out of my mind
Posts: 2,792
Send a message via AIM to Rootstonian
There must be more to the decompress than you're telling us..."2344" uncompresses to 001100001111? What about 001111110000? Is there some magic I'm missing that says the first "4" are all zeroes and the second "4" is all ones?

No one here will write code for you. You don't learn that way. However, we can and do make suggestions.

My suggestions:

1.) Keep a copy of your current code THEN START A NEW PROGRAM!

2.) Do a basic program that displays the menu and loops waiting for user input or an exit code. Display "You entered choice 1" when the user presses 1 etc., etc.

3.) Now, add your functions. DO NOT put any code into the functions at this point. Make sure your menu program calls the right function. Verify it.

For Example:

void Compress() {

cout << "Compress Function Entered" << endl;

}

4. At this point, you have what I call a "skeleton" program. You have a menu; it calls the right functions.

Now is the time to ANALYZE, DESIGN and IMPLEMENT your code/logic (your algorithm(s)). Don't just start hammering away at the keys. Write it out on paper in English...or draw a flow chart or say it in your head "If the first number is a 1 AND the second number is a 1 do something, ELSE do anotherthing (hint, cuz the SECOND NUMBER IS NOT A 1 )
Rootstonian is offline   Reply With Quote
Old May 17th, 2005, 12:00 AM     #9 (permalink)
Member
 
Join Date: Feb 2004
Posts: 59
I know this is a basic step, but the first step in writing successful code is understand clearly what you are supposed to do.

If you cannot tell us clearly what you are supposed to do, and we don't have any questions about it, then there is something you must be missing in the problem. Reread the assignment, and jot down anything relevant to the problem. Key facts, what is inputted, what is outputted, and so forth should be known before you can continue.
crobat is offline   Reply With Quote
Old May 17th, 2005, 12:27 AM     #10 (permalink)
SoMuchAnime-SoLittleTime
 
EXreaction's Avatar
 
Join Date: Aug 2003
Location: Plymouth, WI
Posts: 13,871
Blog Entries: 1
Send a message via ICQ to EXreaction Send a message via AIM to EXreaction Send a message via MSN to EXreaction Send a message via Yahoo to EXreaction
Wow, way different from Visual basic, reminds me more of the code I used in Flash MX.
Sry but I can't help you with c++, although i should try something like that with vb.
__________________
My photography: Flickr

Lithium Studios - phpBB3, PHP, and Web Development
EXreaction is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Assembler and C Programming Assignment ruthless Certification and Education 1 May 1st, 2004 07:27 PM
I need some help with my assignment about networking camaro General Tech Discussion 2 November 12th, 2003 02:02 AM
beginner with c++ and need help with an assignment Martster Webmastering and Programming 3 September 18th, 2002 09:02 AM
Pin Assignment Analog Out Etruscan Multimedia and Audio 3 July 26th, 2002 04:36 AM
Stuck in Unix! Pls help NeoStarO1 Applications and Operating Systems 6 January 13th, 2002 01:53 AM

Most Active Discussions
Is It Just Me? (2906)
3-days in and no threads about Gaza (161)
Misery Loves Company... (2144)
New Build ( Finally ) (7)
CPU wont boot (7)
Building a gaming computer advice (5)
I think I just killed my computer w.. (24)
RCA 52Inch HDTV wont turn on (5)
Folderchat Weekday thread (444)
Recent Discussions
Futronix has water features? (0)
Laptop proccesor to desktop mob.. (2)
Please help! multiple problems! (4)
RCA 52Inch HDTV wont turn on (5)
New Build ( Finally ) (7)
Common Spyware Solutions (97)
How do you move a hard-drive to.. (4)
What is the best external enclo.. (0)
Partition Magic 7.0 (Unallocate.. (17)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 04:41 AM.
TechIMO Copyright 2008 All Enthusiast, Inc.



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