Sunday, August 2, 2009

Java and C++ code for this UML diagram?

could someone tell me what the simple class implementation code would be for both java and c++ with this UML diagram?





LibraryPatron Class





protected int PatronNumber


protected String Name


protected String Major


private String Status





LibraryPatron()


void Modify(LibraryPatron ThisPatron)


void InputData(int x)


void PrintMe()


int GetPatronNumber()

Java and C++ code for this UML diagram?
I don't know Java, so I'll just give the C++ half:





// The declaration:





#include %26lt;string%26gt;


class LibraryPatron


{


public:





LibraryPatron();


virtual ~LibraryPatron();





void Modify(const LibraryPatron %26amp; ThisPatron);


void InputData(int x);


void PrintMe() const;


int GetPatronNumber() const;





protected:





int PatronNumber;


std::string Name; // i use STL for all me strings, matey!


std::string Major;





private:





std::string Status;


};








// The implementation:


#include "LibraryPatron.h"


#include %26lt;stdio.h%26gt;





LibraryPatron


::LibraryPatron()


: PatronNumber(0)


{


}


LibraryPatron


::~LibraryPatron()


{


}





void


LibraryPatron


::Modify(const LibraryPatron %26amp; ThisPatron)


{


if( %26amp;ThisPatron == this ) return;


PatronNumber = ThisPatron.PatronNumber;


Name = ThisPatron.Name;


Major = ThisPatron.Major;


Status = ThisPatron.Status;


}





void


LibraryPatron


::InputData(int x)


{


// I have no clue what to do with "x", sorry....


}





void


LibraryPatron


::PrintMe() const


{


printf("PatronNumber = %d\n", PatronNumber);


printf("Name = %s\n", Name.c_str());


printf("Major = %s\n", Major.c_str());


printf("Status = %s\n", Status.c_str());


}





int


LibraryPatron


::GetPatronNumber() const


{


return PatronNumber;


}








As I said, I don't know java :(


Can someone please check this code for me it is in C programing due today so please hurry?

#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;


#include %26lt;time.h%26gt;


#include %26lt;conio.h%26gt;


#include %26lt;ctype.h%26gt;





int main (void)


{


//creating random balance for user


srand(time(NULL));


int ranBal;


ranBal = rand();





printf("\t\t Virtual Bank at Osceola\n");


printf("\t\t\t WELCOME\n\n");





char num1, num2, num3, num4;


printf("Please enter you 4 digit pin number: \n");


scanf("%c%c%c%c", %26amp;num1, %26amp;num2, %26amp;num3, %26amp;num4);





//Pin number code


for (int count = 0; count %26lt; 4; count++)


{


if (count == 3)


{


printf("Sorry You can't continue, contact your bank for assistance");


}


if ((isdigit(num1)) %26amp;%26amp; (isdigit(num2)) %26amp;%26amp; (isdigit(num3)) %26amp;%26amp;(isdigit(num4)))


{


printf("Valid Pin");


break;


}//end if


else


{


printf("Invalid Pin");


printf("Please try to enter your pin again");


scanf("%c%c%c%c", %26amp;num1, %26amp;num2, %26amp;num3, %26amp;num4);


}//end else





}//end for





int receipt;


printf("For Receipt enter 1, For no receipt enter 2\n");


scanf("%d", %26amp;receipt);


if (receipt == 1)


printf("Please take your receipt\n");


else if (receipt == 2)


printf("No receipt will be printed\n\n");


else


printf("Invalid Entry\n");








//clear screen


//clrscr();





int again = 1;


int option;





while (again == 1)


{


printf("Please choose one of the following numbers\n\n");


printf("1: Get Card Back 2: Fast Cash 3: Withdraw 4: Deposit 5: Balance\n\n");


scanf("%d", %26amp;option);





int fastCash;





if (option == 1)


{


printf("Goodbye!\n\n");


}//end option 1


printf("Press 1: Another Transaction or Press 2: Get Card Back");


scanf("%d", %26amp;again);


else if (option == 2)


{


printf("1: $20.00 2: $40.00 3: $80.00 4: $100.00\n\n");


scanf("%d", %26amp;fastCash);


if (fastCash == 1)


{


printf("You have withdrawn $20.00\n");


}


if (fastCash == 2)


{


printf("You have withdrawn $40.00\n");


}


if (fastCash == 3)


{


printf("You have withdrawn $80.00\n");


}


if (fastCash == 4)


{


printf("You have withdrawn $100.00\n");


}





printf("Press 1: Another Transaction or Press 2: Get Card Back");


scanf("%d", %26amp;again);


}//end option 2


else if (option == 3)


{


int withdrawl;


printf("Please enter withdrawl amount\n");


scanf("%d", withdrawl);


ranBal = ranBal - withdrawl;


if (ranBal %26lt; 0)


printf("");


//compare to actual balance which must be a randomized number


printf("Press 1: Another Transaction or Press 2: Get Card Back");


scanf("%d", %26amp;again);


}//end option 3


else if (option == 4)


{


printf("Please enter deposit amount\n");


printf("Press 1: Another Transaction or Press 2: Get Card Back");


scanf("%d", %26amp;again);


}//end option 4


else if (option == 5)


{


printf("Your balance is %d.\n", ranBal);


printf("Press 1: Another Transaction or Press 2: Get Card Back");


scanf("%d", %26amp;again);


//just print off randomized balance number


}//end option 5


else


{


printf("Invalid Entry\n");


printf("Press 1: Another Transaction or Press 2: Get Card Back");


scanf("%d", %26amp;again);


}





}





if (again == 2)


printf("Goodbye!");





if ((again != 1) %26amp;%26amp; (again != 2))


printf("Invalid Entry");





system("pause");


return (0);


}//end main

Can someone please check this code for me it is in C programing due today so please hurry?
I stopped reading after this line:





char num1, num2, num3, num4;


printf("Please enter you 4 digit pin number: \n");


scanf("%c%c%c%c", %26amp;num1, %26amp;num2, %26amp;num3, %26amp;num4);





which is so hopelessly messed up, I had to laugh for a few hours.





Anyway, there is no way to judge this program since you just threw code at us and not what it is supposed to do. So yeah, this code looks perfect, just like any other code someone might post.
Reply:That program is screwed up in more ways than a dozen. Good luck. You need to talk to your professor and tell her or him to help you. Your professor has obviously not communicating with you on how to write a program.





RJ
Reply:This must be for a university course.





It's hard to read because it's all crammed over to the left.


Review the use of indention, and ANSI standards.





Also, you have everything in the main function which also makes it hard to read, too much in one function.
Reply:Couple of things -





for (int count = 0; count %26lt; 4; count++) - what exactly is this for loop for? You should probably be using a switch statement.
Reply:Can you try with system("CLS") ; instead of clescr();

aster

C++ Problem, please help...?

I wrote this program, first I should say I'm an amature and I'm learning C++.


When I run this program if the input is a letter it returns you havent passed, but if the input is a number then the program halts and got hangged. whats the prob whit this program?


Im using DEV-C++ compiler








#include %26lt;stdio.h%26gt;


#include %26lt;windows.h%26gt;


int main()


{


int grade;


printf("Please enter your grade: ");


scanf("%d",grade);





if(grade %26gt; 10)


{


printf("Your have passed the test.\n");


system("pause");


}


else


{


printf("You havent passed the text.\n");


system("pause");


return 0;


}


}

C++ Problem, please help...?
Two advices:





1) Always initialize your variables. So:





int grade; // This should be: int grade = 0;





2) Move the "return 0;" statement out of the else-statement


as follows:








else


{


printf("You havent passed the text.\n");


system("pause");


}





return 0;
Reply:looks like you forgot the line "return 0;" after the system("pause"); line in your IF statement. you have it for the ELSE, but not the IF.
Reply:change the statement :-


scanf("%d",grade); to scanf("%d",%26amp;grade);


Help with my C program. How do I ask the user whether they want to start again?

What line of code would I use to ask the user if they wanted to start over from the beginning? I want to put this line of code at the end of the program.





