Free Essay

# Book Report

In:

Submitted By Tabsko
Words 1617
Pages 7
Selection statements
Selection is used to select which statements are to be performed next based on a condition being true or false.
Relational expressions
In the solution of many problems, different actions must be taken depending on the value of the data. The if statement in C I used to implement such s decision structure in its simplest form – that of selecting a statement to be executed only if a condition is satisfied.
Syntax:
if(condtion) statement executed if condition is true
When an executing program encounters the if statement, the condition is evaluated to determine its numerical value, which is then interpreted as either true or false. If the condition evaluates to any non-0 value (positive or negative), the condition is considered as a “true” condition and the statement following the if is executed; otherwise this statement is not executed.

Relational Operators In C Relational operator | Meaning | Example | < | Less than | age < 30 | > | Greater than | height > 6.2 | <= | Less than or equal to | taxable <= 200000 | >= | Greater than or equal to | temp >= 98.6 | == | Equal to | grade == 100 | != | Not equal to | number !=250 |

In creating relational expressions, the relational operators must be typed exactly as given in the above table. Thus, although the following relational expressions are all valid: age > 40 length <= 50 temp >= 98.6
3 < 4 flag == done day != 5
The following are invalid: length =< 50 /* operator out of order*/ 2.0 >> 3.3 /*invalid operator*/ flag = = done /*spaces are not allowed*/
Relational expressions are also known as conditions.
The if and if-else Statements
The simplest C selection statement is the one-way if statement having the syntax if ( expression ) statement;
In this construction, the statement following the if (expression ) is only executed if the expression has a non-0 value ( a true condition ). Examples of this statement are if ( age > 62 ) discount = .20;

if (grade > 70 ) ++passTotal;
In the example above the statement following the condition contained within the parenthesis is only executed if the relational expression is true; otherwise the statement following the condition is not executed at all.

#include <stdio.h> main() { int idNum; float miles; printf(“ Please type in car number and mileage :” ); scanf(“ %d %f”, &idNum, &miles); if( miles > 3000) printf(“ Car %d is over the limit.\n”, idNum); printf(“. . .end of program output. . .\n”); getch(); }
#include <stdio.h> main() { int idNum; float miles; printf(“ Please type in car number and mileage :” ); scanf(“ %d %f”, &idNum, &miles); if( miles > 3000) printf(“ Car %d is over the limit.\n”, idNum); printf(“. . .end of program output. . .\n”); getch(); }

Compound statements
Although only a single statement is permitted in an if statement, this statement can be a single compound statement. A compound statement is one or more statements contained between braces as shown below:
{
statement1; statement2; statement3;
}
The use of braces to enclose a set of individual statements creates a single block of statements, which may be used anywhere in a C program in place of a single statement. The general syntax of a compound within a one way if statement is:

if (expression)
{
statement1; statement2; .
.
.
}

The if-else Statement
The if-else statement directs the computer to select a sequence of one or more instructions based on the result of a comparison. The commonly used form of the if-else statement is: if (expression) statement1; else statement2;
#include <stdio.h> main() { int a=0; printf(“enter your age : ”); scanf(“%i”, &a); if(a >= 21 ){ printf(“You are an adult.\n”); else printf(“You are a teenager “); printf(“end. . .”); getch(); }

#include <stdio.h> main() { int a=0; printf(“enter your age : ”); scanf(“%i”, &a); if(a >= 21 ){ printf(“You are an adult.\n”); else printf(“You are a teenager “); printf(“end. . .”); getch(); }

The expression is evaluated first. If the value of the expression is non-0, which corresponds to the expression being true, statement1 is executed. If the value is 0 which corresponds to the expression being false the statement2 after the reserved word else is executed. Thus, one of the two statements either statement1 or statement2 is always executed depending on the value of the tested expression.

The if-else Chain
Including one or more if-else statements within an if or if-else statement is referred to as nested if statements. if (expression1) statement1; else if(expression2) statement2; else if(expression3) statement3;
#include <stdio.h> main() { int grade=0; printf(“enter your grade : ”); scanf(“%i”, &grade); if( grade >= 100 ){ printf(“Excellent.\n”); else if(grade >= 90 ) printf(“Good job!\n “); else if(grade >= 80 ) printf(“Fair!\n “); else printf(“Sorry! You failed!”); printf(“end. . .”); getch(); }

