Lab Exercise : Write a program that print the final price of purchase at a store where everything costs exactly one dollar. Ask for the number of items.

Slides:



Advertisements
Similar presentations
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Advertisements

Computer Programming Lab 8.
1 Programming in C++ Lecture Notes 9 Functions (Returning Values) Andreas Savva.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
What is an algorithm? Informally: An Algorithm is a step by step method for solving a problem. It’s purpose is to break a larger task down so that each.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 Lab Session-8 CSIT-121 Fall 2003 w Call by Reference w Lab Exercise 1 w Lab Exercise for Demo w Practice Problems.
1 Lab 2 CSIT-120 Spring 2001 Session II-A (Feb 13th) Operations on Data Lab Exercise 2-A Data Types Variables Lab Exercise 2-B Session II-B (Feb 20th)
Overview creating your own functions calling your own functions.
C++ Typecasting. Math Library Functions.. Operator / Operands A = x + y.
CMPUT 101 Lab #6 October 29, :00 – 17:00. Array in C/C++ Array is a structure type variable. One dimension of array int: int num[3]; There are.
1 Lab Session-6 CSIT-121 Spring 2005 Structured Choice The do~While Loop Lab Exercises.
1 Lab Session-3 CSIT 121 Spring’05 Division rules Operator precedence rules Lab Exercise.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
1 10/25/06CS150 Introduction to Computer Science 1 Reading from and Writing to Files.
1 Lab Session-7 CSIT-121 Fall Introducing Structured Choice 4 The do~While Loop 4 Lab Exercises.
COMP 110 Introduction to Programming Mr. Joshua Stough September 24, 2007.
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Presented by Joaquin Vila Prepared by Sally Scott ACS 168 Problem Solving Using the Computer Week 12 Boolean Expressions, Switches, For-Loops Chapter 7.
Programming in C++ Lecture Notes 6 Void Functions (Procedures) Andreas Savva.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
REVIEW Surie SMKDPM2009. Q1 : Write a while loop that output the numbers 2, 4, 6, 8,..., 20. Answer : i=2; While(i
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
1 Lab Session-8 CSIT-121 Spring 2005 Call by Reference Lab Exercise for Demo Practice Problems.
Sales Tax, Discounts, and Commissions Section 6.7.
Selection Statements in C++ If Statement in C++ Semantics: These statements have the same meaning as in the algorithmic language. 2- Two way selection:
Lecture 5 Selection Control Structures Selection Control Structures Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Chapter 4 Selection Structures: Making Decisions.
习 题 4.23 编写一个 applet ,读取一个矩形的边长,然后 用在 paint 方法中使用 drawString 方法画出用星组成 的空心矩形。程序应能画出边长从 1 到 20 的任何矩 形。
Copyright © Nancy Acemian 2004 For Loops-Break-Continue COMP For loop is a counter controlled loop. For loop is a pretest loop. Used when number.
CHAPTER 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
CHAPTER 8 CONTROL STRUCTURES Prepared by: Lec. Ghader R. Kurdi.
Procedural Programming. Programming Process 1.Understand the problem 2.Outline a general solution 3.Decompose the general solution into manageable component.
CHAPTER#3 PART1 STRUCTURED PROGRAM DEVELOPMENT IN C++ 2 nd semester King Saud University College of Applied studies and Community Service Csc.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Control Structures (B) Topics to cover here: Sequencing in C++ language.
1. 2 Sales tax is calculated by finding the percent of the total purchase.
1 Programming 2 Overview of Programming 1. Write the equations in C++ notation : a) R =   a + b  24  2 a  b) W = a 12 + b 2 – 2abcos(y) 2a.
CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
Agenda  Take up homework  Loops - Continued –For loops Structure / Example involving a for loop  Storing Characters in variables  Introduction to Functions.
Functions Structured Programming. Topics to be covered Introduction to Functions Defining a function Calling a function Arguments, local variables and.
LESSON 4 Decision Control Structure. Decision Control Structures 1. if statement 2. if-else statement 3. If-else-if statement 4. nested if statement 5.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
For Friday Read No quiz Program 6 due. Program 6 Any questions?
Computer Programming Arrays 1. Question #1 2 Question Choose the correct answer..
1 Input (Read) Statement. Variable Declaration (Definition) Initialization Assignment Displaying variables: using cout statement Reading variables from.
C++ Basics Lecture 2.
Basic concepts of C++ Presented by Prof. Satyajit De
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Exercise : Write a program that print the final price of purchase at a store where everything costs exactly one dollar. Ask for the number of items purchased.
MT262A Review.
Variables Mr. Crone.
LESSON 4 Decision Control Structure
Decisions Chapter 4.
Chapter 3 Selections Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
Chapter 2.2 Control Structures (Iteration)
SELECTION STATEMENTS (1)
Control Statement Examples
Computers & Programming Languages
IDENTIFIERS CSC 111.
Compound Assignment Operators in C++
SELECTION STATEMENTS (2)
Class Examples.
SELECTIONS STATEMENTS
Lec 6 Logical Operators String comparison
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Presentation transcript:

