Sunday, July 12, 2009

Write a simple C/C++ program which defines an array of five elements, then using pointer to display the addres

Write a simple C/C++ program which defines an array of five elements, then using pointer to display the addresses of all elements of the array.

Write a simple C/C++ program which defines an array of five elements, then using pointer to display the addres
/* Tolga's C code */


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


int main(){


int i=0, arr[5];





for(;i%26lt;5;i++)


printf("Address of the element #%d is %p\n",i,(arr+i));


return 0;}
Reply:This looks like a command instead of a question. I don't even see a question mark anywhere! You wouldn't be asking people to do your homework now, would you? You're not that kind of person I'm sure.


Please help!!! C++ user defined funtions?

im trying to put some functions into my code. i want to create 2 functions in my switch statement one for case A and one for case B but im having trouble with my variables and the user input here is my code im open to any suggestions








#include %26lt;iostream%26gt;





using namespace std;





int main()


{





char choice; // variable for selection


int quantity; // variable for quantity of numbers


int num1; // variable for option A numbers


int num2; // variable for option B numbers


int largest; // variable for largest number


int smallest; // variable for smallest number





do


{ // beginning of do while loop





cout %26lt;%26lt; " Please choose one of the following options" %26lt;%26lt; endl; // instructions telling user what to enter





cout %26lt;%26lt; " A. - find the largest number with a known quantity of numbers" %26lt;%26lt; endl; //


cout %26lt;%26lt; " B. - Find the smallest number with an unknown quantity of numbers" %26lt;%26lt; endl; // display menu options to user


cout %26lt;%26lt; " C. - Quit" %26lt;%26lt; endl; //





cout %26lt;%26lt; " Please enter your choice: - "; //


cin %26gt;%26gt; choice; // ask user for input


cout %26lt;%26lt; endl; //





switch (choice)


{ // beginning of switch statement





case 'a': // case for when user selects option A


case 'A':





cout %26lt;%26lt; " A. - find the largest number with a known quantity of numbers" %26lt;%26lt; endl;


cout %26lt;%26lt; " Please enter the total quantity of numbers you would like to use: ";


cin %26gt;%26gt; quantity;





for (quantity;quantity %26gt; 0;quantity--)


{





cout %26lt;%26lt; " please enter a number - ";


cin %26gt;%26gt; largest;


cout %26lt;%26lt; endl;





for (quantity;quantity %26gt; 1;quantity--)


{


cout %26lt;%26lt; " please enter a number - ";


cin %26gt;%26gt; num1;


cout %26lt;%26lt; endl;





if (largest %26lt;= num1)


largest = num1;


}





}





cout %26lt;%26lt; " the largest number you entered is (" %26lt;%26lt; largest %26lt;%26lt; ")" %26lt;%26lt; endl;





break;





case 'b': // case for when user selects option B


case 'B':





cout %26lt;%26lt; " B. - Find the smallest number with an unknown quantity of numbers" %26lt;%26lt; endl;





cout %26lt;%26lt; " enter your first number - ";


cin %26gt;%26gt; num2;


cout %26lt;%26lt; endl;





smallest = num2;





cout %26lt;%26lt; " to get result and return to main menu enter (-99) for your number" %26lt;%26lt; endl;





while (num2 != -99)


{





cout %26lt;%26lt; " please enter another number - ";


cin %26gt;%26gt; num2;


cout %26lt;%26lt; endl;





if (num2 != -99)


if (num2 %26lt; smallest)


smallest = num2;


}





cout %26lt;%26lt; " the smallest number you entered is (" %26lt;%26lt; smallest %26lt;%26lt; ")" %26lt;%26lt; endl;





break;





case 'c': // case for when user selects to exit the program


case 'C':





exit('c');





default: // case for when user tries to select and option other than a, A, b, B, c, or C





cout %26lt;%26lt; " the letter you entered is not valid" %26lt;%26lt; endl;





} // end of switch statement





} while (choice != 'c'); // end of do while loop





return 0;





}

Please help!!! C++ user defined funtions?
create 2 functions called


void largest()


{


do all your things here;


returns nothing;


}


void smallest()


{


do all your things here;


returns nothing;


}
Reply:I see a problem with this section of code:


You are reading in a value for largest. That should only change when num1 is larger than largest's current value.





for (quantity;quantity %26gt; 0;quantity--)


