


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Due Date: By 11:59 PM, Sunday, October 6th, 2019
Evaluation: 3% of final mark (see marking rubric at the end of handout)
Late Submission: none accepted
Purpose: The purpose of this assignment is to help you learn the C++ Basics, cout, cin / loops, function design and its call, the use of operators and primitive types.
Teams: The assignment can be done individually or in teams of 2 students maximum. Team members must be in the same lecture section. Submit one assignment per team; be sure to have both team members’ name in the comments at the top of the assignment.
General Guidelines When Writing Programs:
// Assignment (include number)
// Written by: (include your name (s) and student id(s))
// For CSI2372 Section (your section) – Fall 2019 // -----------------------------------------------------------------------------
Exercise #1:
Rewrite the following C program in C ++ program. C ++ program must be compiled and tested with the number entered on the screen by the user and must display the correct result: #include <stdio.h>
int read_number(void) { int n; /* Read a number */ printf("Enter a number : "); scanf("%d", &n); return n; } void main() { int i, n; long total = 0;
n = read_number();
for (i = 1; i <= n; i++) { total += i; /* accumulation in the variable « total » */ printf("i = %d, total = %ld \n", i, total); }
printf("\n"); printf("*** Final Total = %ld *** \n", total); } /* end of main() */
Here is an example of the output of the C program given above:
Source code
Question 1 (5 pts.)
Rewriting correctly C program to C++ program 3 pts.
Displaying the correct result 2 pts.
Question 2 (5 pts.)
Prompting user/reading data 1 pt.
Utilization of cin, cout and endl 1 pt.
Calculation of the formula 1 pt.
Displaying the result using variables values 2 pts.
Question 3 (5 pts.)
Prompting user/reading data 1 pt.
Utilization of cin, cout and endl 1 pt.
Utilization of while loop and an array to store the numbers 1 pt.
Displaying the result using variables values 2 pts.
Question 4 (5 pts.)
Prompting user/reading data 1 pt.
Utilization of cin, cout and endl 1 pt.
Utilization of while loop and an array to store the numbers 2 pt.
Displaying the result using variables values 1 pt.
Question 5 (5 pts.)
Prompting user/reading data 1 pt.
Utilization of cin, cout and endl 1 pt.
Designing the conversion() function 2 pt.
Displaying the result using variables values 1 pt.