Lab Exercise : Write a program that print the final price of purchase at a store where everything costs exactly one dollar. Ask for the number of items purchased. Compute a sales tax of:  8 percent if the users purchase is less than $100  7.5 percent if the purchase is greater or equal to $100. Also if the purchase is over $500, give the customer an additional 10 percent after-tax discount. Print the purchase price, the amount of tax, the amount of the discount ($0.00 if no discount applies) and the total price. Output: Enter number of items purchased= 60 the purchase price= 60 $ the amount of tax= 4.8 $ the amount of the discount= 0.00$ the total price= 64.8 $ Enter number of items purchased= 510 the purchase price= 510$ the amount of tax= 38.25$ the amount of the discount= 54.82$ the total price= $

void main() { int i; float price,tax,d=0,TP; cout >i; price=i; if(price>0) { if(price 500) d=(price + tax)*10/100; TP=price+tax-d; cout<<“ the purchase price= "<<price<<'$'; cout<<"\n\n the amount of tax= "<<tax<<'$'; cout<<"\n\n the amount of the discount= "<<d<<'$'; cout<<"\n\n the total price= "<<TP<<'$'; } else { cout<<"wrong entry"; } getch(); }

Exercise : Write a program that request the user’s language and then print a greeting in that language. Output: Engl., Fren., Ger., Ital., or Rus. ? (e,f,g,i,r):e Welcome Where the greeting will be: English="Welcome" France="Bon jour" Germany=“Guten" Italian=“Bon giorno" Russian="Dobre utre"; Other language=“Sorry, we don't speak your language";

Void main() { char language; cout >language; if (language=='e') cout<<"Welcome"; else if (language=='f') cout<<"Bon jour"; else if (language=='g') cout<<"Guten"; else if (language=='i') cout<<"Bon giorno"; else if (language=='r') cout<<"Dobre utre"; else cout<<"Sorry, we don't speak your language"; getch(); }

Exercise : and write a c++ program that reads an integer number of two digits, then display each digit in a separate line after checking that the number consists of only two digits, otherwise display an appropriate message. Enter number of tow digits = output : Enter number of tow digits =684 Wrong Entry

void main() { int num; cout >num; if((num>=10) && (num<100)) { d1=num%10; d2=num/10; cout<<d1<<endl<<d2; } else cout<<“Wrong Entry"; getch(); }

Exercise: Write a program that reads a six-digits integer and prints the sum of its six digits. Use the quotient operator ( / ) and the reminder operator (%) to extract the digits from the integer. Output: Enter a six-digit integer: The sum of the digits of is 22

void main() { int n,sum ; cout >n; sum = n%10 + (n/10)%10 + (n/100)%10 + (n/1000)%10 + (n/10000)%10 + n/ ; cout<<“ The sum of the digits of “<< n <<” is: “<< sum; getch(); }

Exercise: Write a program that reads a character and determine if it is a vowel letter or not. vowel letters =(a, e, I, o, u) Output: ENTER any character: a a is a vowel letter. Output: ENTER any character: t t is not a vowel letter.

void main() { char le; cout >le; switch(le) { case 'a': case 'e': case 'i': case 'o': case 'u': cout<<le<<" is a vowel letter."; break; default : cout<<le<<" is not a vowel letter."; } getch(); }

Exercise: Output: - Square (sq) - Cube (c) -Squareroot (sr) - power (p) ENTER YOUR CHIOCE: sq enter your number: Square (sq) - Cube (c) - Squareroot (sr) - power (p) ENTER YOUR CHIOCE: p enter tow numbers: 2 3 8

#include #include #include #include void main() { char choice[3]; float x,y,z; cout >x; z=x*x; cout >x; z=sqrt(x); cout<<z; break; default : cout<<"error in index[1]"; } break; case 'c': case 'C': cout >x; z=x*x*x; cout >x>>y; z=pow(x,y); cout<<z; break; default : cout<<"error"; } getch(); }