10 Super-Simple Sample Programs (C++ Review)
Home assignment (C++ review) for CSC 240 Data Structures @ Lyon College, Fall 2025. Week 1 - C++ Review. Using Emacs and Org-mode (use https://tinyurl.com/lyon-emacs as an init file). Silent hacking with country music. 1. Declare two double variables, assign them values, and print their sum, difference, product, and quotient, each on a separate line with a label. 2. Write a program that prompts the user for their first_name and age. Print a message like: "Hello Alice, you are 20 years old." 3. Create a program that declares a const int DAYS_IN_WEEK = 7. Ask the user for a number of days and print how many full weeks and remaining days that corresponds to. 4. Write a program that uses a for loop to compute the sum of all integers from 1 to 100, then print the result. 5. Ask the user to enter a single character. If it’s a vowel, print "You entered a vowel." Otherwise, print "You entered a consonant or symbol." 6. Declare an integer array of size 5. Initialize it with these values in the declaration: 100, 200, 300, 400, 500. Use a loop to print the values in reverse order, with a space in between the elements. 7. Write a program with a function square(int n) that returns the square of n. In main, call the function with a user-provided integer (e.g. 5) and print the result (e.g. 25). 8. Prompt the user to enter 10 integers. Count how many of them are negative, positive, and zero, and print the results. 9. Write a program that simulates rolling a six-sided die 10 times using rand(). Research the usage of this function using cppreference.com. Print the results in a single line separated by spaces. 10. Define a struct called Book with members: title (string), author (string), and pages (int). In main, declare one Book variable, assign values, and print its details.
Download
0 formatsNo download links available.