COMP 218 C++

Java Python © May not be copied or duplicated
without the permission of the owner.
COMP 218 Fundamentals of Object-Oriented
Programming
Assignment 1

Please note: you are NOT allowed to post the assignment/solution anywhere on the
Internet. Intellectual Property rights are reserved. If any similar cases are found via your
account or IP, your submission will NOT be considered and will be reported
immediately.

General Guidelines when Writing Programs:
- Include the following comments at the top of your source codes
// -----------------------------------------------------
// Assignment (include number)
// Question: (include number)
// File name: (include source code file name)
// Written by: (include your name and student id)
// -----------------------------------------------------
- In a comment, give a general explanation of what your program does. As the
programing questions get more complex, the explanations will get lengthier.
- Include comments in your program describing the main steps in your program.
- Print a welcome message which includes your name.
- Display clear prompts for users when you are expecting the user to enter data
from the keyboard.
- All output should be printed out with clear messages and in an easy to read
format.
- End your program with a closing message so that the user knows that the
program has terminated.

© May not be copied or duplicated
without the permission of the owner.
Question #1: Display a message (3 pts)
Write a complete C++ program that displays the following output exactly as in the
sample output. You are to use a single cout statement to output the message. There is
no need to declare any variables for this question.

Figure 1 – Sample output for Question 1

© May not be copied or duplicated
without the permission of the owner.
Question #2: Number Generator Program (6 pts)
In C++, we can use rand() function (More details) to generate random numbers. In the
number calculation following the requirements:
1. Display a welcome message.
2. Display the randomly generated even/odd number.

Figure 2 – Sample output #1 for Question 2
For example, if the number is 1234, change it to 4321.
For example, 1221 is a palindrome as it is the same if reversed.
For example, the largest digit is 9 and smallest is 1, in 3179.
Your program must display the same information and formatted the same.
3. Reverse the number.
4. Check if the number is a palindrome.
5. Find the smallest and largest digit in the number
question, we will generate a 4-digit random number between 1000 – 9999 and complete
Use at least one constant variable to store value in the program.
Following are 2 sample screen shots to illustrate the expected behavior of y COMP 218、C++ our
program.
Note:
4

© May not be copied or duplicated
without the permission of the owner.

Figure 3 – Sample output #2 for Question 2

Question #3: New Word Program (6 pts)


Your program should behave as follow:
1. Display a welcome message.
2. Ask the user to prompt 3 words with at least 1 letter.
3. Ask the user to prompt 3 numbers, that should be less than the length of each
word to indicate length of substring in each word. For example, if the word is
Ann, then the entered number should be less than 3 (the length of Ann).

5. Display the resulting new word.
6. Display a farewell message, so that the user knows that the program has
terminated normally.
Restriction: This questions requires the use of the functions: length(), substr().
Assumption: Assume a perfect user who will always enter the correct input values.

Following are two sample screen shots to illustrate the expected behavior of your
program. Your program is to work with any words entered by the user.

last n characters. Concatenate the three resulting substrings into a single
new word.
4. For each word, create a new substring by taking the first n characters and the
Write a program that prompts the user for three words.
5

© May not be copied or duplicated
without the permission of the owner.


Figure 4 – Sample output #1 for Question 3

Figure 5 – Sample output #2 for Question 3


6

© May not be copied or duplicated
without the permission of the owner.
Submitting Assignment 1
- Naming convention for zip file to submit: Create one zip file, containing all source
files (.cpp files only) for your assignment. The zip file should be called
a#_studentID, where # is the number of the assignment and studentID is your
student ID number. For example, for the first assignment, student 123456 would
submit a zip file named a1_123456.zip. (See instructions on how to zip files
which are posted in the Assessment section of the eConcordia course webpage.)
- Submit only ONE version of an assignment.
- Late assignments will be discounted by 25%. Late assignments are accepted up
to five days late (grace period) and weekends count.

Evaluation Criteria for Assignment 1 (20 pts)
Question #1
3 pts.
Question #2
6 pts.
Question #3
6 pts.
Format/clarity/completeness/accuracy
of output
1 pt. 4 pts. 2 pts.
Proper use of required C++ concepts 2 pts. 2 pts. 4 pts.


For all 3 questions of assignment 1 – 5 pts.
Comments – description of variables / description of the steps in code
/ purpose of program
2 pts.
Choice of variable names 1 pt.
Indentation and readability of program 2 pts         

这个错误通常是在运行 C/C++ 程序时出现的。它意味着编译器在编译程序时发生了错误,导致无法正确运行程序。可能的原因包括语法错误、链接错误或者库文件丢失等等。为了解决这个问题,你可以检查编译器的输出信息,查看具体的错误提示,从而找到并修复错误。你也可以在编译程序时加入调试信息,以便更好地定位问题。另外,确保你的代码符合语法规范,并且正确地链接了所需的库文件,这些也有助于解决这个问题。非常抱歉,由于您没有提供更多的上下文信息,我很难确定您遇到的确切问题。不过,通常情况下,“error while running c/c++ comp”是指在运行C/C++编译器时出现了错误。以下是一些常见的可能导致此错误的原因和解决方法: 1. 您的代码存在语法错误或逻辑错误,导致编译器无法正常编译。请检查您的代码并尝试修复任何错误。 2. 您的编译器可能没有正确地配置或安装。请检查您的编译器的设置和安装,并确保它们正确地安装和配置。 3. 您的代码可能依赖于缺失的库或头文件。请检查您的代码并确保它们正确地包含了必要的库和头文件。 4. 您的代码可能包含了与平台或操作系统不兼容的部分。请检查您的代码并确保它们与您的平台和操作系统兼容。 如果以上解决方法仍然无法解决您的问题,我建议您提供更多的上下文信息,例如具体的错误消息和代码片段,这将有助于更准确地确定问题并提供更好的解决方案。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值