#include <stdio.h> main() { int grade=0; printf(“enter your grade : ”); scanf(“%i”, &grade); if( grade >= 100 ){ printf(“Excellent.\n”); else if(grade >= 90 ) printf(“Good job!\n “); else if(grade >= 80 ) printf(“Fair!\n “); else printf(“Sorry! You failed!”); printf(“end. . .”); getch(); }

The construction is called an if-else chain, and is used extensively in many programming problems. In this construction, each condition is evaluated in order, and if any condition is true, the corresponding statement is executed and all further processing of the chain stops. Thus the final else statement is only executed if none of the previous conditions are satisfied. This serves as a default or catch-all case that is useful for detecting an impossible or error condition.

The switch statement
A switch statement is a specialized selection statement that can be used in place of an if-else chain where exact equality to one or more integer constants is required. Such cases occur with some regularity in real-world applications.
The main advantages of using a switch statement are to avoid using the equality operator, ==, avoids braces needed for compound statements internal to an if-else chain, and frequently results in simpler code. The general form of a switch statement is switch( integer_expression)
{
case value1: statement1; statement2; break; case value2: statement3; statement4; break; case value3: statement5; statement6; break; default: statement5;
}
In the syntax above the switch statement uses for new keywords: switch, case, default and break.
The keyword switch identifies the start of the switch statement. The integer_expression in parentheses following this word is evaluated first. The integer value of the expression is then compared to each of the values listed after the keyword case contained within the compound statement. A compilation error occurs if any of these values are not integer constants or variables.
The keyword case identifies the values that will be compared to the value of the switch expression. This expression’s value is compared to each of these case values in the order that these values are listed until a match is found. When a match occurs, execution begins with the statement immediately following the match.
Any number of case labels may be contained within a switch statement, in any order. If the value expression does not match any of the case values, however no statement is executed unless the keyword default is encountered. The word default is optional and operates the same as the last else in an if-else chain. If the value of the expression does not match any of these case values, program execution begins with the statement following the word default.
Once an entry point has been located by the switch statement, no further case evaluations are done; this means that unless a break statement is encountered, all statements that follow, until the closing brace of the switch statement, will be executed. This is the reason for the break statement, which identifies the end of a particular case and causes an immediate exit from the switch statement. Thus, just as the word case identifies possible starting points in the compound statement, the break statement determines termination points. If the break statements are omitted, all cases following the matching case value, including the default case, are executed.

#include <stdio.h> main() { int choice; float num1, num2; printf(“please type in two numbers : ”); scanf(“%f %f ”, &num1, &num2); printf(“enter your code:”); printf(“\n 1 for addition”); printf(“\n2 for subtraction”); printf(“\n3 for multiplication”); scanf(“%i”, &choice); switch( choice)
{
case 1: printf(“the sum of the 2 numbers entered is %f”, num1+num2); break; case 2: printf(“the difference of the 2 numbers entered is %f”, num1-num2); break; case 3: printf(“the product of the 2 numbers entered is %f”, num1*num2); break; getch();
}

#include <stdio.h> main() { int choice; float num1, num2; printf(“please type in two numbers : ”); scanf(“%f %f ”, &num1, &num2); printf(“enter your code:”); printf(“\n 1 for addition”); printf(“\n2 for subtraction”); printf(“\n3 for multiplication”); scanf(“%i”, &choice); switch( choice)
{
case 1: printf(“the sum of the 2 numbers entered is %f”, num1+num2); break; case 2: printf(“the difference of the 2 numbers entered is %f”, num1-num2); break; case 3: printf(“the product of the 2 numbers entered is %f”, num1*num2); break; getch();
}

When constructing a switch case statement, multiple case values can be stacked together, and the default label is always optional. switch (number)
{
case 1: printf(“have a good morning!\n”); break; case 2: printf(“have ahappy day!\n”); break; case3: case4: case5: printf(“have a nice nice evening!\n”);
}
Assuming the choice is a character variable, the following switch statement is valid: switch (choice)
{
case ‘a’: case ‘b’: printf(“you enter a letter!\n”); break; default: printf(“ it’s not a letter!\n);
}

### Similar Documents

Free Essay

#### Writing a Book Report

