C++
A sample project is provided AverageGrade that is very similar to the MovieRatings project, but it only is inputting one string (className) instead of both the movie name and the MPAA rating. Another difference is that the AverageGrade program scores grades A to F with point values from 4.0 to 0.0 (highest to lowest) while the MovieRatings scores the rating from 1 to 5 (lowest to highest). When using the AverageGrade program as a reference, make sure that the program for MovieRatings does not use variables such as Acount, Bcount, classSize, etc. Please modify the program below to satisfy the conditions above.
// AverageGrade.h // Provides a C++ class definition that will collect the number of grades // in a classroom and determine the average grade for all students. // // This project implements a program similar to the MovieRatings project. It does not // provide all of the required 'information' shown on the movie ratings project definition. // It the movie ratings go from 1 to (bad to worse), but this program has grade from // A to F (best to worse). These differences need to be taken into account when using // this program as a reference to build the MovieRatings project. #ifndef AverageGrade_h // only compile this header file one time #define AverageGrade_h class AverageGrade { private: char className[100]; int Acount; int Bcount; int Ccount; int Dcount; int Fcount; int classSize; public: AverageGrade(); // default constructor AverageGrade(char *name); // constructor with one argument void countGrade (char grade); void setName(char *name); // mutator - sets the name into the object char *getName(); // accessor - gets the name from the object double getAverage(); }; #endif
=======================================================================
// AverageGrade.cpp // // This project implements a program similar to the MovieRatings project. It does not // provide all of the required 'information' shown on the movie ratings project definition. // It the movie ratings go from 1 to (bad to worse), but this program has grade from // A to F (best to worse). These differences need to be taken into account when using // this program as a reference to build the MovieRatings project. #include "stdafx.h" // only used by some Microsoft C++ compilers #include "AverageGrade.h" #include <cstring> #include <cctype> #include <iostream> using namespace std; AverageGrade::AverageGrade() // default constructor { className[0] = '\0'; // set to an empty string Acount = Bcount = Ccount = Dcount = Fcount = 0; classSize = 0; } AverageGrade::AverageGrade(char *name) { // strcpy (className, name); // use if strcpy is required by the compiler strcpy_s (className, 100, name); // use if strcpy_s is required by the compiler Acount = Bcount = Ccount = Dcount = Fcount = 0; classSize = 0; } void AverageGrade::setName(char* name) // mutator - sets the className { // strcpy (className, name); // use if strcpy is required by the compiler strcpy_s (className, 100, name); // use if strcpy_s is required by the compiler } char* AverageGrade::getName() // accessor - gets the className { return className; } void AverageGrade::countGrade (char grade) { switch ( toupper(grade) ) { case 'A': Acount++; // count the number of A's classSize++; // count the number of students break; case 'B': Bcount++; // count the number of A's classSize++; // count the number of students break; case 'C': Ccount++; // count the number of A's classSize++; // count the number of students break; case 'D': Dcount++; // count the number of A's classSize++; // count the number of students break; case 'F': Fcount++; // count the number of A's classSize++; // count the number of students break; default: cout << grade << " was an illegal input value" << endl; } } double AverageGrade::getAverage() { return ( Acount * 4.0 + Bcount * 3.0 + Ccount * 2.0 + Dcount * 1.0 + Fcount * 0.0) / classSize; }
===================================================================
// C++MovieRatings.cpp : Defines the entry point for the console application. // // This project implements a program similar to the MovieRatings project. It does not // provide all of the required 'information' shown on the movie ratings project definition. // It the movie ratings go from 1 to (bad to worse), but this program has grade from // A to F (best to worse). These differences need to be taken into account when using // this program as a reference to build the MovieRatings project. #include "stdafx.h" // only used by some versions of Microsoft C++ #include "AverageGrade.h" #include <iostream> using namespace std; int main(int argc, char* argv[]) { AverageGrade CIS054; // create an object of class AverageGrade CIS054.setName("C/C++ Programming"); // use mutator to set the class name CIS054.countGrade('A'); CIS054.countGrade('B'); CIS054.countGrade('A'); CIS054.countGrade('C'); CIS054.countGrade('B'); CIS054.countGrade('A'); CIS054.countGrade('F'); cout << "The average score for " << CIS054.getName() << " is " << CIS054.getAverage() << endl; AverageGrade CIS073("Visual Basic Programming"); // create an object of class AverageGrade CIS073.countGrade('A'); CIS073.countGrade('B'); CIS073.countGrade('A'); CIS073.countGrade('C'); CIS073.countGrade('B'); CIS073.countGrade('A'); CIS073.countGrade('D'); cout << "The average score for " << CIS073.getName() << " is " << CIS073.getAverage() << endl; system ("PAUSE"); return 0; }
1. MovieRating.h
#ifndef MovieRating_h // only compile this header file one
time
#define MovieRating_h
class MovieRating
{
private:
char movieName[100];
char MPAA[10];
int count1;
int count2;
int count3;
int count4;
int count5;
public:
MovieRating();
MovieRating(char *n, char *m); //
constructor
void setName(char *name); // mutator
- sets the name into the object
char
*getName();
// accessor - gets the name from the object
void setMPAA(char *m); // mutator -
sets the rating into the object
char *getMPAA();
void addRating(int a); // to add the
rating
double getAverage(); // to calculate average of
all the ratings
};
#endif
2. MovieRating.cpp
#include <cstring>
#include <cctype>
#include <iostream>
#include "movie_rating.h"
using namespace std;
MovieRating::MovieRating() // default
constructor
{
movieName[0] = '\0'; // set to
an empty string
MPAA[0]='\0';
count1 = count2 = count3 = count4 = count5 =
0;
}
MovieRating::MovieRating(char *n, char *m)
{
strcpy (movieName, n);
strcpy(MPAA,m);
count1 = count2 = count3 = count4 = count5 =
0;
}
void MovieRating::setName(char* name) // mutator - sets the
className
{
strcpy(movieName,name); // use
if strcpy_s is required by the compiler
}
char* MovieRating::getName()
// accessor - gets the className
{
return movieName;
}
void MovieRating::setMPAA(char* name) // mutator - sets the
className
{
strcpy(MPAA,name); // use if
strcpy_s is required by the compiler
}
char* MovieRating::getMPAA()
// accessor - gets the className
{
return MPAA;
}
void MovieRating::addRating (int a)
{
switch ( a )
{
case 1:
count1++; // count the number
of 1's
break;
case 2:
count2++; // count the number
of 2's
break;
case 3:
count3++; // count the number
of 3's
break;
case 4:
count4++; // count the number
of 4's
break;
case 5:
count5++; // count the number
of 5's
break;
default:
cout << a <<
" was an illegal input value" << endl;
}
}
double MovieRating::getAverage()
{
return 1.0*( count1
+ count2
+ count3
+ count4
+ count5) / 5;
}
3. main.cpp
//#include
"stdafx.h" // only
used by some versions of Microsoft C++
#include "movie_rating.cpp"
#include <iostream>
using namespace std;
int main()
{
MovieRating m1; // create an
object of class MovieRating
m1.setName("HarryPotter-1");
// use mutator to set the class name
m1.setMPAA("G");
m1.addRating(1);
m1.addRating(2);
m1.addRating(3);
m1.addRating(3);
m1.addRating(2);
m1.addRating(1);
m1.addRating(6);
cout<< m1.getName()<<endl;
cout<<m1.getMPAA()<<endl;
cout<< m1.getAverage() <<
endl;
cout<<endl;
MovieRating m2("Snow
White","PG"); // create an object of class
MovieRating
m2.addRating(1);
m2.addRating(2);
m2.addRating(1);
m2.addRating(3);
m2.addRating(2);
m2.addRating(1);
m2.addRating(1);
cout<< m2.getName()<<endl;
cout<<m2.getMPAA()<<endl;
cout<< m2.getAverage() << endl;
return 0;
}
C++ A sample project is provided AverageGrade that is very similar to the MovieRatings project, but...
C++, this is an intro class please do not make it complicated. Consider a class Movie that contains information about a movie. The class has the following attributes The movie name The MPAA rating (for example, G, PG, PG-13, R) An array to store the movie ratings .The number of people that have rated this movie as a 1 (Terrible) .The number of people that have rated this movie as a 2 (Bad) .The number of people that have rated...
moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring> using namespace std; typedef struct{ int id; char title[250]; int year; char rating[6]; int totalCopies; int rentedCopies; }movie; int loadData(ifstream &infile, movie movies[]); void printAll(movie movies[], int count); void printRated(movie movies[], int count); void printTitled(movie movies[], int count); void addMovie(movie movies[],int &count); void returnMovie(movie movies[],int count); void rentMovie(movie movies[],int count); void saveToFile(movie movies[], int count, char *filename); void printMovie(movie &m); int find(movie movies[], int...
BACKGROUND Movie Review sites collect reviews and will often provide some sort of average review to sort movies by their quality. In this assignment, you will collect a list of movies and then a list of reviews for each movie. You will then take a simple average (total of reviews divided by number of reviews) for each movie and output a sorted list of movies with their average review. Here you are provided the shell of a program and asked...
COSC 1437 C++2 Project Assignment 3 Description: Computer Science Department is evaluating its professors to see which professor has the highest rating according to student input. You will create a ProfessorRating class consisting of professor Name and three ratings. The three ratings are used to evaluate easiness, helpfulness, and clarity. The value for each rating is in the range of 1 to 5, with 1 being the lowest and 5 being the highest. Your program should contain the following functionalities:...
C++ program Correctly complete the following assignment. Follow all directions. The main purpose is to show super and sub class relationships with an array of super media pointers to sub class objects and dynamic binding. The < operator will be overloaded in the super class so all subclasses can use it. The selection sort method will be in the main .cpp file because it will sort the array created in main. The final .cpp file, the three .h header class...
-can you change the program that I attached to make 3 file songmain.cpp , song.cpp , and song.h -I attached my program and the example out put. -Must use Cstring not string -Use strcpy - use strcpy when you use Cstring: instead of this->name=name .... use strcpy ( this->name, name) - the readdata, printalltasks, printtasksindaterange, complitetasks, addtasks must be in the Taskmain.cpp - I also attached some requirements below as a picture #include <iostream> #include <iomanip> #include <cstring> #include <fstream>...
For the following task, I have written code in C and need help in determining the cause(s) of a segmentation fault which occurs when run. **It prints the message on line 47 "printf("Reading the input file and writing data to output file simultaneously..."); then results in a segmentation fault (core dumped) I am using mobaXterm v11.0 (GNU nano 2.0.9) CSV (comma-separated values) is a popular file format to store tabular kind of data. Each record is in a separate line...
c++ implement a student class Determine the final scores, letter grades, and rankings of all students in a course. All records of the course will be stored in an input file, and a record of each student will include the first name, id, five quiz scores, two exam scores, and one final exam score. For this project, you will develop a program named cpp to determine the final scores, letter grades, and rankings of all students in a course. All...
Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...
Kindly follow the instructions provided carefully. C programming Project 6, Program Design One way to encrypt a message is to use a date’s 6 digits to shift the letters. For example, if a date is picked as December 18, 1946, then the 6 digits are 121846. Assume the dates are in the 20th century. To encrypt a message, you will shift each letter of the message by the number of spaces indicated by the corresponding digit. For example, to encrypt...