TALK @ PhilMusic.com - The Online Home of the Pinoy Musician
Tech Forums => ph.Cyberview => Topic started by: geetar_geek79 on May 14, 2006, 11:14:20 AM
-
I need help with some of my C++ school projects (6 left in all). I'm totally lost with all of them. I was able to do the first few of them but the later ones are pretty hard for me to grasp.
Here's the link of the assignments:
http://www.glendale.edu/knighton/C_C++_Programming/Assignments_C.html
Anybody? Please help!...
-
Are you left with the last 6 ones or you're only required to answer the first 6 ones?
-
I'm left with the last six.... thanks!
sample codes, plz!
-
matutulungan sana kta eh kaso tagal na ko d nag C++.. pag may extra time review ko and try ko gawin yan hehehe puro PHP na kc ako ngayon at ASP e
-
matutulungan sana kta eh kaso tagal na ko d nag C++.. pag may extra time review ko and try ko gawin yan hehehe puro PHP na kc ako ngayon at ASP e
slamat bosing! ang hirap talaga eh, lalo na yung Classes at Structures. Stuck din ako sa Arrays saka passing arguments. Modular kasi lahat...
-
Ang gulo nung 5. Scanning characters from keyboard tas hindi dapat scanf or any other STDIO functions? pano yun? Assembly call?
-
nde... gagawa ka ng sariling function na mayroong array. doon mo ii-store yung bawat letter na input sa keyboard tapos terminate mo ng null string. ayaw kasi ng proff namin gamitin namin yung built-in function ng C++. Gusto raw nya kami matuto gumawa ng sariling functions saka mag-manipulate ng Arrays... hirap nga, eh. Napaka-tnga ko pa naman sa Arrays...
Slamat boss.
-
hehe demm i shouldve taken C++... kung VB/VBA lang sana yan id be glad to help...
good luck bro!
-
nde... gagawa ka ng sariling function na mayroong array. doon mo ii-store yung bawat letter na input sa keyboard tapos terminate mo ng null string. ayaw kasi ng proff namin gamitin namin yung built-in function ng C++. Gusto raw nya kami matuto gumawa ng sariling functions saka mag-manipulate ng Arrays... hirap nga, eh. Napaka-tnga ko pa naman sa Arrays...
Slamat boss.
ahh simple lang yan. Try mo tong code na to.
short get_str(char[] strPrompt, char[] strFilename, long MAX)
{
short i,n;
char[] strArray;
printf("%s",strPrompt);//print prompt
scanf("%s",&strArray);//okaya gets(strArray);
for(n=0;strArray[n]!='\0';n++);//count string input length
if(strlen(strArray)<MAX)//check if input exceeds maximum no. of strings
{
for(i=0;i<n;i++)
strFilename=strArray;//copies the contents char per char
strFilename='\0';//null pointer for string.
return i;//return the length of string
}
else
return -1;//return something to denote exceeding of value
}
-
ahh simple lang yan. Try mo tong code na to.
short get_str(char[] strPrompt, char[] strFilename, long MAX)
{
short i,n;
char[] strArray;
printf("%s",strPrompt);//print prompt
scanf("%s",&strArray);//okaya gets(strArray);
^^look out for this one. you have not allocated any space for strArray, this will lead to a very confusing debugging struggle, use fgets :D. Never use gets :D
WOA, do not use str*, that is reserverd for system use and will confuse the compiler :) kindly review standard naming conventions and rules :)
for(n=0;strArray[n]!='\0';n++);//count string input length
if(strlen(strArray)<MAX)//check if input exceeds maximum no. of strings
{
for(i=0;i<n;i++)
strFilename=strArray;//copies the contents char per char <-- strFilename must be big enough to hold strArray :)
strFilename='\0';//null pointer for string. <-- you might overwrite the last character you copied on to the string :) i++ :D
return i;//return the length of string
}
else
return -1;//return something to denote exceeding of value
-
Salamat po boss, I'll try the code...
-
btw, what compiler and environment are you using?
-
ahh simple lang yan. Try mo tong code na to.
short get_str(char[] strPrompt, char[] strFilename, long MAX)
{
short i,n;
char[] strArray;
printf("%s",strPrompt);//print prompt
scanf("%s",&strArray);//okaya gets(strArray);
^^look out for this one. you have not allocated any space for strArray, this will lead to a very confusing debugging struggle, use fgets :D. Never use gets :D
IIRC, fgets is for file get string; not something that you would take from the console keyboard input stream (in a standard sense) and IIRC C++ automatically allocates memory for Arrays (And I don't see why you need unallocated arrays). Yung sinasabi mo, pointers.
WOA, do not use str*, that is reserverd for system use and will confuse the compiler :) kindly review standard naming conventions and rules :)
Dude, we(programmers) all know that naming convention does not affect anything about the system AND is only used to help ease the reading of the program. str btw is reserved for structured datatypes in C not for system use. You do the reviewing.
for(n=0;strArray[n]!='\0';n++);//count string input length
if(n<MAX)//check if input exceeds maximum no. of strings
{
for(i=0;i<n;i++)
strFilename=strArray;
//copies the contents char per char <-- strFilename must be big enough to hold strArray :)
There's a predefined MAX, look for the bolded part
strFilename='\0';//null pointer for string. <-- you might overwrite the last character you copied on to the string :) i++ :D
not sure about this part. Just put an i++ before putting the null at the end of the string if it overwrites the last char
return i;//return the length of string
}
else
return -1;//return something to denote exceeding of value
}[/b]
-
^SALAMAT!!! I'll try the codes...
-
WOA, do not use str*, that is reserverd for system use and will confuse the compiler :) kindly review standard naming conventions and rules :)
Dude, we(programmers) all know that naming convention does not affect anything about the system AND is only used to help ease the reading of the program. str btw is reserved for structured datatypes in C not for system use. You do the reviewing.
Oops my bad, reserved identifiers rules only affect function names and global variables and not local variables :)
-
btw, what compiler and environment are you using?
Dev C++
http://www.bloodshed.net/devcpp.html
Thanks...
-
Here's for the 6. Not really sure bout this one.
void assignment_6()
{
FILE *pFile;
int i,nLength;
char[] sFilename,sMode,sInput;
char cData;
get_str("Enter File Name:",sFilename,MAX);//Gets filename
get_str("Enter Mode (R/W)",sMode,MAX);//Gets mode
if(strcmp(sMode,"R")==0||strcmp(sMode,"r")==0)//if sMode gets R or r
{
if((pFile=fopen(sFilename, "rt"))!=NULL)//opens file for Reading and checks if it exists
{
do{
cData=fgetc(pFile);//gets the character from the file
printf("%c",cData);//prints cData
}while(cData!=EOF);//while it's not yet the end of the file
fclose(pFile);
/*the reason why I chose fgetc over fgets is because of the bug that fgets has with the EOF. I'm not sure if they already fixed the bug though*/
}
else //if it doesn't exists or something is wrong witht he file
puts("Error Opening File");
}
else if(strcmp(sMode,"W")==0||strcmp(sMode,"w")==0)//if sMode gets W or w
{
if((pFile=fopen(sFilename, "wt"))!=NULL)//Opens the filename for writing
{
do{
nLength=get_str("",sInput,MAX);//gets input from keyboard
for(i=0;i<nLength;i++)//loops the whole string char per char
fputc(pFile,sInput);//enters the whole string char per char except the '\0'
fputc(pFile,'\n');//inserts a line break
}while(strcmp(sInput,EOF)!=0);//loop to detect if the input from keyboard is an EOF
fclose(pFile);//closes the file
}
else//if file is in use
puts("Error Opening File");
}
else//if keyboard input is wrong
puts("Wrong input. Must be R or W only");
}
-
Wow... ang lulupet tlga ng mg noypits sa programming (except me!)
SALAMAT!!!