...Writing a Book Report Summary: This resource discusses book reports and how to write them. Contributors: Purdue OWL (owl.English.purdue.edu) Book reports are informative reports that discuss a book from an objective stance. They are similar to book reviews but focus more on a summary of the work than an evaluation of it. Book reports commonly describe what happens in a work; their focus is primarily on giving an account of the major plot, characters, thesis, and/or main idea of the work. Most often, book reports range from 250 to 500 words. Before You Read Before you begin to read, consider what types of things you will need to write your book report. First, you will need to get some basic information from the book: • Author • Title • Publisher location, name of publisher, year published • Number of Pages You can either begin your report with some sort of citation, or you can incorporate some of these items into the report itself. Next, try to answer the following questions to get you started thinking about the book: • Author: Who is the author? Have you read any other works by this author? • Genre: What type of book is this: fiction, nonfiction, biography, etc.? What types of people would like to read this kind of book? Do you typically read these kinds of books? Do you like them? • Title: What does the title do for you? Does it spark your interest? Does it fit well with the text of the book? • Pictures/Book Jacket/Cover/Printing:...

Words: 645 - Pages: 3

Free Essay

#### Book Report Guidline

...Book Report Guidelines You must choose one out of the two books listed below for your book report. The book report is due on November 5th, 1 pm and must be typed, ten pages long (double spaced) with font size no larger than 11. You must email me the book report by this date. Books: 1. What Has Government Done to our Money? By Murray Rothbard. Amazon link: http://www.amazon.com/What-Has-Government-Done-Money/dp/146997178X/ref=sr_1_1?ie=UTF8&qid=1378217153&sr=8-1&keywords=what+has+government+done+to+our+money Free PDF: http://mises.org/books/whathasgovernmentdone.pdf 2. The Federal Reserve and the Financial Crisis. By Ben Bernanke Amazon link: http://www.amazon.com/The-Federal-Reserve-Financial-Crisis/dp/0691158738/ref=sr_1_1?ie=UTF8&qid=1378217165&sr=8-1&keywords=ben+bernanke For the book report, you must: 1. Read the book (!) 2. Write a short introduction providing an overview of the book, its author and the main themes.(1 page) 3. Summarize the main arguments in the book. (about 4 pages) 4. Write an analysis of what you perceive to be the strengths and weaknesses in the author’s arguments from the point of view of economics. You should be able to utilize economic concepts and theories that we have studied in class over the semester to do this. I will grade you in this section based upon your ability to present a point of view (a perceived strength or weakness) and cogently defend it using an (economic) argument. (about 5 pages) ...

Words: 544 - Pages: 3

