Question

In: Computer Science

Inside “Lab1”folder, create a project named “Lab1Ex1”. Use this project to write and run a C++...

Inside “Lab1”folder, create a project named “Lab1Ex1”. Use this project to write and run a C++ program that produces:  Define a constant value called MAX_SIZE with value of 10.  Define an array of integers called Class_Marks with MAX_SIZE which contains students Mark. Define a function called “Fill_Array” that takes an array, and array size as parameters. The function fills the odd index of the array randomly in the range of [50- 100] and fills the even index of the array using input from user. The valid input values are between 50-100.

Hint: To get random number you can use rand() function: min + rand()%(max-min+1)  Fill the array by calling Fill_Array function

Solutions

Expert Solution

#include<iostream>
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
using namespace std;
void Fill_Array(int marks[],int size);

int main (){
   /* initialize random seed: */
   srand (time(NULL));
   const int MAX_SIZE = 10;
   int Class_Marks[MAX_SIZE];
   Fill_Array(Class_Marks,MAX_SIZE);
   cout<<"\nMarks in the array:\n";
   for(int i=0;i<MAX_SIZE;i++){
       cout<<Class_Marks[i]<<endl;
   }
   return 0;
}

void Fill_Array(int marks[],int size){
   for(int i=0;i<size;i++){
       if(i%2==0){
           cout<<"Enter marks at index "<<i<<": ";
           cin>>marks[i];
           while(marks[i]<50 || marks[i]>100){
               cout<<"Marks should be in the range [50,100]!!\n";
           cout<<"Enter marks at index "<<i<<": ";
           cin>>marks[i];
           }
       } else {
           marks[i] = 50 + rand()%(100-50+1);
       }
   }
}


Related Solutions

Inside “Lab1” folder, create a project named “Lab1Ex3”. Use this project to develop a C++ program...
Inside “Lab1” folder, create a project named “Lab1Ex3”. Use this project to develop a C++ program that performs the following:  Define a function called “Find_Min” that takes an array, and array size and return the minimum value on the array.  Define a function called “Find_Max” that takes an array, and array size and return the maximum value on the array.  Define a function called “Count_Mark” that takes an array, array size, and an integer value (mark) and...
I. At the beginning, create a folder named "test" and add the folder into the version...
I. At the beginning, create a folder named "test" and add the folder into the version control tool tracking system. Then create one file named "001" under this folder. Commit any change if necessary. II. Next, add another file named "002" in the same folder and commit the change ("adding") in the version control tool. III. Followed by adding that file, create a branch (namely, "branch-A") in the version control tool and make some changes to the contents in file...
In the root of the project create a folder called res. In that folder create a...
In the root of the project create a folder called res. In that folder create a file called DemoFile.txt Create a class with a static main that tests the ability to resolve and print a Path: Create an instance of a FileSystem class. Create an instance of the Path interface for the DemoFile.txt file. Print the constructed Path with System.out.println() method. Create a class that does the following: Using a pre-Java 7 solution, create a class that tests streams in...
Using NetBeans, create a Java project named FruitBasket. Set the project location to your own folder....
Using NetBeans, create a Java project named FruitBasket. Set the project location to your own folder. 3. Import Scanner and Stacks from the java.util package. 4. Create a Stack object named basket. 5. The output shall: 5.1.Ask the user to input the number of fruits s/he would like to catch. 5.2.Ask the user to choose a fruit to catch by pressing A for apple, O for orange, M for mango, or G for guava. 5.3.Display all the fruits that the...
At the command prompt: Change to your Downloads folder inside your home folder. Inside your Downloads...
At the command prompt: Change to your Downloads folder inside your home folder. Inside your Downloads folder, create a new folder named "IT1130". Inside the IT1130 folder, enter the following command: date /T > now.txt This last command creates a text file named now.txt containing the current date. Use the more command to display the contents of the now.txt file. Copy and paste the entire output of your more command into the space provided below. There should be one line...
Objectives: 1. Create classes to model objects Instructions: 1. Create a new folder named Lab6 and...
Objectives: 1. Create classes to model objects Instructions: 1. Create a new folder named Lab6 and save all your files for this lab into this new folder. 2. You can use any IDE (such as SciTE, NetBeans or Eclipse) or any online site (such as repl.it or onlinegdb.com) to develop your Java programs 3. All your programs must have good internal documentation. For information on internal documentation, refer to the lab guide. Problems [30 marks] Problem 1: The Account class...
Objectives: 1. Create classes to model objects Instructions: 1. Create a new folder named Lab6 and...
Objectives: 1. Create classes to model objects Instructions: 1. Create a new folder named Lab6 and save all your files for this lab into this new folder. 2. You can use any IDE (such as SciTE, NetBeans or Eclipse) or any online site (such as repl.it or onlinegdb.com) to develop your Java programs 3. All your programs must have good internal documentation. For information on internal documentation, refer to the lab guide. Problem : The Fraction class (Filename: TestFraction.java) Design...
JAVA There is a folder named Recursive folder at the same location as these below files,...
JAVA There is a folder named Recursive folder at the same location as these below files, which contains files and folders. I have read the data of the Recursive folder and stored in a variable. Now they are required to be encrypted and decrypted. You may copy past the files to three different files and see the output. I am confused on how to write code for encrypt() and decrypt() The names of files and folders are stored in one...
Create a schematic of a circuit using and write C program to run on a PIC...
Create a schematic of a circuit using and write C program to run on a PIC 16F88 that will flash between a red and green LED at 5Hz with the green on 75% of the time and the red on 25% of the time.
Create a C++ project in visual studio. You can use the C++ project that I uploaded...
Create a C++ project in visual studio. You can use the C++ project that I uploaded to complete this project. 1. Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT