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

Similar documents
Computer Department. Question (1): State whether each of the following is true or false. Question (2): Select the correct answer from the following:

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

LAB 4.1 Relational Operators and the if Statement

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

CS 007A Midterm 1 Practice Chapters 1 5

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Dr. Khalil Exam II Fall 2011

Add Subtract Multiply Divide

3/12/2018. Structures. Programming in C++ Sequential Branching Repeating. Loops (Repetition)

CSci 1113 Midterm 1. Name: Student ID:

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science. Instructor: Final Exam Fall 2011

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.

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 4: Repetition Control Structure

Chapter 01 Arrays Prepared By: Dr. Murad Magableh 2013

CSCE Practice Midterm. Data Types

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Instructor: Final Exam Fall Section No.

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

CMPS 221 Sample Final

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010

Computer Programming

while for do while ! set a counter variable to 0 ! increment it inside the loop (each iteration)

Lab 6. Review of Variables, Formatting & Loops By: Dr. John Abraham, Professor, UTPA


(6) The specification of a name with its type in a program. (7) Some memory that holds a value of a given type.

C Programming for Engineers Structured Program

CSCE Practice Midterm. Data Types

CSCE 2004 Midterm Exam Spring 2017

Arrays in C++ Instructor: Andy Abreu

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.7. User Defined Functions II

Exam 1. CSI 201: Computer Science 1 Fall 2018 Professors: Shaun Ramsey

Elements of C in C++ data types if else statement for loops. random numbers rolling a die

Computer Engineering Department CMPE110 Midterm Sample Questions, 2017/ Fall

In this chapter you will learn:

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

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

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

Al Imam Mohammad Ibn Saud Islamic University College of Computer and Information Sciences Computer Science Department

C++ PROGRAMMING SKILLS Part 4: Arrays

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 03

1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl?

Structured Programming. Flowchart Symbols. Structured Programming. Selection. Sequence. Control Structures ELEC 330 1

Chapter 3 Problem Solving and the Computer

Exam 3 Chapters 7 & 9

CS 105 Lecture 5 Logical Operators; Switch Statement. Wed, Feb 16, 2011, 5:11 pm

Functions Overview. Functions (aka procedures, subroutines, or methods) are the unit of code decomposition and abstraction

CS 101, Spring 2016 March 22nd Exam 2

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

Learning Objectives: General Description: DONE DONE Structure Chart

EE 109 Lab 8a Conversion Experience

University of Dublin

CMPE Experiment 3 Selective Structures

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

FORM 2 (Please put your name and form # on the scantron!!!!)

CSci 1113 Midterm 2. Name: Student ID:

C++ Final Exam 2017/2018

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Introduction to Computer Science Midterm 3 Fall, Points

CS 141, Introduction to Computer Science Fall Midterm Exam

Arrays and functions Multidimensional arrays Sorting and algorithm efficiency

REPETITION CONTROL STRUCTURE LOGO

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

University of Toronto

Computer Programming

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE Instructor: Final Exam Fall 2014

Final Examination Semester 2 / Year 2005

Review Problems for Final Exam. 1. What is the output of the following program? #include <iostream> #include <string> using namespace std;

1) What of the following sets of values for A, B, C, and D would cause the string "one" to be printed?

int x = 5; double y = 3; // Integer division rounds the result down to the nearest whole number. cout << "1a: " << x / 3 << endl; //1

Copy: IF THE PROGRAM or OUTPUT is Copied, then both will have grade zero.

CSCI 101L - Data Structures. Practice problems for Final Exam. Instructor: Prof Tejada

Independent Representation

Problem Statement. B1: average speed

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

CSCE 206: Structured Programming in C++

Computer Programming. Decision Making (2) Loops

CSCI 111 Midterm 1, version A Exam Fall Solutions 09.00am 09.50am, Tuesday, October 13, 2015

Looping. Arizona State University 1

COMP 11 Class 17 Outline

C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh

(3) Some memory that holds a value of a given type. (8) The basic unit of addressing in most computers.

Name Section: M/W T/TH Number Definition Matching (8 Points)

CS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma.

Outline. Introduction. Arrays declarations and initialization. Const variables. Character arrays. Static arrays. Examples.

1. HotDog 판매량출력프로그램. numsold = newnumsold; ID = newid; HotDogStand(); HotDogStand(int newid, int newnnumsold); return ID; void SetID(int newid);

Lecture 3 Tao Wang 1

Increment and the While. Class 15

CSC 211 Intermediate Programming. Pointers

CSCI 111 First Midterm Exam Spring Solutions 09.05am 09.55am, Wednesday, March 14, 2018

Control Structures. Flowchart Symbols

Chapter 2 - Control Structures

INTRODUCTION TO COMPUTER SCIENCE - LAB

The American University in Cairo Computer Science & Engineering Department CSCE 106 Fundamentals of Computer Science

The American University in Cairo Department of Computer Science & Engineeringt CSCI &09 Dr. KHALIL Exam-I Fall 2009

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

CHAPTER 3 Expressions, Functions, Output

UEE1302(1066) F12: Introduction to Computers and Programming Function (II) - Parameter

LAB 7.1 Working with One-Dimensional Arrays

1st Midterm Exam: Solution COEN 243: Programming Methodology I

Class 2: Variables and Memory. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

Transcription:

Write a program that displays all the even integers between 1 and 100, inclusive for(int i=1;i<=100;i++) if(i%2==0) cout << setw(4) << i; Write a program that performs multiplication of integers by repeated addition. The program should ask the user to enter two integers, which the program stores in num1 and num2. Using an accumulator, the program should then add num1 to itself num2 times. Finally, the program should display the resulting product. int num1,num2,result=0; cout << "Enter the num1, num2: "; cin >> num1 >> num2; for(int i=0;i<num2;i++) result+=num1; cout << "\nthe resulting product: " << result << endl;

Write a program that raises an integer to a positive integer power. The program should prompt the user to enter the base and the exponent. The program should calculate the power by multiplying base by itself exponent times. Finally, the program should display the result. Test your program by making it calculate 25 and 54. int base,exponent,result=1; cout << "enter the base: "; cin >> base; cout << "\nenter the exponent: "; cin >> exponent; for(int i=0;i<exponent;i++) result*=base; cout << "\nthe result: " << result << endl; A cattle-feed company needs a program to help process feed orders. The program is to process an indeterminate number of orders. Each customer orders one or both of two types of feed, A and B. Feed A costs $2.50 per 100 pounds and feed B costs $3.15 per 100 pounds. Amounts less than 100 pounds are to be charged proportionally. For each customer, the program should ask the user to enter the actual number of pounds ordered for each of feeds A and B to the nearest tenth of a pound. The program should display the amount and cost of each type of feed and the total cost of the order. When no more customers are to be processed, the program should display the total number of customers processed, the total amount of feed A ordered, and the total amount of feed B ordered to the nearest tenth of a pound, and the total receipts. Write the required program. int feeds,poundsa,poundsb,t_poundsa=0,t_poundsb=0,num=0; float costa,costb,t_costs=0; char R; while(r!= 'n') cout << "\n1.a feed\n2.b feed\n3. A,b feed " <<endl; cin >> feeds; if(feeds==1) cout << "\nenter the actual number of pounds for A: ";

cin >> poundsa; costa=(2.5/100)*poundsa; t_costs+=costa; t_poundsa+=poundsa; cout << "\nthe amount of A: " << poundsa; cout << "\nthe cost of A: " << costa; cout << "\nthe total cost of the order: " << costa; cout << "\nto another order press (y) or not (n): "; cin >> R; else if(feeds==2) cout << "\nenter the actual number of pounds for B: "; cin >> poundsb; costb=(3.15/100)*poundsb; t_costs+=costb; t_poundsb+=poundsb; cout << "\nthe amount of B: " << poundsb; cout << "\nthe cost of B: " << costb; cout << "\nthe total cost of the order: " << costb; cout << "\nto another order press (y) or not (n): "; cin >> R; else if(feeds==3) cout << "\nenter the actual number of pounds for A : "; cin >> poundsa; cout << "\nenter the actual number of pounds for B: "; cin >> poundsb;

costa=(2.5/100)*poundsa; costb=(3.15/100)*poundsb; t_costs+=(costa+costb); t_poundsa+=poundsa; t_poundsb+=poundsb; cout << "\nthe amount of A: " << poundsa; cout << "\nthe amount of B: " << poundsb; cout << "\nthe cost of A: " << costa; cout << "\nthe cost of B: " << costb; cout << "\nthe total cost of the order: " << costa+costb; cout << "\nto another order press (y) or not (n): "; cin >> R; cout << "\nthe total number of customers processed: " << num; cout << "\nthe total amount of feed A ordered: " << t_poundsa; cout << "\nthe total amount of feed B ordered: " << t_poundsb; cout << "\nthe total receipts: " << t_costs << endl;

A computer science instructor needs a program that averages the grades she receives on a quiz she gives to her class. Each grade is an integer between 0 and 100. She does not know the number of grades at this time. Write a program that asks the user to enter quiz grades one at a time. After the user has completed entering grades, the program should display the number of grades entered and the sum of the grades entered. The program should also display the average of the grades, rounded to the nearest tenth. int grades,num=0,sum=0; char out; for(;;) cout << "\nto input grades press (y) or not press (n): "; cin >> out ; if(out == 'n' out == 'N') break; cout << "\nenter quiz grades: "; cin >> grades ; while (grades<0 grades>100) cout << "\nenter quiz grades between 0 and 100: "; cin >> grades; sum+=grades; cout << "\nthe number of grades entered: " << num; cout << "\nthe sum of the grades entered: " << sum; cout << "\nthe average of the grades: " << sum/num << endl;

A computer science instructor wants you to write a program to compute final grades for her Introduction to Computers course. The program is to process an indeterminate number of students. For each student the program should ask the user to enter the mid-term and final exam scores and then display the student's final grade. The final grade is the sum of 45% of the mid-term exam score and 55% of the final exam score. After it processes all the students, the program should display the number of students it processed, and the average mid-term exam score, average final exam score, and average final grade all to the nearest tenth. Write the required program. int mid_term,final_exam,t_mid_term=0,t_final_exam=0,student_final,num=0,sum=0,t_student_final=0; char out; for(;;) cout << "\nenter the mid-term scores: "; cin >> mid_term ; cout << "\nenter the final exam scores: "; cin >> final_exam ; student_final=((mid_term*45)/100)+((final_exam*55)/100); t_mid_term+=((mid_term*45)/100); t_final_exam+=((final_exam*55)/100); t_student_final+=student_final; cout << "\nthe student's final grade: " <<student_final; cout << "\nto input scores again press (y) or not press (n): "; cin >> out ; if(out == 'n' out == 'N') break; cout << "\nthe number of students it processed: " << num; cout << "\nthe average mid-term exam score: " << t_mid_term/num; cout << "\nthe average final exam score: " << t_final_exam/num; cout << "\nthe average final grade score: " << t_student_final/num << endl;