Homework 2 Solutions Group B 1- Write a C++ program to read a students score in Statistics and print if he is successful or failing.

Similar documents
Chapter 4. Flow of Control

Object Oriented Programming Using C++ Mathematics & Computing IET, Katunayake

Selection Control Structure CSC128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING

Engineering 12 - Spring, 1999

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100

Control Statements. If Statement if statement tests a particular condition

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

A Freshman C++ Programming Course

1. Answer the following : a) What do you mean by Open Source Software. Give an example. (2)

Computer Programming. Decision Making (2) Loops

Relational operators (1)

MODULE 2: Branching and Looping

5. Selection: If and Switch Controls

C++ character set Letters:- A-Z, a-z Digits:- 0 to 9 Special Symbols:- space + - / ( ) [ ] =! = < >, $ # ; :? & White Spaces:- Blank Space, Horizontal

Programming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3

Sample Paper - II Subject Computer Science

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

switch case Logic Syntax Basics Functionality Rules Nested switch switch case Comp Sci 1570 Introduction to C++

I SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK a) What is the difference between Hardware and Software? Give one example for each.

CSCE Practice Midterm. Data Types

Warm Up. Factor the following numbers and expressions. Multiply the following factors using either FOIL or Box Method

Programming Fundamentals. With C++ Variable Declaration, Evaluation and Assignment 1

Boolean Algebra Boolean Algebra

C Program. Output. Hi everyone. #include <stdio.h> main () { printf ( Hi everyone\n ); }

c++ Solutions eedsohag.epizy.com Ahmed Ali

Chapter 3 Problem Solving and the Computer

More Programming Constructs -- Introduction

Computer Engineering Department CMPE110 Midterm Sample Questions, 2017/ Fall

Operators and Expressions:

1. FIBONACCI SERIES. Write a C++ program to generate the Fibonacci for n terms. To write a C++ program to generate the Fibonacci for n terms.

CSCE Practice Midterm. Data Types

UNIT- 3 Introduction to C++

CSCI 135 Software Design and Analysis, C++ Homework 1 Solution

Write a program that displays all the even integers between 1 and 100, inclusive

ASSIGNMENT CLASS-11 COMPUTER SCIENCE [C++]

CS1100 Introduction to Programming

SHARDA UNIVERSITY SCHOOL OF ENGINEERING & TECHNOLOGY Mid Term Examination, (Odd Term, ) SOLUTION

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

COMP 208 Computers in Engineering

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

conditional statements

C++ PROGRAMMING SKILLS Part 2 Programming Structures

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE

Inheritance

Control Structure and Loop Statements

The Distributive Property and Expressions Understand how to use the Distributive Property to Clear Parenthesis

Algebra 2 Common Core Summer Skills Packet

Chapter-9 INPUT AND OUTPUT OPERATORS

CMPE Experiment 3 Selective Structures

/* Area and circumference of a circle */ /*celsius to fahrenheit*/

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

ME 172. Lecture 2. Data Types and Modifier 3/7/2011. variables scanf() printf() Basic data types are. Modifiers. char int float double

Lecture 3 Tao Wang 1

Review. Relational Operators. The if Statement. CS 151 Review #4

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

AP CS Unit 3: Control Structures Notes

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

PDS Lab Section 16 Autumn Tutorial 3. C Programming Constructs

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

Precedence and Associativity Table. % specifiers in ANSI C: String Control Codes:

LOGO BASIC ELEMENTS OF A COMPUTER PROGRAM

C Tutorial: Part 1. Dr. Charalampos C. Tsimenidis. Newcastle University School of Electrical and Electronic Engineering.

Lecture 4. 1 Statements: 2 Getting Started with C++: LESSON FOUR

Topics. Chapter 5. Equality Operators

More About Factoring Trinomials

C++ Programming: From Problem Analysis to Program Design, Third Edition

b. Suppose you enter input from the console, when you run the program. What is the output?

Transformation a shifting or change in shape of a graph

Solve the matrix equation AX B for X by using A.(1-3) Use the Inverse Matrix Calculator Link to check your work

C++ Final Exam 2017/2018

PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE

Computer Programming : C++

LAB 4.1 Relational Operators and the if Statement

VOLUME II CHAPTER 9 INTRODUCTION TO C++ HANDS ON PRACTICE PROGRAMS

Structured Programming. Dr. Mohamed Khedr Lecture 4

Worksheet 4 Basic Input functions and Mathematical Operators

2. ARRAYS What is an Array? index number subscrip 2. Write array declarations for the following: 3. What is array initialization?

Concepts Review. 2. A program is the implementation of an algorithm in a particular computer language, like C and C++.

Introduction to Algorithms and Programming (COMP151)

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

LAB 5 Arithmetic Operations Simple Calculator

Finite Math - J-term Homework. Section Inverse of a Square Matrix

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Decision Making and Branching

The following expression causes a divide by zero error:

Introduction to Programming EC-105. Lecture 2

Algebra I Notes Linear Equations and Inequalities in Two Variables Unit 04c

بسم اهلل الرمحن الرحيم

Overview of C, Part 2. CSE 130: Introduction to Programming in C Stony Brook University

UNIT 8: SOLVING AND GRAPHING QUADRATICS. 8-1 Factoring to Solve Quadratic Equations. Solve each equation:

Tribhuvan University Institute of Science and Technology 2065

REPETITION CONTROL STRUCTURE LOGO

Course Outline. Introduction to java

Reading from and Writing to Files. Files (3.12) Steps to Using Files. Section 3.12 & 13.1 & Data stored in variables is temporary

Lesson 02 Data Types and Statements. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Rules of Exponents Part 1[Algebra 1](In Class Version).notebook. August 22, 2017 WARM UP. Simplify using order of operations. SOLUTION.