{





cout %26lt;%26lt; " please enter a number - ";


cin %26gt;%26gt; largest;


cout %26lt;%26lt; endl;





for (quantity;quantity %26gt; 1;quantity--)


{


cout %26lt;%26lt; " please enter a number - ";


cin %26gt;%26gt; num1;


cout %26lt;%26lt; endl;





if (largest %26lt;= num1)


largest = num1;


}





}


C++ user defined arrays?

Ok, last week my problem was getting two 3x3 matrices (whose elements were defined by the user) multiplied, and thanks to the help from here I got it figured out. This week, we're just supposed to stretch this out a bit, by letting the user state the size of his matrices. I thought it would be as simple as removing the 3 from:





const int row = 3;


const int column =3;





and just using a cin to let the user define these variables, but this small change spat back 22 errors at me. I take it you can't do this with an array, but then how do you let a user define it's size?





a snippit:


int main( )


{





const int row;


const int column;





int i, j;





cout %26lt;%26lt;"How many rows will this matrix have?" %26lt;%26lt; endl;


cin%26gt;%26gt;row;





cout %26lt;%26lt;"How many columns will this matrix have?" %26lt;%26lt; endl;


cin%26gt;%26gt;column;





cout %26lt;%26lt; "FIRST MATRIX (A):" %26lt;%26lt; endl;


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


for (j = 0; j %26lt; column; j++)


{





cout %26lt;%26lt; "Enter value for row " %26lt;%26lt; i+1 %26lt;%26lt; " column " %26lt;%26lt; j+1 %26lt;%26lt; ": " %26lt;%26lt; endl;


cin %26gt;%26gt; matrixOne[i][j];


.


.


.

C++ user defined arrays?
Something like this should do








int main( )


{


int row;


int column;





int i, j;





cout %26lt;%26lt;"How many rows will this matrix have?" %26lt;%26lt; endl;


cin%26gt;%26gt;row;





cout %26lt;%26lt;"How many columns will this matrix have?" %26lt;%26lt; endl;


cin%26gt;%26gt;column;





int matrix[row][column];
Reply:You can't cin %26gt;%26gt; row; or cin %26gt;%26gt; column; if it defined as a const.


Remove "const" before int row and int column and it should start working.

artificial flowers

2 simple programs in C++. & also a basic doubt. please make it simple as i am a beginner.?

C++ : should main() b defined compulsarily?can it b inside a class? also in array c[]={1,2,3} what will be c[1]?


define a class to represent a book in a library with datamembers: book number, Book Name, Author, Publisher,Price, no. of copies, No.ofcopies issued.


member function : (i) to assign initial values (ii) issues book after checking for its availability.


(iii) to return a book. (iv) to display book information.





Define a class ELECTION with the following speciations. with a suitable main() fumction also to declare 3 objects of ELECTION type %26amp; find the winner %26amp; display the details.


private members: candidate_name, party, votes_received


public memberfumctions: enterdetails()-input data


Display()- to display winner


winner()- to return details of the winner through the object after comparing the votes received by the 3 candidates.

2 simple programs in C++. %26amp; also a basic doubt. please make it simple as i am a beginner.?
"C++ : should main() b defined compulsarily"





Not sure what you mean.





"can it b inside a class?"





Not in C++, no it must be global. You can do this though:





int main(int argc, char **argv)


{


return Program.Main(argc, argv);


}





static class Program


{


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


{


return 0;


}


}





"also in array c[]={1,2,3} what will be c[1]?"





Arrays in C are 0-based, so c[1] is the second element, in this case the value is 2.





The rest of your questions sound like homework and I'm not going to ruin your learning experience.


Health Care Proffesionals! Definition of Med/Surge & C-Diff?

I am a nursing student and would like to know your definition of Med/Surge and the responsibilities that are entailed. Also, if you would please define C-Diff, I would appreciate it.

Health Care Proffesionals! Definition of Med/Surge %26amp; C-Diff?
Med/Surg is basically a general medical area, not specializing in anything specific. Any medical or surgical type problems. Common in small hospitals to have a med/surg floor instead of many speciality floors.





C-Diff or CLOSTRIDIUM DIFFICILE


Clostridium (klo-STRID-e-um) difficile (DIF-ih-sil) is a type of bacteria (bak-TEER-e-uh) (germ) that may cause illness in people and animals. Clostridium difficile is also called C. diff. C. diff may live for long periods of time on many surfaces. It may live for months to years without dying, even when those surfaces are cleaned. It also lives in soil and water. C. diff grows and spreads quickly in hospitals, long term care centers, and day care centers. It is unknown how long you may have C. diff in your body before getting sick. Most of the time, you will not get sick from C. diff because your body will protect you from the bacteria. Older adults, babies, and people who have other medical conditions may get very sick from C. diff.





Hope this all clears things up for you!
Reply:you should not expect Yahoo Answer to substitute hard work and real library search.





I would not like to be your patient someday in a hopsital ....
Reply:Dear Steve,





You're lucky I am in a good mood. Normally I would tell you to look up the answer like a good little nursing student would. Fortunately, I am feeling generous. So I am going to tell you the answer. Hehehe.





First, Medical / Surgical Nursing is a broad specialty. It includes caring for the adult patient with any medical issue or any adult surgical patient. It varies greatly. Most med-surg units include adults from age 18 to 100 something. They typically do not exclude the Geriatric population although Geriatrics is a Nursing Speciality on its own. Medical issues can range from Cellulitis, to Diabetic Ketoacidosis, to Diverticulitis, to Sepsis, to Liver Cirrhosis, to Congestive Heart Failure.... and much much more. Surgical patients can include those who have had elective plastic surgery such as Abdominoplasty, to ORIF (open reduction and internal fixation) of a Hip Fracture, to a CABG (coronary artery bypass graft).... and much much more....





2) C-Diff is the shortened named for Clostridium difficile. C Diff is a bacterial infection, usually of the GI tract. It is mostly thought to be a nosocomial infection ( or "hospital bug" ). It presents as loose, watery, frequent diarrhea with a very foul smell. The patient may also exhibit fever, chills, and weakness and occasionally nausea/vomiting and decreased appetite. It is sometimes spread through the fecal-oral route. Commonly spread from patient to patient through the hands of health care workers. Patients who test positive for the C diff organism should be isolated from other patients as soon as possible, but they may be cohorted with others who tested positive. Each insititution may have a different policy as to when to isolate a suspected case of C diff. Some may require the nurse to wait for positive lab results. Others may allow it immediately. In the event that total isolation is not possible, and there is no other with Cdiff to cohort... the nurse should avoid cohorting with Surgical patients or those who are immunocompromised, such as those on Chemotherapy for Cancer, or the extreme Elderly. Careful and thorough handwashing must be practiced to limit the transmission of the bug. The nurse should instruct the support staff on the importance of isolating the patient and careful handwashing. Also the nurse should teach the patient basic hand hygeine, and explain why they are in a private room. Visitors also need to be instructed as to avoid touching items in the room and avoid touching any body fluids.





Good Luck,





Angie R.N.


Let V be the set of all real-valued continuous functions. If f and g are in V, define f+g by (f+g)(t) =?

Let V be the set of all real-valued continuous functions. If f and g are in V, define f+g by (f+g)(t) = f(t)+g(t). If f is in V, define c.f by (c.f)(t) = cf(t). Prove that V is a vector space, which is denoted by C(-infinity, infinity).





By definition, a vector space is a set V of elements on which we have two operations '+' and '.' defined with the following properties:





a) If u and v are any elements in V, then u+v is in V. (We say that V is closed under the operation '+')





b) If u is any element in V and c is any real number, then c.u is in V.( i.e., V is closed under the operation '.')





Here, the operation '+' is vector addition and the operation '.' is scalar multiplication.

Let V be the set of all real-valued continuous functions. If f and g are in V, define f+g by (f+g)(t) =?
V is not only a vector space, it is, in fact, a linear vector space!





To verify the requirements,





a) prove that if f,g are real, continuous, the f+g is also real, continuous.





The reals are closed under addition, and continuity can be proven from epsilon-delta arguments.





b) if u is real, continuous, and c a scalar in R, you only need to prove that cu is real, and continuous. R is closed under multiplication, and the cont of cu, again, from definition, some epsilon-delta argument.


Find the coordinates of the turning points of the curve C, defined by y = x^3 - x?

turning points occur where there is a local max or min





y'=3x^2 -1





3x^2-1=0


3x^2=1


x^2=1/3





x=1/sqrt3, -1/sqrt3





plug this x value into the original equation to find the y value and that is your turning point.

800flowers.com