assigment-muhamad hazim bin ahmad izuddin

Upload: muhamad-hazim

Post on 03-Mar-2016

14 views

Category:

Documents


0 download

DESCRIPTION

Assigment-muhamad Hazim Bin Ahmad Izuddin

TRANSCRIPT

1.Who is Written C++ ? Bjarne stroustrup

His history: Bjarne:Like many high-school students, I didnt have a clue what to do after high-school. I read up on various possible careers, and dreamt of becoming an architect, a historian, a sociologist, an engineer, a psychologist, and more. My family was encouraging me to choose something with a clear job and career path after my studies, such as a business major.In the end, I chose mathematics with computer science because mathematics was one of my favorite topics in high school and I was under the mistaken impression that computer science was a form of applied mathematics. I had never seen a computer in those days computers were rare and hidden away in dedicated machine rooms. I chose mathematics because it would make a good career and a lousy hobby over my second choice, history, which I thought would make a lousy career and a great hobby. To this day, I have more history books than computing books, and Im part-way through a book on the history of England in the 14thcentury.I was right that mathematics would make a great career, but only because I had been completely mistaken about computer science. It turned out to be far more interesting, practical, and useful than I had imagined. Also, real applied mathematics would probably have been beyond my limited talents in that direction. I ended up doing pure math and programming. So, I was signed up for computer science from the start, but what really sparked my interest was the introductory computer science course.2. state staements below and give an example application in program.

a. GOTO: A statement label is meaningful only to agotostatement; otherwise, statement labels are ignored. Labels cannot be redeclared.It is good programming style to use thebreak,continue, andreturnstatements instead of thegotostatement whenever possible. However, because thebreakstatement exits from only one level of a loop, you might have to use agotostatement to exit a deeply nested loop.For more information about labels and thegotostatement, seeLabeled StatementsandUsing Labels with the goto Statement.In this example, agotostatement transfers control to the point labeledstopwheniequals 3.// goto_statement.cpp#include int main(){ int i, j;

for ( i = 0; i < 10; i++ ) { printf_s( "Outer loop executing. i = %d\n", i ); for ( j = 0; j < 2; j++ ) { printf_s( " Inner loop executing. j = %d\n", j ); if ( i == 3 ) goto stop; } }

// This message does not print: printf_s( "Loop exited. i = %d\n", i );

stop: printf_s( "Jumped to stop. i = %d\n", i );

b. While: The do-while loopA very similar loop is the do-while loop, whose syntax is:

do statement while (condition);

It behaves like a while-loop, except thatconditionis evaluated after the execution ofstatementinstead of before, guaranteeing at least one execution ofstatement, even ifconditionis never fulfilled. For example, the following example program echoes any text the user introduces until the user enters goodbye:

1234567891011121314// echo machine#include #include using namespace std;

int main (){ string str; do { cout =18){ printf("you can vote");}else{ printf("you are not eligible for voting");}What did happen in above example?The above example needs user input to determine the age of the user and based on that it is displaying the message.How if-else statement works in C program?As you have already seen in above program that when condition given in if is true then the set of statements enclosed in if body will execute otherwise (when condition is false) the else statements gets executed.