...Term Paper/Book Review 11/16/15 Magnificent Masquerade, by Charles Keats, 1964 Summary of the McKesson & Robbins Scandal Before the scandals of Enron and WorldCom, which are considered the greatest accounting scandals of the 21st century, the most notorious & influential accounting scandal of frauds in the 20th century, or in American history, is the McKesson & Robbins scandal of 1939. In the early fall of 1926, Philip Musica, assuming the name of F. Donald Coster, took control of the pharmaceutical company McKesson & Robbins by using his bootlegging profits from Girard & Co. to issue a merger between the two pharmaceutical companies, and he became McKesson & Robbins’ president. From his experience with Girard, Coster “knew how auditors functioned, they were interested in account books & supporting documents” (Keats, 71) & he knew how to mislead auditors. Coster conducted fraudulent transactions for McKesson & Robbins by continuing to manufacture (fraud) documents of inventories & accounts receivable such as, “order slips, shipping records, duplicate invoices, & other bookkeeping evidences of sale” (Keats, 72). Julian Thompson, Coster’s top assistant, finally uncovered the fraud scandal in 1938 through his suspicions of the existence of the McKesson & Robbins’ Canadian subsidiary’s warehouse. Coster was convicted of “violating Section 32 of the Securities Act of 1934: filing false financial information with the SEC” (Keats...

Words: 2688 - Pages: 11

#### 10 Minute Mindfulness Book Report

...The book I chose to read was “10-Minute Mindfulness” by S.J. Scott & Barrie Davenport. I chose this book for assistance in providing me with the tools and instructions to be more mindful and positive in my everyday life. This is something I think each and every one of us can benefit from, especially in todays fast paced world. How to reclaim your family This book describes several simple habits (71 to be exact) to assist in practicing mindfulness even with all the hussle and bussle of our daily lives. Another thing I really liked about this book is how it describes how to implement each habit into our daily activities we already do. The authors really made it easy for me to picture in my mind, integrating these mindful habits on a day-to-day...

Words: 585 - Pages: 3

Free Essay

#### How to Write a Book Report

Words: 1197 - Pages: 5

#### Book Report Bilbo Baggins

...At the start, he was not a very well known man, except by his family, his friends, and his neighbors, and he pretty much just kept to himself. He states a lot throughout the book that he’d much rather be at home. But as the book takes its pace, Bilbo starts to change. He learns humility, kindness, and bravery. He learns to respect the dwarves, along with the countless other people he meets on the journey. He tries to help everyone to the best of his ability. I think it’s because he likes to see people happy; I think it reminds him of his...

Words: 1985 - Pages: 8

Free Essay

#### Stealing Buddha’s Dinner Book Report

...While preparing for this book report I found an interview posted online with Bich Minh Nguyen. She said that her reasoning behind writing Stealing Buddha’s Dinner was because her childhood was defined by a feeling of isolation. She also said “It does seem easier now for Asian immigrants to be themselves; a good deal of progress has been made since the early 1980s. At the same time I think the negative idea of the “foreigner” still persists—not just for Asian immigrants, but for many nonwhite immigrants and their descendants, people who continue to be asked: “Where are you from? I mean, where are you really from?”” My generalization of this book is that Bich struggled during her childhood simply to “fit in.” Stealing Buddha’s Dinner reminds me so much of The Mixed-Up Chameleon by Eric Carle. (I used this example in a previous assignment but I feel like it fits so well into the main theme of this course.) Bich is fixated with the idea of trying to assimilate herself into the American culture. In The Mixed-Up Chameleon, the chameleon (Bich) sees all of the animals at the zoo and (her peers) wants to “be like them” in some way. She goes to great lengths to eat American food and take an American name and dress the way other Americans do. I see many similarities between the feelings of lonely segregation that Bich felt and those of the students discussed in the case studies throughout our textbook. Works Cited Nguyen, B. M. (2008). Stealing buddha's dinner: A memoir. Penguin...

Words: 280 - Pages: 2

#### Not Sure

Words: 2409 - Pages: 10

...|Unit Title: |Unit No:1 |Date Issued | |Business Environment | |Week beginning 11/02/13 | |Student Name |Student ID |Due Date – 03/06/13 | |Lecturer Name: Ibrahim kevin, Sujata,& Issac |Internal Verifier Name | | |Mr. M. Azam | Rules and regulations: |Plagiarism is presenting somebody else’s work as your own. It includes: copying information directly from the Web or books without | |referencing the material; submitting joint coursework as an individual effort; copying another student’s coursework; stealing coursework from| |another student and submitting it as your own work. Suspected plagiarism will be investigated and if found to have occurred will be dealt | |with according to the procedures set down by the College. Please see your student handbook for further details of what is / isn’t plagiarism.| Coursework Regulations   1. Submission of coursework must be undertaken according to the relevant procedure – whether online or paper-based. Lecturers will give information as to which procedure must be followed, and details of submission procedures and penalty fees can be obtained...

Words: 2134 - Pages: 9

Free Essay

#### Staying on Course

...STAYING ON COURSE Kendra Harvey Pre 100 sect. 7116 October 12, 2013 Kendra Harvey Pre 100 Sect. 7116 12 October 2013 STAYING ON COURSE Enrolling in college at 26 years old was very intimidating to me. Although I graduated from high school, I have a real problem with self confidence. Keeping up with my classmates from high school on social media sites, I became discouraged and depressed from seeing how successful some of them had become. I often wondered why I haven’t become successful. Why was I made to be a failure? Then it dawned on me that I, myself was my own problem. At different points in my life I’ve often given up when I was faced with a challenge. I always took interest in the healthcare field, and I pursued and completed a certification in nursing. When certain circumstances caused for me to have to go back to school to recertify, instead of pressing on I choose defeat. My greatest obstacles now are my children, for I don’t have a strong support system and because of this I have allowed myself to be defeated by other obstacles in life. When I got into college, my biggest challenge was staying focused and motivated. I continued to stay out late, I would put off assignments until the last minute, I did cram study sessions, I was lazy all the time and couldn’t concentrate, and I missed classes and fell behind on home assignments. This caused a major problem for me like receiving failing grades. I blamed everything and...

Words: 890 - Pages: 4

#### International Relations

...Brunel Business School Bachelor of Science TITLE ENTREPRENEURSHIP & MARKETING IN BUSINESS MODULE CODE MG2049 Written Coursework: Deadline (12.00 noon, UK time) on Blackboard Learn. The learning outcomes for this module are as follows: * 1. Critically discuss the theories surrounding entrepreneurship and business ventures and how they relate to the global business environment. 2. Identify the impact that corporate communications have on internal and external audiences and their role in the development of integrated marketing communications. 3. Critically analyse issues around new business formation and growth of national and multinational enterprises. 4. Evaluate the application of theories in entrepreneurship and marketing communications ------------------------------------------------- The coursework comprises two elements which include the groupwork and individual essay (100%). The groupwork element attracts formative assessment while the individual element attracts summative assessment (3000 words). The individual element poses questions on your experience as regards the groupwork element and the ‘entrepreneurial journey’ of well-known enterprises. In order to benefit from the experiential learning inherent in the groupwork, it is important that you set about forming groups as early...

Words: 1335 - Pages: 6

Free Essay

#### Book Report

... Vytautas Didysis gimnasium Form IIIc Laurita Drankinaitė Book report John Grogan Marley & Me John Grogan He was born in the Motor City, Detroit, Michigan, on March 20, 1957. He got into writing by default because He was so bad at everything else. Algebra, geometry, French, chemistry, physics -- they all escaped me. But writing, now there was a subject he could have some fun with. By eighth grade He was penning parodies of the nuns just for fun, and in high school, besides writing for the school newspaper, He started an underground tabloid, which earned me a celebrated trip to the principal's office.  From there it was on to Central Michigan University, where He earned the princely sum of twenty-five cents per column inch writing for the campus newspaper while slugging away at a double major in journalism and English. He’s first full-time writing job came immediately upon graduation in 1979 when He was hired as a police reporter for the small and laughably lackluster Herald-Palladium in the Michigan harbor town of St. Joseph. He rode all night with cops, photographed murder victims, picked my way through smoldering house fires and sat over coffee with grieving parents. He also summoned the courage to ask out a willowy and tart-tongued reporter on the staff whose name was Jenny and who eventually would become my soul mate, lover, and wife, in that order. About the book This book tells a real story about a journalist John Grogan and his family's...

Words: 584 - Pages: 3

Free Essay

#### Book Report

...stress, such as circus trapeze artists. Wolfe states that President Dwight D. Eisenhower, however, insisted on pilots, even though the first crew members would not actually fly the spacecraft. When Gus Grissom lands at sea and exits his space capsule, saving the capsule seems more important to the recovery team than saving the pilot because of the value of the data. Wolfe contrasts the Seven with the Edwards test pilots, among whom was Chuck Yeager, who was shut out of the astronaut program after NASA officials decided to use college-degreed pilots, not ones who gained their commissions as enlisted men, such as participants in the USAAF Flying Sergeants Program in World War II. Chuck Yeager spent time with Tom Wolfe explaining accident reports "that Wolfe kept getting all wrong." Publishing insiders say these sessions between Wolfe and Yeager led Wolfe...

Words: 411 - Pages: 2

#### Book Report

...BOOOK REPORT: HARRY POTTER AND THE PRISONER OF AZKABAN SUBMITTED BY: JOHN JAYROME V. HERNANDEZ Submitted to:ms maricel marquez ENGLISH BOOK REPORT: I. HARRY POTTER and the Prisoner of Azkaban II. AUTHOR: Joanne K. Rowling III. Date: A. Started Reading: December 3, 2011 B. Finish Reading: December 28, 2011 IV. VOCABULARY WORDS 1.legal- 2.injustice- 3. Muggle- 4. demeanor- 5. Dementors- 6.staunch- 7.ennui- 8.dreadful- 9. xenophobia,- 10.paranomia-mental illness 11.deluted-weakened 12.evove-develope 13.engulfed-surrounded 14.hostage-prisoner 15.insigne-badge V. POINT OF VIEW - Sirius Black has escaped from Azkaban, the wizarding prison. In response, the Ministry of Magic sends Dementors, a race of dreadful creatures which either wear or are made of Black Cloaks, to guard Hogwarts and their Emotion Eating powers seem to affect Harry especially. Remus Lupin, meanwhile, makes his first appearance, taking on thedreade Gryffindor d Defense Against the Dark Arts post. The book's popularity may be partially due to the introductions of Sirius and Lupin, considered by some fans to be two of the coolest characters in the series. It also marks the point where the books started to become more serialized with each ending setting up the next one. VI. THEME The Injustice of Legal Systems This book makes several moral attacks on a legal system that is controlled by men like Lucius Malfoy who bully people until he gets his way...

Words: 2662 - Pages: 11