Score score < score < score < 65 Score < 50

CSCI 111 First Midterm Exam Fall Solutions 09.00am 09.50am, Wednesday, October 18, 2017

If Control Construct

Transcription:

Homework 2 Solutions Group B 1- Write a C++ program to read a students score in Statistics and print if he is successful or failing. int score; cout<< \nenter Student s score: ; cin>>score; if ((score>=60)&&(score<=100)) cout<< Successful ; if ((score>=0)&&(score<60)) cout<< Failing ; cout<< not a valid score ; 2- Write a C++ program to calculate and print out the almsgiving on an amount of money only if it is more than or equal 10000. float amount,giving; cout<< \nenter an amount: ; cin>>amount; if (amount >= 10000) giving = amount * 0.025; cout<< \n You have to pay: <<giving; cout<< \n You have not to pay ;

3- Write a C++ program to enter an integer and determine if it is positive, negative or zero. int num; cout<< \nenter an integer: ; cin>>num; if (num>0) cout<< positive ; if(num>0) cout<< negative ; cout<< zero ; 4- Write a C++ program to enter two integers and an operation to be executed on them and calculate the result. Use switch case. int x,y; char op; cout<< \n Enter num1 operand num2 ; cin>>x>>op>>y; switch(op) case + : cout<< \n sum = <<x+y; break; case - : cout<< \n difference = << x-y; break; case * : cout<< \n multiply = << x*y; break; case / : cout<< \n quotient = <<x/y; break;

5- Write a C++ program to read the user s age and print a message you are a child if age is less than 18, you are an adult if age is more than or equal 18 and less than 65 or you are a senior citizen if age is more than or equal 65. #include<iostream> #include<conio.h> int age; cout<<"\n Please enter your age: "; cin>>age; if (age<18) cout<<"\n You are a child"; if ((age>=18)&&(age<65)) cout<<"\n You are an adult"; cout<<"\n You are a senior citizen"; 6- Write a C++ program to read a character and print a message it is a vowel if character is one of (a,e,i,o,u), it is an operator if character is (+,-,*,/) or it is something if any other character. Use if, then use switch case. char ch; cout<<"\n Enter a character: "; cin>>ch; switch (ch) case a : case e : case i : case o : case u : cout<< \n it is a vowel ; break; case + : case - : case * : case / : cout<< \n it is an operator ; break; default: cout<< \n it is something ;

char ch; cout<<"\n Enter a character: "; cin>>ch; if ((ch == a ) (ch == e ) (ch == i ) (ch == o ) (ch == u )) cout<< \n it is a vowel ; if ((ch == + ) (ch == - ) (ch == * ) (ch == / )) cout<< \n it is an operator ; cout<< \n it is something ; 7- Write a C++ program to read two integer values and use the conditional expression (?) to find and print out if one of them is a multiple or not multiple of the other. int a,b; cout<<"\n a= "; cin>>a; cout<<"\n b= "; cin>>b; cout<< ((a%b==0)? " a multiple": " not a multiple"); 8- Write a C++ program to read 4 integer values and print out them in reverse order. int a,b,c,d; cout<<"\n enter four integers "; cin>>a>>b>>c>>d; cout<<d<<, <<c<<, <<b<<, <<a;

9- Write a C++ program to read 4 integers, find and print the maximum and the minimum. int a,b,c,d; int max,min; cout<<"\n enter four integers "; cin>>a>>b>>c>>d; max = a; min = a; if (max<b) max=b; if (min>b) min=b; if (max<c) max=c; if (min>c) min=c; if (max<d) max=d; if (min>d) min=d; cout<< \n max value= <<max; cout<< \n min value= <<min; 10- Write a C++ program to find and print out the solutions of a quadratic equation in one variable. ax 2 + bx + c = 0 #include<stdio.h> #include<conio.h> #include<math.h> float a,b,c,d,x1,x2; cout<<"\n a= "; cin>>a; cout<<"\n b= "; cin>>b; cout<<"\n c= "; cin>>c; d = pow(b,2) - 4*a*c; if ( d>=0 ) x1 = (-b + sqrt(d))/(2*a); x2 = (-b - sqrt(d))/(2*a); cout<<"\n real roots: x1= <<x1<< and x2= "<<x2; cout<<"\n No real roots";

11- Write a C++ program to count the characters, numeric and spaces in a written paragraph. // Count blanks, digits, letters, newlines, and others char ch; int blank_cnt = 0, digit_cnt = 0, letter_cnt = 0, nl_cnt = 0, other_cnt = 0; while ((ch = getchar())!= EOF) /* braces not necessary */ if (c == ' ') ++blank_cnt; if (c >= '0' && c <= '9') ++digit_cnt; if ((c >= 'a' && c <= 'z') (c >= 'A' && c <= 'Z')) ++letter_cnt; if (c == '\n') ++nl_cnt; ++other_cnt; cout<< \n blanks \t digits \t letters \t lines \t others"; cout<< \n <<blank_cnt<< \t <<digit_cnt<< \t <<letter_cnt<< \t <<nl_cnt << \t << other_cnt;

12- Write a C++ program to enter the income in US Dollars, calculate and print out the income taxes according to the following table: Income 0<income<=15000 15000<income<=30000 30000<income<=55000 income>55000 Tax value 7.5% of the income 10% of the income 15% of the income 20% of the income #include<iostream> #include<conio.h> float income, tax; cout<<"\n enter the income in USD: "; cin>>income; if (income>0 && income<=15000) tax = 0.075*income; if (income>15000 && income<=30000) tax = 0.1*income; if (income>30000 && income<=55000) tax = 0.15*income; if (income>55000) tax = 79772 + 0.396*income; cout<< \n tax value = <<tax;