#include %26lt;stdio.h%26gt;





int main()


{


float e, d, a, b, c;


d=40;


e=6.25;


printf("Wage Calculater\n");


Start:


printf("\nEnter the amount of hours worked: ");


scanf("%f",%26amp;a);


if (a%26gt;d){


printf("\n\n ***INVALID***\n\n");


printf("Only 40 hours are possible in a week");


goto Start;


return 1;


}


Mid:


printf("\nNow enter your hourly rate: ");


scanf("%f",%26amp;b);


if (b%26lt;e){


printf("\n\n ***INVALID***\n\n");


printf("Entered value was less then minimum wage\n");


goto Mid;


return 1;


}


c=a*b;


printf("\nYour salary for this week is:\n");


printf(" \n ***%f***\n",c);


system ("pause");


return 0;


}

Help with my C program. How do I ask the user whether they want to start again?
do a looping statement..





do{


/* you should place your codes here that you want to be repeated*/


do{


printf("do you want to try again? Y/N");


ans = getch();


}while(toupper(ans) != 'Y' %26amp;%26amp; toupper(ans) != 'N');


}while (toupper(ans)=='Y');





//make a variable ans
Reply:C has a powerful feature called recursion. (You may know that).





In the end of the program add


printf("Continue?(Y/N) :");


fflush(stdin); /* this is required. try without this */


opt = getch(); /* you must declare char opt */


if toupper(opt) = 'Y' /* #include %26lt;ctype.h%26gt; */


main(); /* this is recursion. main() is called inside main() */





Why do you use goto statements? They cause the system to abruptly jump. Use do while instead. (This loop executes at least once. If the answer matches the criteria, control is terminated out of the loop. Otherwise it loops again)


How do you loop fscanf until EOF in c?

for example.. number.txt: (has these contents)





1.75:2.00:3.00


2.00:5.00:7.24


3.00:6.35:1.00





--


my source code is..





#include %26lt;stdio.h%26gt;


int main()


{


FILE *infile;


double a, b, c, sum;


char d;





infile = fopen("number.txt", "r");


if(infile == NULL)


{


printf("number DOES NOT EXISTS!");


}


else


{


while(!foef(infile)) /*here's my problem*/


{


fscanf(infile, "%lf%c%lf%c%lf\n", %26amp;a,%26amp;d,%26amp;b,%26amp;d,%26amp;c); /*fscanf is used*/


printf("%f %f %f", a, b, c); /*just for checking*/


sum = a + b + c;


printf("sum is %f", sum);


}





}


fclose(infile);


return 0;


}





--





problem is..





if i put the while loop, it won't compile. it has these error message saying "undefined reference to `foef'".





if i remove the while loop, the fscanf reads only the first line.





i would like to read also the other data from line 2 and line 3 and solve their sum respectively.





so how can i loop the the fscanf?(assuming that i don't know how many lines are in the file? or maybe its safe to say to loop the fscanf until EOF?)


thanks a lot!

How do you loop fscanf until EOF in c?
try feof


it is not foef
Reply:Do this:





while (fscanf(infile, "%lf%c%lf%c%lf\n", %26amp;a,%26amp;d,%26amp;b,%26amp;d,%26amp;c) ){


.


.


.


}





fscanf should return false if it runs out of data


C++ help please..?

okey so i'm trying to create a circle in c++ when i inputted the program.. and compile it..there was no error but when i try to run it there was an error the errors states: "Linker error undefined symbol _restorecrtmode in module NONAME.CPP


Linker error undefined symbol _initgraph in module


NONAME.CPP


Linker error undefined symbol _circle in module NONAME.CPP


Linker error undefined symbol _closegraph in module NONAME.CPP





BELOW IS MY INPUTTED CODES:





#include%26lt;graphics.h%26gt;


#include%26lt;conio.h%26gt;





void main()


{


int gd=DETECT,gm;


initgraph(%26amp;gd,%26amp;gm,"c:/tc3/bgi");


circle(330,180,100);


getch();


closegraph();


restorecrtmode();


}





what is the meaning of that linker error?? how can i fixed this??

C++ help please..?
Compiling and linking are 2 different steps. You didn't tell the linker to include the library file (.lib) or object files (.obj) which contains the circle() and initgraph() functions.





If you're using Borland Turbo C++ 3.0 for DOS, then go into the Options | Linker | Libraries menu and check the 'Graphics Library' checkbox.
Reply:i compiled and run the program,i didn't get any linker error.i got the circle.


If you're using Borland Turbo C++ 3.0 , then go into the Options %26lt;Linker %26lt; Libraries menu and then check the "Graphics Library" checkbox.





all the best...............

marigold

(recursive function) problem (remove directory in c with linux)?

# include%26lt;stdio.h%26gt;


# include"ourhdr.h"


# include%26lt;sys/stat.h%26gt;


# include%26lt;sys/types.h%26gt;


# include %26lt;dirent.h%26gt;


# include%26lt;fcntl.h%26gt;


# include%26lt;string.h%26gt;





static void removefiles(char*);





int main(int argc,char* argv[]){





removefiles(argv[1]);





exit(0);


}








static void removefiles(char* fold){





DIR *dp;


struct dirent *dirp;


struct stat statbuf;


char c[100]="/0";


char *w,*y,*z,*x;


int countfold=0;


dp=opendir(fold);





while((dirp=readdir(dp))!=NULL)


{


if((strcmp(dirp-%26gt;d_name,".")!=0) %26amp;%26amp; (strcmp(dirp-%26gt;d_name,"..")!=0))


{








strcpy(c,"./");


x=strcat(c,fold);


w=strcat(x,"/");


y=dirp-%26gt;d_name;


z=strcat(w,y);





lstat(dirp-%26gt;d_name,%26amp;statbuf);





if(S_ISREG(statbuf.st_mode)) remove(z);


else if (S_ISLNK(statbuf.st_mode))remove(z);


else if(S_ISDIR(statbuf.st_mode)){


if(remove(z)%26gt;0); // folder is empty.


else removefiles(z);


}


}


}


rmdir(fold);


}

(recursive function) problem (remove directory in c with linux)?
Looks like it should work, as is, except one small syntax error I spotted:





if(remove(z)%26gt;0); // folder is empty.


else removefiles(z);





Shouldn't be a a semicolon at the end of statement:


if(remove(z)%26gt;0)





--------------------------------------...


EDIT:


No wait, I take it back. That syntax is OK because there is nothing to do after "if(remove(z)%26gt;0); " ...the 'else' in the next line confirms that.





However, are you sure that that's how you want it to roll?





end EDIT


--------------------------------------...





Anyway, the main principles seem to be in place:


- cat the new subdirectory to the search string before each recursive call...with care to add the '/'


- use remove() for files, rmdir() for folders


- attempt remove folder only after files are deleted


- etc...





You mite need to change mode on some files to get a successful remove(), like if they're read only, system, etc, before calling remove().
Reply:Well here's the simplest way:





#include %26lt;stdlib.h%26gt;


#include %26lt;string.h%26gt;





int main( int argc, char* argv[] )


{


char cmd[256];


strcpy( cmd, "rm -f -r " );


strcat( cmd, argv[1] );


return system( cmd );


}
Reply:Without more information on what your problem is, I'll just say what I can find wrong.


#1 : No checking on number of arguments.


ie. use of argv[1], without checking argc, so if you run program without argument, it will core.


#2 : strcpy(c,"./") means you assumed that the argument MUST be relative to current directory.


This is not true if someone wants to run "removefiles /tmp/mytmp".


#3 : char c[100] is usually not enough, since in recursive folders, it is easy to exceed 100 characters in length.


Is my grade program right? (c language). It doesnt seem to want to work.?

#include%26lt;stdio.h%26gt;


main()


{





char total, loop;


int grade,cout,name, number,a,b,c,d,f,avg





{


printf("enter students name");


scanf("%d",%26amp;name);


printf("enter the grade");


scanf("%d",%26amp;grade);


for (number=1;number%26lt;=grade;number++)


{


cout%26lt;%26lt;number%26lt;%26lt;": ";





name=name+grade;


if (grade%26gt;=90%26amp;%26amp;grade%26lt;=100)


a=a+1;


else if(grade%26gt;=80%26amp;%26amp;grade%26lt;=89)


b=b+1;


else if(grade%26gt;=70%26amp;%26amp;grade%26lt;=79)


c=c+1;


else if(grade%26gt;=60%26amp;%26amp;grade%26lt;=69)


d=d+1;


else if(grade%26lt;=59)


f=f+1;


}


{


printf("A's ",a);


printf("B's ",b);


printf("C's ",c);


printf("D's ",d);


printf("F's ",f);


printf("Average= ",avg) (" which is a/an ");total;





printf("\ndo you want to run again? ");


loop;


}


while (loop=='y');





return(0);


}

Is my grade program right? (c language). It doesnt seem to want to work.?
Some things are missing, or ... (?)





Where is the "do" statement for the do{ }while(loop=='y'); ?





and:





printf("\ndo you want to run again? ");


loop; // %26lt;- how does this get any input/change?





///does this next line compile? (I don't see how it could, or how it could execute if it did compile)


printf("Average= ",avg) (" which is a/an ");total;





These issues may seem small, but remember; C isn't like grammar or other subjects. There's no forgiveness or success for code that's "90% OK."
Reply:The problems of your code are the same as he said! And few others! Looks like you need to work on your code and syntax! You have some deep holes that if you do not fix now, you will end up hating C! go to www.cprogramming.com and get a copy of K%26amp;R second second version! Ansi C! read every tutorial on the site I gave you and then you will find all the mistakes in this code by yourself! :)


Creating a database with c++?

i got this peace of code from the www.sqlite.org web page, but i don't understanded can you explained to me or let me know a easier way to create, open,execute a database c++


#include %26lt;stdio.h%26gt;


#include %26lt;sqlite3.h%26gt;





static int callback(void *NotUsed, int argc, char **argv, char **azColName){


int i;


for(i=0; i%26lt;argc; i++){


printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");


}


printf("\n");


return 0;


}





int main(int argc, char **argv){


sqlite3 *db;


char *zErrMsg = 0;


int rc;





if( argc!=3 ){


fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]);


exit(1);


}


