Question

CT143 : Intro to C++ Lab 15: Array Practice Instructions Complete each of the C++ activities described below in a single sour
b. Request the user to enter 5 grades (out of 100) and store the results in the 5 spaces of the array. c. Using a variable ca
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. Favorite Numbers

#include <iostream>

using namespace std;

int main()
{
int count[10] = {1, 2, 3, 4,5,6,7,8,9,10};  // initialize the array with 10 integers
std::cout << count[0]+count[4] << std::endl; // accessing 1st element and 5th element and adding both
std::cout << (count[9]*3)-count[3] << std::endl; // multiplying 10th member 3 times and subtracting 4th member from it
if(count[5]>count[7]) // checking largest of the 6th and 8th member
{
std::cout << count[5] << std::endl;
}
else
{
std::cout << count[7] << std::endl;
}

return 0;
}

2. Days of the week

#include <iostream>
#include<string> // for string class

using namespace std;

int main()
{
string weekdays[10] = {"Monday","Tuesday","Wednesday","thursday","friday","saturday","sunday"}; // initialize the array with 7 strings ie weekdays
std::cout <<"The third day of the week is "<<weekdays[2]<< std::endl; // print the 3rd memeber of the weekdays array
return 0;
}
3. Grades

#include <iostream>
#include<string> // for string class

using namespace std;

int main()
{
float sum=0.0,average=0.0; // initialize the sum to add all the 5 grades and initialize average to find the average
float grades[5] = {0.0}; // initialize the array of 5 grades with value 0.0

  std::cout<<"enter 5 grades out of 100"<< std::endl;
for(int i =0;i<5;i++) // Loop for 5 times to input 5 grades into the grades array
{
std::cin >> grades[i];  // grade input from user
}
for(int i=0;i<5;i++) // Loop for 5 times to get the inputed grades
{
sum=sum+grades[i]; // add all the grades into the variable sum
}
average = sum/5; // divide the sum by total number of grades ie 5 to get the average
std::cout <<"The average is "<<average<< std::endl;

return 0;
}


4. Looping the week

#include <iostream>
#include<string> // for string class

using namespace std;

int main()
{
string weekdays[7] = {"Monday","Tuesday","Wednesday","thursday","friday","saturday","sunday"};// initialize the array with weeks
for(int i=0;i<7;i++) // Loop for 7 times to display the days
{
std::cout <<weekdays[i] << std::endl; display each day stored in the array
}
return 0;
}

Add a comment
Know the answer?
Add Answer to:
CT143 : Intro to C++ Lab 15: Array Practice Instructions Complete each of the C++ activities...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c++ I need help! create Student.h In this class, you are provided with a class skeleton...

    c++ I need help! create Student.h In this class, you are provided with a class skeleton for the Student type. This type should contain two member variables: a string called name a vector of doubles called grades Additionally, you should declare the following functions: A constructor which accepts a single string parameter called name A void function, addGrade which accepts a single double parameter and adds it to the grades vector A function which accepts no parameters and returns the...

  • Help with C++ please Create a class called ClassQuiz. ClassQuiz will maintain quiz grades for students...

    Help with C++ please Create a class called ClassQuiz. ClassQuiz will maintain quiz grades for students in a class. The class has the following member variables: int numStudents // holds the number of students in the class double* grades // to point to a dynamically allocated array of grades The class has the following public functions: +default constructors //set numStudents = 0; and grades = nullptr; +parameterized constructors //accepts numStudents and creates an array with size = numStudents; +AcceptGrades //...

  • using c/c++ Q1 (15 Marks) Console Application for Student Data 1- Write a function named Average...

    using c/c++ Q1 (15 Marks) Console Application for Student Data 1- Write a function named Average that Receives two integer numbers as parameter and returns the average Is used in a main function. Main() stays in a loop and asks user to enter 2 numbers and then shows the average using the Average function above Define a class named Student with following members: private data: 2 grades and a GPA (average). public constructor to initialize the members a public function...

  • I need help with this assignment. It's due Tuesday at 8 AM. Please follow the instructions thorou...

    I need help with this assignment. It's due Tuesday at 8 AM. Please follow the instructions thoroughly as to not use any advanced material we may not have gone over in class. The instructions let you know what all should be used. Thanks! Use only what you have learned in Chapters 1 - 7. Use of "advanced" material, material not in the text, or project does not follow the instructions, will result in a GRADE OF 0% for the project....

  • create an application that calculates the grades of students Wilbur Wright College CIS 142 C++ Programming...

    create an application that calculates the grades of students Wilbur Wright College CIS 142 C++ Programming Language Prof. Gustavo Alatta Lab #4 Points: 100 1.1. Create an application that calculates the grades of a group of students. The program must follow these specifications: - You need to declare 2 arrays: 1 single String array to contain the name of the students and the second a double two-dimensional to hold the grades of the students. - The program must allow the...

  • Using the following parallel array and array of vectors: // may be declared outside the main...

    Using the following parallel array and array of vectors: // may be declared outside the main function const int NUM_STUDENTS =3; // may only be declared within the main function string Students[NUM_STUDENTS] = {"Tom","Jane","Jo"}; vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}}; Write a C++ program to run a menu-driven program with the following choices: 1) Display the grades 2) Add grade 3) Remove grade for all students for a selected assignment 4) Display Average for each student 5) Display the name of...

  • c++ code Lab Exercises This assignment consists of two exercises. Exercise 1- Count Inversions Exercise Objectives...

    c++ code Lab Exercises This assignment consists of two exercises. Exercise 1- Count Inversions Exercise Objectives Define and call functions ✓ Using Array Using nested loop ✓ Using input/output statement Problem Description Inside "Lab2" folder, create a project named "Lab2Ex1". Use this project to write and run a C++ program that produces: Define a constant value called A_SIZE with value of 10. ► Declare an integer 10 array of size A_SIZE called Arr. Define a function called Read that accept...

  • C and C++ Console Application for Student Data 1- Write a function named Average that a....

    C and C++ Console Application for Student Data 1- Write a function named Average that a. Receives two integer numbers as parameter and returns the average b. Is used in a main function. Main() stays in a loop and asks user to enter 2 numbers and then shows the average using the Average function above 2- Define a class named Student with following members: a. private data: 2 grades and a GPA (average). b. public constructor to initialize the members...

  • Lab 6 Instructions Objectives: • Executing and experimenting with programs that handle array related topics such...

    Lab 6 Instructions Objectives: • Executing and experimenting with programs that handle array related topics such as declaration, initialization, storing, retrieving, and processing elements. • Effectively manipulating and using ArrayList objects. • Becoming familiar with the use of arrays as method arguments and how array elements are passed to and returned from the called method. • Mastering the use of various debugging tools available on the Eclipse IDU. Important: EVERY one of the following Activities MUST be in a separate...

  • Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names,...

    Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names, and read in course names from an input file. Then do the output to show each course name that was read in. See Chapter 8 section on "C-Strings", and the section "Arrays of Strings and C-strings", which gives an example related to this lab. Declare the array for course names as a 2-D char array: char courseNames[10] [ 50]; -each row will be a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT