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

Premium Essay

Dear Dumb Diary Book Report

...This week, I am going to tell you about a funny book I am currently reading. The title of the book is Dear Dumb Diary, Let's pretend this never happened. When I first opened the book it was like light shining towards my face (Sarcasm) When you first start to read it, it makes you want to flip into the next page when you are not even finished with the first page. The book made me wonder why Angeline was being so nice to Jamie after she was so mean to her all of the time. I enjoyed predicting what would happen next when weird things happened. Angeline and Jamie are two interesting characters because they are mean in different ways. One day they're nice to each other, and another day they're mean. I also enjoyed the illustrations because they...

Words: 355 - Pages: 2

Premium Essay

Magnificent Masquerade Book Report

...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

Premium Essay

No More Perfect Kids Book Report

...Here is a 10 great Summer books to read while watching your children play. The books I have chosen are a variety and not a specific to one genre. So here are they 10 books I have chosen for Reading during the Summer. No More Perfect Kids by Jill Savage & Kathy Koch, PhD ~In No More Perfect Kids, Jill Savage and Kathy Koch equip us with the tools and perspective to: Identify and remove the Perfection Infection from our parenting Release our children from unrealistic expectations Answer the questions our kids are silently asking in a way that gives them the courage and freedom to be themselves Meet the needs of our children, including those with special needs Kill Devil by Mike Dellosso ~Jed Patrick is convinced he’s doing all it takes to keep...

Words: 1741 - Pages: 7

Premium Essay

Hearing Impaired Children Book Report

...The page then goes on to talk about how the auditory system works, and how we use decibels and hertz to measure sound. E: The book mentions how some children can be mistaken as being stubborn, disobedient, or even lazy before they are diagnosed with having a hearing impairment. I think it is important, as future teachers, that we are looking out for children who may be hearing impaired but not yet diagnosed because we wouldn't want mistake a hearing impaired child for a disobedient or lazy child. E: I really liked reading this page because it made me think of the Pre-K students that I used to watch at the preschool I worked at. There were some students that really had a problem listening to what I had to say, and I used to get so annoyed that they wouldn't listen. After reading this page, I am now wondering if any of them may have had a hearing impairment or some...

Words: 796 - Pages: 4

Premium Essay

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

...How to Write a Book Review The purpose of a book review in the most basic sense is to convey to the reader what the book is about and whether it is worth reading or not. A good book review expands upon these two areas. When describing the book the following should be included: • The vital statistics: the title, author, publisher, price, paperback or hardback, length, illustrations, if it has been translated • The type of material: fiction, nonfiction, essay, poetry, biography • The contents: describe what the book is about, the plot, its purpose, its organization • Information about the author: what they have written before, other prominent work, their qualifications • A quoted passage: to allow the reader to see important information and a sense of the writer’s style. When providing judgment of the book it should be followed by the reason why that judgment was made. It should provide enough support for the reader to decide whether or not they want to read or buy the book. The following are examples of what to make judgments on: • Intent or purpose: how well the author realized their intent or fulfilled the purpose of the book • Relevancy: if the book is relevant to the real world and our time • Accuracy: whether the book works or fails based on its accuracy or errors • Uniqueness: comment on the unique qualities of the book • Audience: a comment on the intended audience of the book or its appeal to other potential readers In addition...

Words: 1197 - Pages: 5

Premium Essay

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

Premium Essay

Not Sure

...be UNDER the desk. Required materials: Charged tablet, charged back-up battery, tablet pen, red pens, pencils, blue or black pens, binder Homework expectations: You will have a variety of different homework assignments. It is imperative that you check RenWeb on a consistent basis, as well as write down the homework from the board every day. Most of the assignments will be completed on your tablet. Many assignments will be graded together in class, and then uploaded to Moodle. Late policy: Daily homework will not be accepted late. If homework is not turned in on the day it is due it will receive a zero. The first zero will result in an email sent to your parents. The second zero will result in a referral to a dean. For projects, book reports, and for the research paper the late policy is a little different than the daily homework policy. The first day that it is late it will get 10% taken off of its overall grade earned. For the second day that it is late it will get 20% taken off of the overall grade earned. On the third day that it is late 30% of the grade will be taken off of its overall grade earned. It will receive a zero if it is not turned in after the third day. Absence policy: You are responsible for completing all work that they have missed. You will have as many days as you have missed to complete the work. Missed quizzes or tests will be made up on the day the you return to school. It is your...

Words: 2409 - Pages: 10

Premium Essay

Business Purpose

...|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

Premium Essay

The Poisonwood Bible Book Report

...Sometimes the things we can’t change end up changing us. In “The Poisonwood Bible”, we are shown just how true this quote can be. In this novel, a missionary Nathan Price, his wife Orleanna and their four daughters, Rachel, Leah, Adah, and Ruth May, all travel to Kilanga to set out on a journey to preach the word of God to the Congolese people. As they begin to leave their home in Georgia they pack everything they believed they were going to need to survive. They did so not knowing what was ahead for them will change their lives. This book is narrated by all of the Price women one after the other. This family goes through things they had never imagined like huge human eating ants, droughts, floods, hunger, diseases, killer mamba snakes and...

Words: 317 - Pages: 2

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

Premium Essay

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