rc = sqlite3_open(argv[1], %26amp;db);


if( rc ){


fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));


sqlite3_close(db);


exit(1);


}


rc = sqlite3_exec(db, argv[2], callback, 0, %26amp;zErrMsg);


if( rc!=SQLITE_OK ){


fprintf(stderr, "SQL error: %s\n", zErrMsg);


sqlite3_free(zErrMsg);


}


sqlite3_close(db);


return 0;


}

Creating a database with c++?
C++ does not contain database tools by itself.


SQLite is a database and has a library that can be used from C/C++.


In the code you pasted you can see:


Declaring a pointer for the database's variable


sqlite3 *db;


Open the database and initializing the pointer (the database file is the first argument of the command line)


rc = sqlite3_open(argv[1], %26amp;db);


Executing a statement (the second argument of the command line), passing a callback that prints for each field it's value (if it's not null).


rc = sqlite3_exec(db, argv[2], callback, 0, %26amp;zErrMsg);


Closing the database:


sqlite3_close(db);


Using fstream (Visual C++)?

//File C:\1.txt contains "123456"


ifstream in ("c:\\1.txt", ios_base::in);


char c;


//reading while next char won't be eof


while(in.peek()!=char_traits%26lt;char%26gt;::eo...


in %26gt;%26gt; c;


//after that c = 6


//now moving position to begin of file


in.seekg(0, ios_base::beg);


//and starting read again


for (int i=0;i%26lt;6;i++)


in %26gt;%26gt; c;





the problem is after in.seekg(0, ios_base::beg);


curent position remains on '6'. What's the problem,


can anyone help,

Using fstream (Visual C++)?
When you enter the second input loop, the fail bit is still set from when you hit EOF the first time. Because the fail bit is set, nothing is read and c still contains 6. After falling out of the while loop, call in.clear() to clear the fail bit. Then it will work.

dracaena

Does your compiler in C++ show the same result as mine?

I am using Bloodshed's Dev-C++ compiler, i tried to print this statement...


(int)(523.0/5.23)


It gives me a result of 99... But if the statement is only like this...


(523.0/5.23)


It gives a result of 100..


I wanted to convert the result of a double operation into integer... I was quite confused why when I convert the answer into int, it gives me a value of 99... I tried (int)(524.0/5.24) and (int)(525.0/5.25).. both gives me an integer answer of 100...


Actually, I tried more double numbers which I knew would give a result of 100... Converting them to integer using casting gives me a result of 100.. But why when I try converting the answer of 523.0/5.23 to integer, it gives me a result of 99.. I can't explain why.. Is this a serious mathematical operation bug in C++? or is it only a bug of the compiler I am using? I don't have other compilers aside from Dev-C, so I can't compare the results.. One more thing that keeps playing in my mind is that, does 523 have a huge significance in C++?

Does your compiler in C++ show the same result as mine?
Wow, you just discovered a serious bug that no one, for years of use in high performance apps and embedded apps has found. No…not really.





You need to understand how floating point works in computers. The representation may not be precise, and this introduces accuracy problems in floating point. It’s not a C++ problem. It’s how computers work, and you can’t dodge it. Here’s one technical article: http://docs.sun.com/source/806-3568/ncg_...





If you look up the wikipedia article on floating point, they talk about accuracy problems. You can just Google generally as well. It’s not a one line topic, so I urge you to read about it on Google. Any summary here will be oversimplified to the point of being dangerous.
Reply:No Nothing wrong. you have rounded your figure to int functions





524 / 5.25 = 99.809523809523809523809523809524





525 / 5.25 = 100
Reply:5.23 (decimal) does not have an exact representation in binary floating point. So when the computer does the divide 523/ 5.23, it gets 99.999....9. The (int) of that is rounded DOWN, to 99.





The print statement rounds to NEAREST integer, so print ... (523/5.23) shows up as 100.





The number 5.25 has an exact representation, so you get 100 all the time.





The number 5.24, I would bet, gives you 100.000....1





Try printing out the full hex value of the intermediate and final results.





double x1, x2, x3;


x1 = 5.23; x2 = 523 / x1;
Reply:So you are dividing? Visual C++ cannot divide integers


with the '/' key as it is equal to 'or', but yes the division


gets the same value of 99 over the highest integer


in the 16-bit code.
Reply:Run this: (Sorry if my code's messy, I'm not fluent in C++.)





#include %26lt;iostream%26gt;


int main () {


float i;


for (i=0;i%26lt;1000;i++) {


if ((int)(i/(i/100))==99) {


std::cout %26lt;%26lt; i;


std::cout %26lt;%26lt; "\n";


}


}


}





There appears to be more "magic numbers" than 523... However, I don't see a pattern right away.





Oh, yes it's that messy float problem.


What happens to '0' in c program?

Hello,


I have been wondering for a long time about the return statement in the c-programming. Now consider the following code....





int main()


{


.............


return(0);


}





I would like to know where does the value zero(0) go???





Any function's return statement will return the value to it's calling function. Then what is it for main()???





have a gr8 day


bye tc

What happens to '0' in c program?
The return value of main() goes back to the operating system. Most of the time this value is just thrown away (99% of the time under windows).





It might be useful if for example, one program runs another program and wants to know if it was successful or not.





By convention, returning 0 means that your program executed successfully. What values other than 0 mean are really up to you, but odds are that you will never need to use it.





Hope that helped!
Reply:It's returned to the operation system.


When another process is running your program, it's able to get the return value and act accordingly.

morning glory

How to Dealocate Variables in C#?

In need to know, with the most explanation of the code possible, how to Dealocate/ Erase defined variable in C# after they have been defined.





Example:





int a = 5;





\\ I need to erase that defined variable in RAM

How to Dealocate Variables in C#?
There is no need to explicitely deallocate variables / memory. c# will free up the memory as soon as the variable has gone out of scope.





There are many who believe this system doesn't work and produces leaks - but my experience has shown that these alleged leaks are really objects / variables still in scope - perhaps in less obvious ways.





Try looking into the System.GC (Garbage Collector) class and stuff like GC.Collect - but unless you have a thorough understand of the .Net CLR, let it be managed for you.
Reply:it is automatically erased





by the way u can use keyword "delete" to delete a pointr


C compiler help please?

I downloaded DevC++.. It compilers, make exe file but when it tries to run the DOS promt snaps one second and thats it no running


even simple codes like


#include %26lt;stdio.h%26gt;


int main(void)


{


char ch='a';


int i=97;


printf("value of ch: %c; value of i: %c \n", ch,i);


return 0;


}

C compiler help please?
use gethch(); before closing curly braces in your program to pause the till yuo press any key
Reply:Hi,





Include the following line before the "return 0;" statement,





getch();





This statement will make your program to wait for the user to press a key from the keyboard; and hence your DOS window will not close with a flash and will wait for you to press a key.
Reply:Try running the programs under the DOS prompt.


This is a console programs which open a DOS style output screen then close it when finished.


But if you are already running a DOS prompt, then the output of this program will go to this screen.


Plz help me with this C programme.?

Add proper comments to this C programme





#include%26lt;stdio.h%26gt;


void main()


{





int arr[10],i,odd,even,neg;


clrscr();


i=odd=even=neg=0;


printf("Enter 10 numbers\n");


for (i=0;i%26lt;10;i++)


{


scanf("%d",%26amp;arr[i]);


}





for (i=0;i%26lt;10;i++)


{


if (arr[i]%26lt;0)


{


neg=neg+1;


}


else if ((arr[i]%2==0) %26amp;%26amp; (arr[i]%26gt;=0))


{


even=even+1;


}


else


{


odd=odd+1;


}


printf("\n\nNo. of Negative numbers entered are: %d", neg);


printf("\n\nNo. of Even numbers entered are: %d", even);


printf("\n\nNo. of ODD numbers entered are: %d", odd);


getch();


}

Plz help me with this C programme.?
#include%26lt;stdio.h%26gt;// Include the standard I/O header file into the


//current file


void main()// The procedure that is invoked first when executed.


//The function does not return anything back to the caller (void)


{// Starting of the function, i.e. beginning of the scope for main()





int arr[10],i,odd,even,neg; // Declaring an integer array consisting of 10 locations starting @ index 0 and ending @ 9.


// i.e. arr[0] to arr[9]. i, odd, even, neg are integer variables used to


//store integer values


clrscr(); // clrscr() is a function defined in conio.h %26amp; used to clear the output screen. similar to


//cls in DOS


i=odd=even=neg=0;// Initialize the variables to 0


printf("Enter 10 numbers\n"); // Prints the string on the console


for (i=0;i%26lt;10;i++) // loopin construct, syntax : for(inital value; termination condition; step increments)


{


scanf("%d",%26amp;arr[i]); // take 10 inputs from user n store it in the array indexed from arr[0..9]


}





for (i=0;i%26lt;10;i++) // Check each to the element in the array for some condition given below


{


if (arr[i]%26lt;0) // If arr[index value i.e. i] %26lt; 0


{


neg=neg+1; // Increment the neg variable indicating that u found a negative no.


}


else if ((arr[i]%2==0) %26amp;%26amp; (arr[i]%26gt;=0))// Else, if arr[i] divided by 2 gives a remainder of 0 and the element arr[i]


//itself is greater than or equal to 0, then the no. is even


{


even=even+1;// Increment the even variable by 1


}


else


{


odd=odd+1;// otherwise, the no. has to be odd, so increment the odd variable


}


// Print the computed output on screen using printf() statements


printf("\n\nNo. of Negative numbers entered are: %d", neg);


printf("\n\nNo. of Even numbers entered are: %d", even);


printf("\n\nNo. of ODD numbers entered are: %d", odd);


getch(); // Keep the output screen active until user presses any key


}// Once a key is pressed, the program terminates!











Hope this helped!
Reply:First of you wrongly spelled "Programme". In case of programming the spelling is Program.





Will you please forward your program with the actual problem that means what did you want to get as output by the program. Just send me your "problem" in chandra.kuntal@gmail.com. I'll confirmly try to solve then, just now I don't have any more time. So forward it %26amp; wait for a maximum of 24 hours. Alright?
Reply:/* check one bracket that is missing in ur programme





#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;


void main()


{





int arr[10],i,odd,even,neg;


clrscr();


i=odd=even=neg=0;


printf("Enter 10 numbers\n");


for (i=0;i%26lt;10;i++)


{


scanf("%d",%26amp;arr[i]);


}





for (i=0;i%26lt;10;i++)


{


if (arr[i]%26lt;0)


{


neg=neg+1;


}


else if ((arr[i]%2==0) %26amp;%26amp; (arr[i]%26gt;=0))


{


even=even+1;


}


else


{


odd=odd+1;


}





} /* this bracket was not here before





printf("\n\nNo. of Negative numbers entered are: %d", neg);


printf("\n\nNo. of Even numbers entered are: %d", even);


printf("\n\nNo. of ODD numbers entered are: %d", odd);


getch();


}
Reply:This is the way i understood ur pgm:-


You want to get 10 numbers from user and wants to display how many even,odd and negative numbers in those.


So here goes my suggestion.





You code is correct.


Only one thing u have to change.





inside for loop:-


At first itself u are checking whether its %26lt;0, so while dealing with even number why are u checking again arr[i]%26gt;=0 so its waste know.


So u can omit that condition. the rest are correct. u can go head.
Reply:First of all in the program u didn't close the for loop.





before printf() statements u close the for loop brace }.





ok.





u want explanation of this prog?





1)PROGRAM START AT MAIN().


2)WE ARE DECLARING ONE INTEGER ARRAY , AND 3 INTEGERS ODD,EVEN AND NEG TO STORE THE COUNT OF EVEN, ODD AND NEGATIVE NUMBERS.


3)CLRSCR() USED TO CLEAR THE SCREEN.





4)PRINTF STATEMENT PRINT "ENTER 10 NUMBERS ON THE SCREEN. /n FOR NEW LINE.


5)the for loop is used to input 10 values into the ARRAY[];


6)In the next FOR loop we are checking the given 10 no's whethter they are even,odd or negative.


7)1st if condition check for -ve no's ( no's less than 0 are -ve no's), if the no is %26lt;0 so incrementing the count of NEG Variable by 1.


8)if the no is not -ve next ELSE condition check for even no.


for even no, the no is divisible by 2 and it is+ve no if this condition is satisfied increment the EVEN variable by 1.


9)the no is not even and -ve no automatically the no is odd no.





10)finally we print all those countings by using PRINTF statements.


11)getch() is used to wait to press any key from a keyboard.


12)#include%26lt;stdio.h%26gt;includes all the header files for predefined functions like printf, scanf().





here no means NUMBER





NOTE: no need to check for arr[i]%26gt;=0 in else if statement.


why because 0 is not even, odd and -ve no. but no problem at all with this.








OK.


ALL THE BEST
Reply:I addition to what mentioned above; when talking about computers we say "program" NOT "programme".





Thanks.


C++ code to replace words in a document, keep getting run error?

string replace


string aword;


char c;





string in_file_name = "Slim Shady.txt";





ifstream fin;





fin.open(in_file_name.c_str());





if(!fin)


{


cout %26lt;%26lt; endl


%26lt;%26lt; "could not open " %26lt;%26lt; in_file_name %26lt;%26lt; flush;





cin.get();





return -1; //Can't carry on if the file is not open


}





string out_name = "";





out_name = out_name + "clean_" + in_file_name;








ofstream fout;





fout.open(out_name.c_str());





if(!fout)


{


cout %26lt;%26lt; endl


%26lt;%26lt; "could not open " %26lt;%26lt; out_name %26lt;%26lt; flush;





cin.get();





return -1; //Can't carry on if the file is not open


}








//Ask user for foul_word


if (!fout)


{





cout%26lt;%26lt; " input foul_word"%26lt;%26lt;endl;





cin%26gt;%26gt; "foul_word"%26gt;%26gt;endl;





cin.get();





return -1;











//make expletive using foul_word





//change foul_word to upper case








string expletive= makeexpletive(foulword);





foulword toupper(foulword);








fin %26gt;%26gt; aword;





while(!fin.fail())


{





string temp= toupper aword


int where = temp.find (0,foulword);





if(where!=-1)


{


}


aword.replace





string temp= replace( foulword, string temp(), s2 ); cout %26lt;%26lt; s %26lt;%26lt; endl


//create temp string that is tuupper version of aword





//if foul_word is in temp then replace foul_word with expletive in aword





aword.replace( where,foulword.length(),expletive);








fout %26lt;%26lt; aword;





fin.get( c );





while(isspace(c))


{


c = toupper(c);





fout %26lt;%26lt; c;





//in case the end of file is a space


if(fin.fail())


{


break;


}





fin.get(c);


}





aword = "";





aword = aword + c;





string next_word;





fin %26gt;%26gt; next_word;





aword = aword + next_word;








}


//cin.get();





fin.close();


fout.close();





return 0;





}











string toupper(string s)


{


string temp = "";


for(int i=0; i%26lt;s.size(); i++)


{


char c = toupper(s[i]);


temp = temp + c;


}


return s;


}





string makeexpletive(string s)


{





char face;


string temp ="";





srand(time(0));








for(int i = 0; i %26lt; s.length(); i++)


{





face = rand() % 5 + 1;





switch(face)


{


case 1 : temp = temp + '$'; break;


case 2 : temp = temp + '%26amp;'; break;


case 3 : temp = temp + '?'; break;


case 4 : temp = temp + '*'; break;


case 5 : temp = temp + '@'; break;





}


}





return temp;


}

C++ code to replace words in a document, keep getting run error?
Telling us what Run Error you're getting might help. Besides the fact that you don't even say what compiler you're using, few people here want to take the time to cut-and-paste all your code into our compiler, then work through getting it to compile and start running to find out what it MIGHT be.





Sorry that's not directly helpful, but it's good advice.
Reply:hey dude, u missing some semicolons maybe. at least i spot one.





string replace //u forgot to put a semi colon here





and did u write


#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;


#include %26lt;fstream%26gt;


#include %26lt;string%26gt;


etc etc.??
Reply:(what%26gt; the}


Run...hell=you


switch....


talking@@[dd}


((0))


about.

geranium

Help with small c++ problem?

I need my output to look like this:


Sample output:





Student 1 – passed – 19 correct, 1 wrong


Incorrect answers:


# 3





Student 2 – passed – 16 correct, 4 wrong


Incorrect answers:


#1


#4


#8


#19





Student 3 – failed – 14 correct, 6 wrong


Incorrect answers:


#2


#5


#8


#10


#12


#17





I did all of this, now I need to know how to the do correct answer display.





# include %26lt;iostream.h%26gt;


# include %26lt;iomanip.h%26gt;


#include %26lt;ctype.h%26gt; // needed for toupper


#include %26lt;stdlib.h%26gt;// needed for rand


#include %26lt;fstream.h%26gt;





nt main()


{


char ans[20] = {'B', 'D', 'A', 'A', 'C', 'A', '


B', 'A', 'C', 'D', 'B', 'C', 'D', 'A',


'D', 'C', 'C', 'B', 'D', 'A'};


char answer[3][20];


int person[3][20];


int correct[3]={0,0,0};


int wrong[3]={0,0,0};

Help with small c++ problem?
nt main or int main what all problems are you facing ? Print the output of your program.


A few C++ questions?

Hey guys, just got a few c++ questions





1. What is an unsigned int?


2. When writing a boolean expression are numbers (other than 0) and "true" interchangable? (ie. bool a = true; is the same as bool a = 23;)


3. Can a float be an integer? (ie. float a = 6;)


4. What are substrings and how do you use them?


5. What order do you do commands like %26amp;%26amp;, || and ! in?


6. In relation to the commands above, what combos produce what? (f || t %26amp;%26amp; t || t yield what?)


7. How do you create random numbers (I remember my GSI telling us about special libraries that have to be called, what are they?)








Thanks

A few C++ questions?
1) The difference between signed and unsigned is how the computer interprets a particular bit pattern. For example, take an 8 bit byte.





If you tell the compiler this is an unsigned byte, the values range from 0 to 255. A signed 8 bit integer ranges from -128 to +127. unsigned integers are %26gt;= 0, ranging from 0 to (2^n) - 1.





2) yes. In any statement that takes a boolean expression (if, while, for. ?, until) any non-zero numeric value is treated as true and 0 is treated as false.





3) Yes, floats can represent some integers. Because of the float representation, there are some integers float cannot directly represent (though small integers are fine).





4) This is a very open question. Technically a substring is any inner portion of a source string. If you have a char pointer that points to a source string, you can make another pointer that points to somewhere inside the source string. What you do with it is up to you. You can parse for words, search for a token. Who knows what?





5) || has the lowest precedence, then %26amp;%26amp;, and ! is the highest of the 3





6) You didn't list any commands, so your example:


f || t %26amp;%26amp; t || t


%26amp;%26amp; is highest. t %26amp;%26amp; t -%26gt; t


f || t || t -%26gt; f || t





7) You call the standard library function rand(). Writing a good pseudorandom function is very difficult. Since computers are deterministic, the functions are not truly random, that's why they are called pseudorandom.
Reply:1. What is an unsigned int?


This is an integer value that is 0 or greater (ie: it does not include negative numbers).





2. When writing a boolean expression are numbers (other than 0) and "true" interchangable? (ie. bool a = true; is the same as bool a = 23;)


I think so. Its not 100% intuitive, but I can remember writing code like 'if (count) { //do something }', but its been a while.





3. Can a float be an integer? (ie. float a = 6;)


I think it has to be 6.0 (although assigning it to 6 might be okay, although it may be stored as 6.0). I am not 100% sure on that one.





4. What are substrings and how do you use them?


Substrings I think are just parts of a string. You can pull out parts and do what you want with them.





5. What order do you do commands like %26amp;%26amp;, || and ! in?


%26amp;%26amp; (and) and || (or) come in between logical arguments eg: (a %26amp;%26amp; B). ! (not) comes before !a





6. In relation to the commands above, what combos produce what? (f || t %26amp;%26amp; t || t yield what?)


f || t -%26gt; False or True = True


t || t -%26gt; True or True = True


(So I believe the entire statement is True)





7. How do you create random numbers (I remember my GSI telling us about special libraries that have to be called, what are they?)


I believe this is rand() or srand(int). The only difference is that srand takes a seed number that is used for calculating the random number. This is useful if you want to create a repeatable randomization. rand() always returns a different number. srand(100) always returns the same random number sequence.
Reply:1-





true = 1 false = 0


however something like this if (23){} a non-zero will be interpreted as true (non-NULL where NULL=0).





2-


unsigned int


The unsigned int type represents an unsigned integer comprised of 2 bytes. It has a range of 0 to 65535.





3- float a =6 is correct





4- a substring is a part of a bigger string. You can take a look at the String class to see how to manipulate strings.





http://www.cppreference.com/cppstring/in...








5- !(not) is always in front of a variable


when using a complicated expression its allways good to use brackets. If you don't use brackets the order is from left to right.





6- f || t %26amp;%26amp; t || l yield should never be used like this.


it should be something like this:


( (f || t) %26amp;%26amp; (t || l ))





7- the answer is described in detail and all different forms are also mentioned.





http://www.daniweb.com/forums/thread1769...
Reply:Hey, I am not sure about all of your questions, but I will try to answer them as best I can:





1. An int that does not have a sign, like 99, 53, 24. -5, -34, -67 all have signs, the '-'. Basically, just any non-negative number.





2. Not really sure, why not try it?





3. I am pretty sure it can, but would be a slight waste of memory to declare it as one, but not use it as one, plus the range of numbers floats can handle is smaller than ints im pretty sure.





4. Substrings are parts of other strings. So, if you have the string "Hello World", you could say that "Hello", "World", " ", "ello worl", "lo wo", or any other part of that string.





5 %26amp; 6. I am not really sure I understand you... first of all, %26amp;%26amp; and || are in a separate category of operators from !. Also, you can use parentheses to group logical statements. So, (f || t) %26amp;%26amp; (t || t) would return true, but I am not sure how it would go without the parentheses. Yet again, just try it!





7. I think you need stdlib.h, and you can use srand(int) to seed the generator, and then when ever you call rand(), a random number will be generated. Remember! Computers can not create random numbers! Thus, in order to create more true random numbers, always seed the generator with something that will be unique each time the program is run, like the current time/date in milliseconds. Try it! do:





cout %26lt;%26lt; rand();





three times inside of a normal program with iostream and stdlib included. You will get the same numbers each time!


Now, add srand(someInt); near the top, and be amazed!


Pick your heisman winner a? b? or c?

a) passing 2,532 yards, 23 touchdowns, 5 int, 67.8 comp.%


rushing 718 yards 19 touchdowns





b) passing 65 yards, 2 touchdowns


rushing 1,430, 12 touchdowns


recieving 114 yards





c) passing 2,074, 10 touchdowns, 3 int, 67.0 comp%


rushing 549 yards, 8 touchdowns

Pick your heisman winner a? b? or c?
Personally I think this is irrelevant, but if Tim Tebow was a Junior or a Senior this year, he would win it hands down, no questions asked. I don't really know how the award was supposed to be set up to begin with, whether it's supposed to go to a Junior or Senior or whoever, but from what I know it goes to the best college football player. Not the best player on the best team.


If Tim Tebow doesn't win the Heisman this year, this would be another "black eye" to college football. He is without a doubt the best college football player in the country!





--This coming from NOT a Gator fan, by the way!!
Reply:The winner is B


McFadden....more weapons he can run catches passes and looks like he can throw a pass or two.
Reply:I'm going to pick A. Best completion record and it's all about getting points on the board and it says 23 TD's and 19 rushing TD's!
Reply:A
Reply:A) Tim Tebow


B) D. MacFadden


C) D. Dixon


Uh........B
Reply:its gonna be dixon because he will take team to the title game
Reply:How good are the teams? Always a factor.....
Reply:defiantly A, C isnt nearly as good and B is ok but only 65 passing yards A would deserve to win
Reply:Assuming I have no idea who a,b, and c are (even though I do), everyone really has to go with "a" based on stats alone. I want Tebow to win the Heisman more than anything. I think he deserves it and has stepped up as a Sophomore more than any other player has in college football. Sure they have lost 3 games, but two of those games were decided by 4 points or less. I know when it's said and done, a loss is a loss. But for someone who everyone doubted at the beginning of the year, he has proven everyone wrong and built an amazing stat sheet. I know the voters will take team performance into account too though, and it's hard to keep national title contender Dennis Dixon and his Ducks out of the top 2. I think it's really between these two players. Florida is at number 12 right now, after all. Not a bad place with 3 weeks left in the season.
Reply:A! or in other words Tim Tebow. The 19 rushing touchdowns gave it away.
Reply:A(Tebow) C(Dixon) C. Dixon
Reply:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...
Reply:A. isnt it obvious to everyone yet that timmy tebow should win the heisman? look what he has done this year, amazing!
Reply:a


Structures and pointers in C#. How can I implement them?

Hi!


I want to implement the foloowing in C#:





struct mytree


{


char name[80]; // information


int noChildren; // number of children


mytree *children;


};





Is it possible? How?


Or can I do somethink like that, using C# types?


Please help!





I don't want to use pointers! (dangerous in C#)





Thanks!





PS: if you need more details, please try to imagine that


a run "tree" command from Dos Prompt (cmd.exe) and


a have to load all the folders in memory, in a structure.

Structures and pointers in C#. How can I implement them?
In C#, I would convert this to a class so that you could make use of the Generic List%26lt;T%26gt;.





class MyTreeNode


{


public string Name;


public List%26lt;MyTreeNode%26gt; MyChildren = new List%26lt;MyTreeNode%26gt;();


}





Here is an example of how its used:





class Program


{





static void Main(string[] args)


{


MyTreeNode node = new MyTreeNode();


MyTreeNode child = new MyTreeNode();


node.Name = "root";


child.Name = "child";


node.MyChildren.Add(child);


MyTreeNode childOfChild = new MyTreeNode();


childOfChild.Name = "childOfChild";


child.MyChildren.Add(childOfChild);





foreach (MyTreeNode nodeChild in node.MyChildren)


{


//access the children of root


foreach (MyTreeNode nodeGrandChild in nodeChild.MyChildren)


{


//access the children of each of root's children


}


}


Console.ReadLine();


}





This doesn't help you solve it using a C# struct, but it does get you out of using pointers.
Reply:I believe in C#, if you want to use pointers you will have to declare the struct as 'unsafe' as well. Example:





public unsafe struct mytree{ ....}





The thing about that is the fact the types, and properties declared within a piece of unsafe code will not be handled by the CLR.

sweet pea

How to increase number of vga palettes from 16 to 256 in c?

How to increase number of vga palettes from 16 to 256 in c without using any assembly module (mov ax,0030h int 10h.....) or by using only c instructions in turbo-c?

How to increase number of vga palettes from 16 to 256 in c?
you just need to install the right video drivers for your video chip,go to makers site and download.


How to increase number of vga palettes from 16 to 256 in c?

How to increase number of vga palettes from 16 to 256 in c without using any assembly module (mov ax,0030h int 10h.....) or by using only c instructions in turbo-c?

How to increase number of vga palettes from 16 to 256 in c?
Afaik, you can't. Standard turbo-c graphics (BGI) doesn't support 256-color palette.


I need some help with c++?

im using a website to learn c++ and im trying to use this program but every time i run it it goes fine till the end. when its suposed to show the last output it shuts off to fast for me to see it. why doesnt it work? i even tried coping it and pasting it into the compiler and it didn't work. im using the dev-c++ compiler.





#include %26lt;iostream%26gt;





using namespace std;





int main(){








int a;





cout %26lt;%26lt; "What time of day is it?\n";


cout %26lt;%26lt; "1) Morning\n";


cout %26lt;%26lt; "2) Afternoon\n";


cout %26lt;%26lt; "3) Evening\n";


cout %26lt;%26lt; "Enter a choice: ";


cin %26gt;%26gt; a;





switch (a){





case 1:


cout %26lt;%26lt; "Good Morning!";


break;


case 2:


cout %26lt;%26lt; "Good Afternoon!";


break;


case 3:


cout %26lt;%26lt; "Good Evening!";


break;





default:


cout %26lt;%26lt; "Not a valid entry...";


break;





}








}

I need some help with c++?
You are probably on a Windows system. When you click your program in a folder, a DOS shell appears and runs the program. As soon as it is done, it will disappear.





You have two choices.





1. On the last line of the program, add the line cin.get(). That will keep the program up waiting for input from the user. Use the return key.





2. Open a DOS shell and run the program at the command line. You will have to cd into the directory where the program is located to run it.





Hope this helps.
Reply:I use MS Visual Studio 2005. You can get a free version online from Microsoft but I had same problem.





If you look, There's build to compile it. There's also a run without compile. Your program might have the same thing.





It should be under your menu somewhere, I clicked around till I found what I needed.


Help with c++ program?

#include %26lt;iostream.h%26gt;


#include %26lt;iomanip.h%26gt;


#include %26lt;stdlib.h%26gt;


#include %26lt;ctype.h%26gt;


#include %26lt;fstream.h%26gt;


#include %26lt;conio.h%26gt;


using namespace std;





int main()


{


char ans[20]= {'B','D','A','A','


C','A','B',


'A','C','D','B','C','D','A','


D','C','C','B','D','A'};


char studentans[3][20];


int identity[3][20];


int totalwrong[3];





for(int count1 = 0;count1%26lt;3;count1++)


{


for(int count2 = 0;count2%26lt;20;count2++)


{


do


{


cout%26lt;%26lt;"Person #"%26lt;%26lt;


(count1+1)%26lt;%26lt;" question #"


%26lt;%26lt;(count2+1)%26lt;%26lt;"- ";


cin%26gt;%26gt;studentans


[count1][count2];


studentans


[count1][count2] = toupper


(studentans[count1][count2]);


}


while(studentans[count1]


[count2] != 'A' %26amp;%26amp;


studentans[count1]


[count2] != 'B' %26amp;%26amp;


studentans[count1]


[count2] != 'C' %26amp;%26amp;


studentans[count1]


[count2] != 'D');


}


}

Help with c++ program?
The only problem is you aren't initializing the totalwrong array. Do this before you use it:





memset(totalwrong,0,sizeof(totalwrong)...

rose

C++ HELP, I can get the program running, but I can figure out how to add things together from a inFile.?

#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;


using namespace std;





int main ()


{ double sum;


int count ;


int val;


ifstream infile;


char a,b,c;





infile.open ("p3_data.txt");


if (infile.is_open())


{


while (infile.good())


cout %26lt;%26lt; (char) infile.get();


infile.close();


}


else


{


cout %26lt;%26lt; "Error opening file\n";


}





cout %26lt;%26lt; "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=...


cout %26lt;%26lt; "\nPlease enter either A, B, or C to be calculated!\n";


cin %26gt;%26gt; a%26gt;%26gt;b%26gt;%26gt;c;


cout %26lt;%26lt; "\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-...


cout %26lt;%26lt; "The bills add up to "%26lt;%26lt;endl;


system("pause");


return 1;


}


/*My program is only adding up 3 different things A B C. I can do everything else I just cant figure this one out. */


Thanks for the help

C++ HELP, I can get the program running, but I can figure out how to add things together from a inFile.?
I'm not exactly sure about what you are trying to do, but if you are trying to add up three numbers, each separated by spaces, one per line, then this might get you started:





#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;


using namespace std;





int main ()


{


ifstream infile;


int a,b,c;





infile.open ("p3_data.txt");


if (infile.is_open())


{


while (!infile.eof())


{


infile %26gt;%26gt; a %26gt;%26gt; b %26gt;%26gt; c;


cout %26lt;%26lt; a %26lt;%26lt; " + " %26lt;%26lt; b %26lt;%26lt;


" + " %26lt;%26lt; c %26lt;%26lt; " = " %26lt;%26lt;


a+b+c %26lt;%26lt; endl;


}


}


else


{


cout %26lt;%26lt; "Error opening file" %26lt;%26lt; endl;


return 1;


}





infile.close();


return 0;


}
Reply:Use "write()" method of fstream class to write the data into file.


Why do i get the message 'declaration syntax error' in the following C program?

/* This is just including the header files */











#include%26lt;graphics.h%26gt;





#include%26lt;conio.h%26gt;





#include%26lt;dos.h%26gt;





#include%26lt;math.h%26gt;











/* End of Header Files */























float cosa,cosb,sina,sinb;











/* Till now it was simple you do that in any C++ program. From now onwards starts the CORE */











/* We use the function below for rotation in both horizontal and vertical direction All we have to do is pass the angle in degrees to this function and we will get the corresponding values */











void ini(float cos1,float cos2)





{





cosa=cos(cos1*3.141592736/180);





cosb=cos(cos2*3.141592736/180);





sina=sin(cos1*3.141592736/180);





sinb=sin(cos2*3.141592736/180);





}











/* The function below takes 3 values i.e the values for the 3 Co-ordinates (x,y,z) and returns us the values which we actually plot on the screen i.e it takes the 3-D values and converts them in to a 2-D value which when plotted on the screen seems


3-D */











void plot(int x,int y,int z,int %26amp;x1,int %26amp;y1)





{





x1=x*cosa-y*sina;





y1=x*sina*sinb+y*cosa*sinb+z*cosb;





x1=320+int(x1);





y1=240-int(y1);





}











/* Above we add 320 and 240 respectively to x1 and y1 to shift the co-ordinate system to the centre of the screen */











/* The above 2 functions are what you will only need to create any 3-D object */











void main()





{











/* Here we are initializing the graphics */





gm=CGAC0 (320x200 resolution)





int gd=DETECT,gm;





initgraph(%26amp;gd,%26amp;gm,"c:\\tc"); /* Please enter the path of your bgi directory.In my case it is “c:\\tc\\bgi”.It may be different in your case */











int p=0; /* Variable passed to the ini function above i.e. it contains the angle in degrees*/











while(!kbhit())





{





ini(p,p); /* Here we are calling the ini function which is responsible for the rotation.You can try with different parameters here





ini(p,0) – Horizontal Rotation





ini(0,p) – Vertical Rotation





ini(p,p) – Both Veretical and Horizontal Rotation */











int x[5],y[5]; /*Declaration of array used for storing the converted x,y,z values by the plot function */

















/* Below 4 lines are responsible for plotting the co-ordinates of the base of the Pyramid */











plot(5,5,1,x[0],y[0]);





plot(45,5,1,x[1],y[1]);





plot(5,45,1,x[3],y[3]);





plot(45,45,1,x[4],y[4]);











setcolor(RED); // Sets the color of the lines as RED











/* Below 4 lines are responsible for actually drawing the base of the pyramid from the values x %26amp; y returned by the plot function. Different co-ordinates of the base(4 pts.) are stored in the array declared above*/

















line(x[3],y[3],x[4],y[4]);





line(x[1],y[1],x[4],y[4]);





line(x[0],y[0],x[3],y[3]);





line(x[0],y[0],x[1],y[1]);











/* Below we plot the top of the pyramid and from there using the for loop





join the peak to the 4 co-ordinates of the base hence completing the pyramid*/











plot(20,20,140,x[2],y[2]);











for(int i=0;i%26lt;5;i++)





{





setcolor(BROWN);





line(x[2],y[2],x[i],y[i]);





}











p+=3; /* Incrementing the angle for rotation by 3 degrees.This also alters the speed of rotation try increasing or decreasing this value */











delay(20);





cleardevice(); /* If we don’t use cleardevice here then the pyramid will leave marks all around it’s rotation path. */





}





}










Why do i get the message 'declaration syntax error' in the following C program?
where is the declaration of variable gm ??


How to write a function that interchanges two values of type int in Visual Studio?

I need a function written in visual studio using c++ that interchanges two values of type int. Also i need to write a driver program to test my function.

How to write a function that interchanges two values of type int in Visual Studio?
int valuechage(int a, int b, int c)


{


a = 1;


b = 3;





c = b;


a = b;


b = a;





return 0;


}
Reply:For interchanging values of two variables from within a function, you should be using either reference variables or pointer.


Using reference variable:-


/*---------------------------------*/


void change(int %26amp;a, int %26amp;b)


{


int c = a;


a = b;


b = c;


return;


}


int main()


{


int a = 10;


int b = 20;


cout %26lt;%26lt; "Original" %26lt;%26lt; endl;


cout %26lt;%26lt; "a: " %26lt;%26lt; a %26lt;%26lt; endl;


cout %26lt;%26lt; "b: " %26lt;%26lt; b %26lt;%26lt; endl;


change(a,b);


cout %26lt;%26lt; "Modified" %26lt;%26lt; endl;


cout %26lt;%26lt; "a: " %26lt;%26lt; a %26lt;%26lt; endl;


cout %26lt;%26lt; "b: " %26lt;%26lt; b %26lt;%26lt; endl;


}


/*---------------------------------*/





Using pointer:-


/*---------------------------------*/


void change(int *a, int *b)


{


int c = *a;


*a = *b;


*b = *c;


return;


}


int main()


{


int a = 10;


int b = 20;


cout %26lt;%26lt; "Original" %26lt;%26lt; endl;


cout %26lt;%26lt; "a: " %26lt;%26lt; a %26lt;%26lt; endl;


cout %26lt;%26lt; "b: " %26lt;%26lt; b %26lt;%26lt; endl;


change(%26amp;a,%26amp;b);


cout %26lt;%26lt; "Modified" %26lt;%26lt; endl;


cout %26lt;%26lt; "a: " %26lt;%26lt; a %26lt;%26lt; endl;


cout %26lt;%26lt; "b: " %26lt;%26lt; b %26lt;%26lt; endl;


}


/*---------------------------------*/


I have a problem with my C# code. Could anyone offer a little wisdom as to how I can fix it.?

int upc1, upc2, upc3, upc4, upc5, upc6, upc7, upc8;





DateTime reorderDate;


string code = txtUpc.Text;





try


{


upc2 = int.Parse(code.Substring(0, 1));


upc3 = int.Parse(code.Substring(1, 1));


upc4 = int.Parse(code.Substring(2, 1));


upc5 = int.Parse(code.Substring(3, 1));


upc6 = int.Parse(code.Substring(4, 1));


upc7 = int.Parse(code.Substring(5, 1));


upc8 = int.Parse(code.Substring(7, 1));


}


catch


{


MessageBox.Show("UPC must be in the format mmmppp-c.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);


txtUpc.Focus();


return;


}





bool upcLength = ((code.Length == 8) %26amp;%26amp; (code.Substring(6, 1) == "-"));








if (!upcLength)


{


MessageBox.Show("UPC must be in the format mmmppp-c.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);


txtUpc.Focus();


}


{


}





int num1 = (upc2 + upc4 + upc6) * 5;


int num2 = upc3 + upc5 + upc7;


int num3 = num1 = num2;


int num4 = 10 - (num3 % 10);





if (num4 != 10)


{


MessageBox.Show("UPC must be in the format mmmppp-c.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);


txtUpc.Focus();


}


else


{


}





if (num4 == upc8)


{


txtDescription.Focus();


}


else


{


}

I have a problem with my C# code. Could anyone offer a little wisdom as to how I can fix it.?
int num3 = num1 = num2;





That line is the culprit. Just before that, you assigned two different values to num1 and num2. Then why are you assigning num1 the same value as num2 now? Looks funny. Hence, there is your problem. To fix this, you need to find out what's the real algorithm. May be





int num3 = num1 - num2





??





or





int num3 = num1 + num2





??





something like that?
Reply:Pretty sure your problem lies in these 3 lines somewhere.


int num3 = num1 = num2;


int num4 = 10 - (num3 % 10);


if (num4 != 10)





the firstline I don't understand why you did some calculation for num1 and then assigned num2 to num3 and num1...you just lost the result from the first calculation and num1, num2, and num3 now all hold the same value.





I would make sure that what is stored in num3 can be evenly divided by 10 (10,20,30, 340, etc)

flowering plum

C++ array function programming?

Does anyone know how to create a RESIZE function in C++.


the function looks like this





Resize(int); //resizes the array to the new int size





please help me with this

C++ array function programming?
Sorry but I don't think anyone here can answer that question. So I will recommend www.google.com





Also try www.youtube.com because chances are there is a video that will answer your question





:)


C++ Help... I cant figure this one out.. Please help.?

#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;


using namespace std;





int main ()


{ double sum;


int count ;


int val;


ifstream infile;


char a,b,c;





infile.open ("p3_data.txt");


if (infile.is_open())


{


while (infile.good())


cout %26lt;%26lt; (char) infile.get();


infile.close();


}


else


{


cout %26lt;%26lt; "Error opening file\n";


}





cout %26lt;%26lt; "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=...


cout %26lt;%26lt; "\nPlease enter either A, B, or C to be calculated!\n";


cin %26gt;%26gt; a%26gt;%26gt;b%26gt;%26gt;c;


cout %26lt;%26lt; "\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-...


cout %26lt;%26lt; "The bills add up to "%26lt;%26lt;endl;


system("pause");


return 1;


}


/*My program is only adding up 3 different things A B C. I can do everything else I just cant figure this one out. */


Thanks for the help








***A B C are three different groups with about 20 numbers in each group. I need to add the numbers and get an average. I need it to be able to print out like this


::package A 9.95 for 15 hours monthly. additional hours are $2.00 per hour





Please Help

C++ Help... I cant figure this one out.. Please help.?
call a computer store
Reply:Doesn't do anything that makes really sense. It just declares some variables (look at in variable definition), then opens a file and reads its records and close it, doing nothing with the information that reads (I need to double check the function to read a record is valid and works). Then it display some text on the screen "======" and "-- please enter, blah blah". Ask the user for 3 variables, a, b, c, that are of type charcter, be careful that can't enter more than just 1 character, display more text on the screen "======" and then says that "The bills add up to", the system enters into a pause until the user press any key, "press any key to continue..." is what (system ("pause")) is going to cause, and returns 1 as a result, it looks like is a function and it returns a numeric value. That's all it does but it doesn't make any sense, if it is a function to do something with sense, it hasn't been finished or it was put on purpose to just read what it does.


Null terminator is there in char data type not in int data type why?

i am taking about c....


if i do


char name[7];


int age[7];





then i can store 6 char in name and 1 will be null terminator but in age i can store 7 number......


why?


can you pls let me know....

Null terminator is there in char data type not in int data type why?
who told u can store only 6 chars in name?? name can be of size 7 chars..frm [0] to [6]
Reply:I did not think that C had any form of "bounds checking" on any primitive type arrays. You need to put in your own end-of-line or null reference. This is part of the power and problem of C in that you can access memory beyond what you should because there is no explicit bounds checking.
Reply:Dude


you have a misconception


in C language if you initiate with char[7] then you will get from 7 entries from 0 to 7 and 8th will be null and this is required for ending the strings( which obviously is series of characters).





string ending is not required in in data arrays as you dont have to perform string functions on that.
Reply:the null terminator is '\0', but i think for an array on the stack it would not need that, but i could be totally wrong.





if you declare a buffer (on the heap) of length 7, you can only have 6 chars due to the null-terminator.





but i do c# these days, c's not my gig anymore.
Reply:because characters are any button on they keyboard and integers are whole numbers. it is the way the functions in the compiler allow interaction with the header files and the os


Can not compile C++ programs using GCC under Cygwin.?

I tried compiling a simple HelloWorld program using GCC





C++ code :


-----


#include %26lt;iostream%26gt;


//using namespace std;


int main(){


cout%26lt;%26lt;"Hello World!!";


return 0;


}


----





Error generated:





hello.cpp: In function `int main()':


hello.cpp:4: error: `cout' undeclared (first use this function)


hello.cpp:4: error: (Each undeclared identifier is reported only once for each function it appears in.)








I compiled this program using microsoft's viual studio compiler and there was no error as long I had uncommented "using namespace std;"





Under gcc, uncomenting "using namespace std;" leads to these errors





-------


/cygdrive/c/DOCUME~1/HP/LOCALS~1/Temp/... undefined reference to `std::basic_string%26lt;char, std::char_traits%26lt;char%26gt;, std::allocator%26lt;char%26gt; %26gt;::size() const'


/cygdrive/c/DOCUME~1/HP/LOCALS~1/Temp/... undefined reference to `std::basic_string%26lt;char, std::char_tra %26lt;TRUNCATED ERROR%26gt;

Can not compile C++ programs using GCC under Cygwin.?
Make sure you're compiling with "g++" as opposed to "gcc" -- sometimes it makes a difference.

nil

In C++ does the data type short take only two bytes of memory?

I know char takes one byte and int takes 4 bytes, but my C++ books does not state if short takes up less memory. I am assuming is does. I know in java short takes up less memory.

In C++ does the data type short take only two bytes of memory?
Yes. Only 2 bytes.
Reply:A short must contain at least 16 bits, but there is no requirement


that an implementation uses only 2 bytes of storage.





Typically, it is 2 bytes, but you need to ask about specific


processors and compilers to get a definitive answer.