Forum Replies Created
- AuthorPosts
- GWILouisaxwzklaParticipant
try:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152<br />/****************************************************************<br />* File Name : c:programshelptempCG.cpp<br />* Date : November,17,2008<br />* Comments : new project<br />* Compiler/Assembler :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 7:02:58 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include < stdio.h ><br />//#include < string.h ><br />//#include < conio.h ><br />//#include < math.h ><br />//#include < iomanip ><br />//#include < ctype.h ><br /><br /><br /><br /><br />//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@<br /><br /><br /><br />//##################################################################################<br /><br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br /><br />int number = 0;<br /><br />printf ( "Enter a number to square " );<br />scanf ( "%i" , & number );<br />printf ( "the square is %i n " , number * number );<br />return 0;<br /><br /><br /><br /><br />}<br /><br /><br />GWILouisaxwzklaParticipantWhat type of input are you using ( from the console , a file ) ??
GWILouisaxwzklaParticipant3.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576<br />/****************************************************************<br />* File Name : c:programshelptempCG.cpp<br />* Date : November,17,2008<br />* Comments : new project<br />* Compiler/Assembler :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 7:02:58 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include < stdio.h ><br />//#include < string.h ><br />//#include < conio.h ><br />//#include < math.h ><br />//#include < iomanip ><br />//#include < ctype.h ><br />#define MAX_LENGTH 50<br /><br /><br /><br />//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@<br /><br />int strLength ( char * );<br /><br />//##################################################################################<br /><br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />char str [ MAX_LENGTH ];<br /><br />printf ( "Enter a string " );<br />scanf ( "%s" , str );<br />int lengthStr = strLength ( str );<br />printf ( "length of string %i n" , lengthStr );<br />return 0 ;<br />}<br /><br /><br />/******************************* FUNCTION DEFINITION ******************************<br /><br />Name : strLength<br />Parameters :<br /><br />char *<br /><br /><br />Returns: int type<br />Comments: string must be null terminated<br /><br /><br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />int strLength ( char * str )<br />{<br /><br />int i = 0;<br /><br />while ( str [ i ] != 0 )<br />{<br />i ++;<br />}<br /><br /><br />return i;<br />}<br /><br />2.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960<br />/****************************************************************<br />* File Name : c:programshelptempCG.cpp<br />* Date : November,17,2008<br />* Comments : new project<br />* Compiler/Assembler :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 7:02:58 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include < stdio.h ><br />//#include < string.h ><br />//#include < conio.h ><br />//#include < math.h ><br />//#include < iomanip ><br />//#include < ctype.h ><br /><br /><br /><br /><br />//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@<br /><br /><br /><br />//##################################################################################<br /><br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />int sLength;<br />int sum = 0;<br />int i = 1;<br />printf ( "Enter length of series " );<br />scanf ( "%i" , & sLength );<br /><br /><br />while ( i <= sLength )<br />{<br />sum = sum + ( i * i * i );<br />i ++;<br />}<br /><br />printf ( "the sum is %i n " , sum );<br /><br /><br /><br /><br /><br />}<br /><br /><br />GWILouisaxwzklaParticipantDo you have a formula for the sum of the first series ( or the name ) ?
GWILouisaxwzklaParticipantCould do:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758<br />/***************************************************************** File Name : c:programshelptempCG.cpp* Date : November,17,2008* Comments : new project* Compiler/Assembler :****** Program Shell Generated At: 3:18:48 p.m.=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/#include <stdio.h>//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@//##################################################################################//main function ******************************int main ( ){int result;int fail = 0 , pass = 0;char newline;printf ( "Enter Result (1=pass, 2fail , 3=quit: )");scanf ( "%i", & result );scanf ( "%c", & newline); //get newline out of stream ( enter key )while ( result != 3 ){if ( result == 1 )pass ++;else if ( result == 2 )fail ++;printf ( "Enter Result (1=pass, 2fail , 3=quit: ");scanf ( "%i", & result );scanf("%c", &newline); //get newline out of stream ( enter key )}printf ( "pass = %i n" , pass );printf ( "pass = %i n" , fail );return 0 ;}GWILouisaxwzklaParticipantI think this does what you want it to:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118<br /><br />/****************************************************************<br />* File Name : c:programshelptemp.cpp<br />* Date :<br />* Comments : new project<br />* Compiler/Assembler :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 3:59:55 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include < iostream.h ><br />#include < ctype.h ><br />//#include < conio.h ><br />//#include < math.h ><br />//#include < iomanip ><br />//#include < ctype.h ><br /><br />//using namespace std;<br /><br /><br />//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@<br /><br /><br /><br />//##################################################################################<br /><br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br /><br />int sizeOfMatrix;<br /><br />cout << "enter the size of the matrix: ";<br />cin >> sizeOfMatrix;<br /><br />//allocate appropriate matrix:<br /><br />int ** matrix = new int * [ sizeOfMatrix ];<br />if ( matrix == NULL )<br />{<br />cout << "Allocation Error!! ";<br />return 1;<br />}<br /><br />int i = 0;<br />while ( i < sizeOfMatrix )<br />{<br />matrix [ i ] = new int [ sizeOfMatrix ];<br />if ( matrix [ i ] == NULL )<br />{<br /><br />while ( i >= 0 )<br />delete [] matrix [ i -- ]; //clean up memory<br />return 0;<br />}<br />i ++;<br />}<br />//write matrix<br />i = 1;<br />int j = 0;<br />int input = 1;<br /><br />while ( j < sizeOfMatrix )<br />{<br />i = 0;<br /><br />while ( i < sizeOfMatrix )<br />{<br /><br />matrix [ i ] [ j ] = input;<br />i ++;<br />input ++;<br />}<br />j ++;<br />}<br /><br />//output matrix<br /><br />i = 0;<br />j = 0;<br /><br />cout << endl;<br />while ( i < sizeOfMatrix )<br />{<br />j = 0;<br /><br />while ( j < sizeOfMatrix )<br />{<br />cout << matrix [ i ] [ j ];<br />//should use iomanip here!!!!!!!!<br />if ( matrix [ i ] [ j ] < 10 )<br />cout << " ";<br />else<br />cout << " ";<br />j ++;<br />}<br />cout << endl;<br />i ++;<br />}<br /><br />//destroy matrix<br /><br />i = 0;<br />while ( i < sizeOfMatrix )<br />delete [] matrix [ i ++ ];<br /><br /><br />}<br />heres the ouput:
enter the size of the matrix: 5
1 6 11 16 21
2 7 12 17 22
3 8 13 18 23
4 9 14 19 24
5 10 15 20 25
Press any key to continueGWILouisaxwzklaParticipantCan you give a definition of spiral matrix?
GWILouisaxwzklaParticipantCould try:
123456789101112131415161718192021222324252627282930<br />#include <br />#include <br />#define MAX 101<br />char * concat ( char s1[], char s2[], int maxlength );<br /><br />int main()<br />{<br />#define MAX 101<br />char s1 [ MAX ];<br />char s2 [ MAX ];<br /><br />printf("Enter the first string ");<br />gets(s1);<br />printf("Enter the second string ");<br />gets(s2);<br />printf("The combined string is: %s n", concat ( s1 , s2 , MAX ) );<br /><br /><br />return 0;<br />}<br /><br />char * concat ( char s1[], char s2[], int maxlength )<br />{<br /><br />if ( strlen ( s1 ) + strlen ( s2 ) > maxlength )<br />return s1;//stings too long , return first string as default<br />strcat ( s1 , s2 ); //stick s2 to the back of s1<br />return s1;<br />}GWILouisaxwzklaParticipantThis seems to work:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687<br /><br />#include <br />#include <br /><br />int main(void)<br />{<br />int choice;<br />int number;<br />float floatingPointNumber;<br />char a;<br />char b;<br />char c;<br /><br /><br />printf ( "please enter a choice nn" );<br />printf ( "A-print the square of the number n" );<br />printf ( "B- print the square root of the numbern" );<br />printf ( "C- print the cube of the number. n" );<br />printf ( "Q- Quit n" );<br />choice = getchar ();<br />getchar (); //get newline char<br /><br />while ( choice != 'Q' && choice != 'q' )<br />{ /*loop until user types the End of File */<br /><br />switch ( choice )<br />{<br /><br />case 'A':<br />case 'a':<br />printf ( "nEnter a number: n" );<br />scanf ( "%d", & number );<br />getchar (); //get newline char<br />number = number * number;<br />printf ( "Your answer is: %i n", number );<br />break;<br /><br />case 'B':<br />case 'b':<br />printf ( "nEnter a number: n" );<br />scanf( "%f", & floatingPointNumber );<br />getchar (); //get newline char<br />floatingPointNumber = sqrt ( floatingPointNumber );<br />printf ( "Your answer is: %f n" , floatingPointNumber );<br />break;<br /><br />case 'C':<br />case 'c':<br />printf ( "nEnter a number: n" );<br />scanf ( "%d", & number );<br />getchar (); //get newline char<br />number = number * number * number;<br />printf ( "Your answer is: %i n", number );<br />break;<br />case 'Q':<br />case 'q':<br />printf ( "goodbye .... n " );<br />break;<br /><br />default:<br />printf ( "n<hr class="bbcode_rule" />" );<br />printf ( "nIncorrect choice entered. ");<br />printf ( "n<hr class="bbcode_rule" />nn" );<br />printf ( "enter a choice: " );<br />break;<br />};/*end switch function*/<br />printf ( "nn" );<br />printf ( "please enter a choice nn" );<br />printf ( "A-print the square of the number n" );<br />printf ( "B- print the square root of the numbern" );<br />printf ( "C- print the cube of the number. nn" );<br />printf ( "Q- Quit n" );<br />choice = getchar ();<br />getchar (); //get newline char<br /><br />}/*end while function*/<br /><br />return 0;<br />}<br /><br /><br />GWILouisaxwzklaParticipantHeres a list of free compilers:
http://www.thefreecountry.com/compilers/cpp.shtml
I would suggest the Borland or Microsoft compilers. Second, is your application to be a Windows or DOS program?
GWILouisaxwzklaParticipantHeres a link on making static header files with VC++.
http://www.functionx.com/visualc/libraries/staticlib.htm
VC++ is Microsoft’s trademark name for their C++ compiler. It uses standard C++ grammar…
GWILouisaxwzklaParticipantThis version works with this file format:
A for loop is designed to
a.)run only if the condition is false
b.)run a set number of times
c.)run at least once
d.)run when there are no conditions
@
A while loop is designed toa.)run only if the condition is true
b.) run a set number of times
c.)run at least once
d.)run when there are no conditions
@123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657#include <stdio.h>#include <stdlib.h>int main ( void ){int questionNum;char questions [ 80 ];char c; /*variable to hold character input by user*/char choice[2]; /*create character array*/int i = 0; /*initialize counter i*/FILE * pFile;char ch;pFile = fopen ( "c:\programs\data2.txt" , "r" );if ( pFile == NULL ){perror ("FILE COULD BE OPEN");return 1;}ch = getc ( pFile );while ( ! feof ( pFile ) ){printf("n___________________n");printf("n Question n");printf("___________________nn");while ( ch != '@'){putchar ( ch );ch = getc ( pFile );}/*end else*/printf( "nnENTER YOUR ANSWER HERE: "); /*prompts user to input answer*/c = getchar ();getchar ();choice [ i ++ ] = c;ch = getc ( pFile );printf ( "n press any 'ENTER' for next Questions: ");}printf ( "n answers: n" );int j = 0;while ( j < i ){putchar ( choice [ j ] ) ;printf ( "n" );j ++;}return 0;}GWILouisaxwzklaParticipantWhat I might do is put a marker in between each question in the file so that one can be read at a time , like:
A for loop is designed to
a.)run only if the condition is false
b.)run a set number of times
c.)run at least once
d.)run when there are no conditions@
A while loop is designed to
a.)run only if the condition is true
b.) run a set number of times
c.)run at least once
d.)run when there are no conditionsso that you can read up to the ‘@’ character , stop and get the answer and then continue. You could make the while loop read one word at a time ( stopping when you read ‘@’ ) and then get the answer.
GWILouisaxwzklaParticipantheres a simpler version ( no driver function ). Seems to work fine – needs to be tested….
/****************************************************************
* File Name : c:programshelppermutations.cpp
* Date : August,1,2002
* Comments : new project
* Compiler/Assembler :
*
*
*
*
*
* Program Shell Generated At: 5:59:12 p.m.
=-=-=-=-=-=-=-=–=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/#include < iostream >
//#include < string.h >
//#include < conio.h >
//#include < math.h >
//#include < iomanip >
//#include < ctype.h >using namespace std;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@
void coinPermutations ( int flips , char * permutations );
//##################################################################################
//main function ******************************
int main ( )
{
int numberOfFlips;cout << "enter number of flips: ";
cin >> numberOfFlips;
cout << "permutations: " << endl;
char * permutations = new char [ numberOfFlips + 1 ];
permutations [ numberOfFlips ] = 0;
coinPermutations ( numberOfFlips – 1 , permutations );
delete [] permutations;return 0 ;
}/******************************* FUNCTION DEFINITION ******************************
Name : coinPermutatins
Parameters :face a(n) char
Returns: Void type
Comments:++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void coinPermutations ( int flips , char * permutations )
{if ( flips == 0 )
{
permutations [ flips ] = ‘t’;
cout << permutations << endl;
permutations [ flips ] = ‘h’;
cout << permutations << endl;
return;
}permutations [ flips ] = ‘t’;
coinPermutations ( flips – 1 , permutations ) ;
permutations [ flips ] = ‘h’;
coinPermutations ( flips – 1 , permutations );return;
}GWILouisaxwzklaParticipantWhat type of data structure are you to use ( linked list ? ).
- AuthorPosts