SOLVED CS201 Assignment 3 Solution and Discussion
-
Assignment No. 3
Semester: Spring 2020
CS201 – Introduction to Programming Total Marks: 20Due Date: 23/07/2020
Instructions
Please read the following instructions carefully before submitting assignment:
It should be clear that your assignment will not get any credit if:o Assignment is submitted after due date.
o Submitted assignment does not open or file is corrupt.
o Assignment is copied (From internet/students).Software allowed to develop Assignment
- Dev C++
Objectives:
To enable students to understand and practice the concepts of:
• Classes
• Objects
• Loops
• File handlingAssignment Submission Instructions
You have to submit only .cpp file on the assignments interface of CS201 at VULMS. Assignment submitted in any other format will not be accepted and will be graded zero marks.
Please note again, assignment submitted other than .cpp format will get zero marks.Assignment
Assignment Statement:
Assume you are working as a sports data analyst for a university named “ABC University”. Your job is to collect data of different players and judge their performance. Based on the data collected from players, their performance for a given season will be analyzed and comparison among players of the team will be made for selection. For this purpose, you are required to write a program in C++ that will create a class named “Sports”. The class will create a file named “Sample.txt” in the current directory. You will use file handling mechanism for entering player’s information. Following tasks are required:• You are required to create a class named “Sports”.
• Declare three data members of Sports class named playername, game_name and total_wins with appropriate data types.
• The class will consist of 6 functions named input_file(), read_file(), notstartingwithA(), lower(), upper() and digit() respectively along with a default constructor. The description of each function is given with the screenshots in the “Sample output”.
• In the main() function an object of the class “Sports” will be created and it will be used along with switch statement to call the functions mentioned above. i.e. input_file(), read_file(), notstartingwithA(), lower(), upper() and digit().
• Initially a menu will be displayed consisting of different choices as shown below:• User will enter a choice from the choices given in the menu. Output of each selected number is shown in the output samples below for detailed description.
Sample Output:-
1.
• In the first step the following menu will appear at the output screen.
• User will first populate file “Sample.txt” before reading the file as given below.
• The function named input_file() will take input from user and store it in the file named “Sample.txt”. If a user wants to enter second record, the first record in the file will not be deleted; rather new data will be added at the end of the file.
• The function read_file() will read all data stored in the file “Sample.txt” from start to end.
• The function notstartingwithA() will check the file and find all lines of the file “Sample.txt” that are not started with character “A” including blank lines. E.g. the above data will consists of 3 lines in the file. notstartingwithA() function will count all those line and display the count on output screen as given below.
• The function lower() will find all those lines that are started with lower characters in the file “Sample.txt” and display the count on outputs screen as given below.
• The function upper() will find all those lines that are started with an upper case character in the file “Sample.txt” and display the count on outputs screen as given below.
• The function digit() will find all those lines that are started with a digits in the file “Sample.txt” and display the count on output screen.
• Program will also check for invalid choices as given below.
Best of luck
Lectures Covered: (Lecture # 17- 27) and Solution Deadline: (23/07/2020).
-
//************** CS201 Assignment No. 3 ****************"; //************** Solution by Cyberian.pk ****************"; #include<iostream> #include<fstream> using namespace std; class Sports { private : string playername; string game_name; int total_wins; public : Sports() { playername=""; game_name=""; total_wins=0; } void input_file() { cout<<"\nWriting in the file"; cout<<"\nEnter the name of the player : "; cin>>playername; cout<<"Enter the Sports name of the player : "; cin>>game_name; cout<<"Enter the number of wins for the current season : "; cin>>total_wins; ofstream outFile; char FileName[] = "Sample.txt"; outFile.open(FileName, std::ios_base::app); if (!outFile) { cout << "Can't open input file named Sample.txt"<< endl; exit(1); } outFile<<playername<<"\n"; outFile<<game_name<<"\n"; outFile<<total_wins<<"\n"; outFile.close(); cout<<"\nData have been entered in the file"; } void read_file() { char FileName[] = "Sample.txt"; ifstream inFile; inFile.open(FileName, ios::in); if (inFile) { string dt=""; while(getline(inFile, dt)) { cout << dt << "\n"; } } else { cout << "File is empty populate it first"<< endl; } } void notstartingwithA() { char FileName[] = "Sample.txt"; ifstream inFile; inFile.open(FileName, ios::in); int count=0; char s; if (inFile) { string dt; while(getline(inFile, dt)) { s=dt.at(0); if(s!='A') { count++; } } inFile.close(); cout<<"\nThe number of lines not started with 'A' including empty lines : "<<count<<endl; } else { cout << "File is empty populate it first"<< endl; } } void lower() { char FileName[] = "Sample.txt"; ifstream inFile; inFile.open(FileName, ios::in); int count=0; char s; if (inFile) { string dt; while(getline(inFile, dt)) { s=dt.at(0); if(islower(s)) { count++; } } inFile.close(); cout<<"\nThe number of lines started with lower character are : "<<count<<endl; } else { cout << "File is empty populate it first"<< endl; } } void upper() { char FileName[] = "Sample.txt"; ifstream inFile; inFile.open(FileName, ios::in); int count=0; char s; if (inFile) { string dt; while(getline(inFile, dt)) { s=dt.at(0); if(isupper(s)) { count++; } } inFile.close(); cout<<"\nThe number of lines started with upper character are: "<<count<<endl; } else { cout << "File is empty populate it first"<< endl; } } void digit() { char FileName[] = "Sample.txt"; ifstream inFile; inFile.open(FileName, ios::in); int count=0; char s; if (inFile) { string dt; while(getline(inFile, dt)) { s=dt.at(0); if(isdigit(s)) { count++; } } inFile.close(); cout<<"\nThe number of lines started with digit are : "<<count<<endl; } else { cout << "File is empty populate it first"<< endl; } } }; main() { int choice; Sports sport; char iterate; do { cout<<"\n\t************** CS201 Assignment No. 3 ****************"; cout<<"\n\t************** Solution by Cyberian****************"; cout<<"\n\n************** WELCOME TO THE UNIVERSITY SPORTS SURVEY SYSTEM ****************"; cout<<"\n\n************** Press 1 for entering record of player ************************"; cout<<"\n************** Press 2 for reading data from the file ***********************"; cout<<"\n************** Press 3 for checking line not started with A *****************"; cout<<"\n************** Press 4 for checking line started with lower case characters**"; cout<<"\n************** Press 5 for checking line started with upper case characters**"; cout<<"\n************** Press 6 for checking line started with digits ****************\n\n"; cin>>choice; switch(choice) { case 1 : sport.input_file(); break; case 2 : sport.read_file(); break; case 3 : sport.notstartingwithA(); break; case 4 : sport.lower(); break; case 5 : sport.upper(); break; case 6 : sport.digit(); break; default : cout<<"\nInvalid choice entered!\n"; break; } cout<<"\nDo you want to continue (y for yes) : "; cin>>iterate; } while(iterate=='y'|| iterate=='Y'); }
-
This post is deleted! -
CS201 ASSIGNMENT 3 SOLUTION SPRING 2021
#include <iostream> using namespace std; #define PI 3.14159265 class Circle { private: double radius; public: void setRadius(); void computeAreaCirc(); Circle(); ~Circle(); }; Circle::Circle() { radius = 0.0; } void Circle::setRadius() { radius = 5.6; } void Circle::computeAreaCirc() { cout << "Area of circle is: " << PI * (radius * radius) << endl; cout << "Circumference of circle is: " << 2 * PI * radius << endl; } Circle::~Circle() { } class Rectangle { private: double length; double width; public: void setLength(); void setWidth(); void computeArea(); Rectangle(); ~Rectangle(); }; Rectangle::Rectangle() { length = 0.0; width = 0.0; } void Rectangle::setLength() { length = 5.0; } void Rectangle::setWidth() { width = 4.0; } void Rectangle::computeArea() { cout << "Area of Rectangle: " << length * width << endl; } Rectangle::~Rectangle() { } main() { cout<<"********************SCIENTIFIC CALCULATOR********************"<<endl; cout<<""<<endl; int run = 1; string option, choice; while(run) { cout << "\nOPTION 1 for computing Area and Circumference of the circle" << endl; cout << "OPTION 2 for computing Area of the Rectangle" << endl; cout << "Select your desired option(1-2): "; cin >> option; if(option == "1") { Circle nCircle; nCircle.setRadius(); nCircle.computeAreaCirc(); cout << "Do you want to perform anyother calculation(Y/N):"; cin >> choice; if(choice == "Y" || choice == "y") { continue; } else { break; } } else if(option == "2") { Rectangle nRectangle; nRectangle.setLength(); nRectangle.setWidth(); nRectangle.computeArea(); cout << "Do you want to perform anyother calculation(Y/N):"; cin >> choice; if(choice == "Y" || choice == "y") { continue; } else { break; } } else { cout << "Invalid Option!, Option should be from (1-2)" << endl; } } }
-
//************** CS201 Assignment No. 3 ****************"; //************** Solution by Cyberian.pk ****************"; #include<iostream> #include<fstream> using namespace std; class Sports { private : string playername; string game_name; int total_wins; public : Sports() { playername=""; game_name=""; total_wins=0; } void input_file() { cout<<"\nWriting in the file"; cout<<"\nEnter the name of the player : "; cin>>playername; cout<<"Enter the Sports name of the player : "; cin>>game_name; cout<<"Enter the number of wins for the current season : "; cin>>total_wins; ofstream outFile; char FileName[] = "Sample.txt"; outFile.open(FileName, std::ios_base::app); if (!outFile) { cout << "Can't open input file named Sample.txt"<< endl; exit(1); } outFile<<playername<<"\n"; outFile<<game_name<<"\n"; outFile<<total_wins<<"\n"; outFile.close(); cout<<"\nData have been entered in the file"; } void read_file() { char FileName[] = "Sample.txt"; ifstream inFile; inFile.open(FileName, ios::in); if (inFile) { string dt=""; while(getline(inFile, dt)) { cout << dt << "\n"; } } else { cout << "File is empty populate it first"<< endl; } } void notstartingwithA() { char FileName[] = "Sample.txt"; ifstream inFile; inFile.open(FileName, ios::in); int count=0; char s; if (inFile) { string dt; while(getline(inFile, dt)) { s=dt.at(0); if(s!='A') { count++; } } inFile.close(); cout<<"\nThe number of lines not started with 'A' including empty lines : "<<count<<endl; } else { cout << "File is empty populate it first"<< endl; } } void lower() { char FileName[] = "Sample.txt"; ifstream inFile; inFile.open(FileName, ios::in); int count=0; char s; if (inFile) { string dt; while(getline(inFile, dt)) { s=dt.at(0); if(islower(s)) { count++; } } inFile.close(); cout<<"\nThe number of lines started with lower character are : "<<count<<endl; } else { cout << "File is empty populate it first"<< endl; } } void upper() { char FileName[] = "Sample.txt"; ifstream inFile; inFile.open(FileName, ios::in); int count=0; char s; if (inFile) { string dt; while(getline(inFile, dt)) { s=dt.at(0); if(isupper(s)) { count++; } } inFile.close(); cout<<"\nThe number of lines started with upper character are: "<<count<<endl; } else { cout << "File is empty populate it first"<< endl; } } void digit() { char FileName[] = "Sample.txt"; ifstream inFile; inFile.open(FileName, ios::in); int count=0; char s; if (inFile) { string dt; while(getline(inFile, dt)) { s=dt.at(0); if(isdigit(s)) { count++; } } inFile.close(); cout<<"\nThe number of lines started with digit are : "<<count<<endl; } else { cout << "File is empty populate it first"<< endl; } } }; main() { int choice; Sports sport; char iterate; do { cout<<"\n\t************** CS201 Assignment No. 3 ****************"; cout<<"\n\t************** Solution by Cyberian****************"; cout<<"\n\n************** WELCOME TO THE UNIVERSITY SPORTS SURVEY SYSTEM ****************"; cout<<"\n\n************** Press 1 for entering record of player ************************"; cout<<"\n************** Press 2 for reading data from the file ***********************"; cout<<"\n************** Press 3 for checking line not started with A *****************"; cout<<"\n************** Press 4 for checking line started with lower case characters**"; cout<<"\n************** Press 5 for checking line started with upper case characters**"; cout<<"\n************** Press 6 for checking line started with digits ****************\n\n"; cin>>choice; switch(choice) { case 1 : sport.input_file(); break; case 2 : sport.read_file(); break; case 3 : sport.notstartingwithA(); break; case 4 : sport.lower(); break; case 5 : sport.upper(); break; case 6 : sport.digit(); break; default : cout<<"\nInvalid choice entered!\n"; break; } cout<<"\nDo you want to continue (y for yes) : "; cin>>iterate; } while(iterate=='y'|| iterate=='Y'); }
-
Please share idea solution.


100% Off on Your FEE Join US! Ask Me How?


