Question

Star Database Program. This is a more sophisticated assignment, it will take longer to do. Write...

Star Database Program.

This is a more sophisticated assignment, it will take longer to do.

Write a program which uses file IO, loops, and function calls.

The following files are provided in pub:
Assignment.cpp
stars.dat
solution_stars.dat
solution.o

when you log in the first time, make a directory for this project
mkdir prog3

then copy down the files.  (WARNING! This will overwrite any file in
the directory named Assignment.cpp, so don't copy down Assignment.cpp
if you have already done work):

cp ~cs1253_pet/pub/prog3/Assignment.cpp Assignment.cpp
and so on, replacing Assignment.cpp with stars.dat, or solution_stars.dat,
or solution.o as needed.

Assignment.cpp is a starter that contains an int main function
as well as some function prototypes.
Your job is to write out the prototyped functions completely.
Do not change the int main function!

When you are done the command
~cs1253_pet/bin/p_copy 3
will submit the contents of the prog3 directory for grading.

by default the solution.o file is not executable, so you may need
to make it executable.  After copying it, the command:
chmod a+x solution.o
should make the file executable.

Your program should use stars.dat as a data file for input and output.
The solution program uses solution_stars.dat as a data file.
stars.dat is formatted to contain information as follows, separated by commas:

star name,star's constellation,star's apparent magnitude,star's mass,
star's diameter,next star's name, next star's constellation....

I will always give you a file that contains information in these 5 value 
pieces, so a given star will always be followed by a value for 
constellation, apparent magnitude, mass and then diameter.  Despite the fact
that some of these values are numeric, it would probably be easiest to 
use strings as variables as you will not need to do any math.

You do not have to test or worry about what happens if you start with a badly
formed file.  You DO have to ensure that you don't write to the file in 
such a way that it becomes malformed.

This program will, on open, display a list of names gathered from a CSV file.
The user will then select a name from that list, or "Add" or "Quit".
The names may have spaces in them.
If Quit is selected the program will end.
If a name is selected, then details about that star will be printed, and
then the menu will be reprinted.
If Add is selected the program will prompt the user to enter information
about a new star.
Note!  You must prohibit the user from entering the star's name as
Add
Quit
or any name that is already in the file as a star name.
Also!  The star information must be added to the file, so that it will persist 
and be present the next time the program is run!.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;

const int STAR_FACTS = 5;
const int PREF_WIDTH = 23;

int input[5];

void PrintMenu(string fileName);

bool IsStarNameValid(string fileName, string starName);

void AddStarToFileFromUserInput(string fileName);

void PrintStarFacts(string fileName, string starName);

//Do not change anything below this line

//you will lose points. That includes these comments.
//EXACTMATCH

int main(){
bool runProgram = true;
string fileName = "stars.dat";
string userSelection;
while(runProgram){
PrintMenu(fileName);
cout << "Enter Star Name, or Add, or Quit:\n";
getline(cin, userSelection);
if(userSelection == "Add"){
AddStarToFileFromUserInput(fileName);
}
else if(userSelection == "Quit"){
runProgram = false;
}
else{
if(IsStarNameValid(fileName, userSelection)){
   PrintStarFacts(fileName, userSelection);
}
else{
   cout << "Invalid Star Name\n";
}
}
}
}
//EXACTMATCH

stars.dat CSV file :

Sirius,Canis Major,8.44,2.02,1.711,UY Scuti,Scutum,9.0,8,1708,Arcturus,Bootes,-0.05,1.08,25.4,2MASS J0523-1402,Lepus,21.05,0.08,0.086,AH Scorpii,Scorpius,1.5,1.5,1411,DiCaprio,No Oscar,1.2,45.2,1,

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Star Database Program. This is a more sophisticated assignment, it will take longer to do. Write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • IP requirements: Load an exam Take an exam Show exam results Quit Choice 1: No functionality...

    IP requirements: Load an exam Take an exam Show exam results Quit Choice 1: No functionality change. Load the exam based upon the user's prompt for an exam file. Choice 2: The program should display a single question at a time and prompt the user for an answer. Based upon the answer, it should track the score based upon a successful answer. Once a user answers the question, it should also display the correct answer with an appropriate message (e.g.,...

  • Write a simple telephone directory program in C++ that looks up phone numbers in a file...

    Write a simple telephone directory program in C++ that looks up phone numbers in a file containing a list of names and phone numbers. The user should be prompted to enter a first name and last name, and the program then outputs the corresponding number, or indicates that the name isn't in the directory. After each lookup, the program should ask the user whether they want to look up another number, and then either repeat the process or exit the...

  • Coding in c++

    I keep getting errors and i am so confused can someone please help and show the input and output ive tried so many times cant seem to get it. main.cpp #include <iostream> #include <vector> #include <string> #include "functions.h" int main() {    char option;    vector<movie> movies;     while (true)     {         printMenu();         cin >> option;         cin.ignore();         switch (option)         {            case 'A':            {                string nm;                int year;                string genre;                cout << "Movie Name: ";                getline(cin, nm);                cout << "Year: ";                cin >> year;                cout << "Genre: ";                cin >> genre;                               //call you addMovie() here                addMovie(nm, year, genre, &movies);                cout << "Added " << nm << " to the catalog" << endl;                break;            }            case 'R':            {                   string mn;                cout << "Movie Name:";                getline(cin, mn);                bool found;                //call you removeMovie() here                found = removeMovie(mn, &movies);                if (found == false)                    cout << "Cannot find " << mn << endl;                else                    cout << "Removed " << mn << " from catalog" << endl;                break;            }            case 'O':            {                string mn;                cout << "Movie Name: ";                getline(cin, mn);                cout << endl;                //call you movieInfo function here                movieInfo(mn, movies);                break;            }            case 'C':            {                cout << "There are " << movies.size() << " movies in the catalog" << endl;                 // Call the printCatalog function here                 printCatalog(movies);                break;            }            case 'F':            {                string inputFile;                bool isOpen;                cin >> inputFile;                cout << "Reading catalog info from " << inputFile << endl;                //call you readFromFile() in here                isOpen = readFile(inputFile, &movies);                if (isOpen == false)                    cout << "File not found" << endl;...

  • This is my assignment prompt This is an example of the input and output This is...

    This is my assignment prompt This is an example of the input and output This is what I have so far What is the 3rd ToDo in the main.cpp for open the files and read the encrypted message? Does the rest of the code look accurate? Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require that you read in an encrypted message from a file, decode the message, and then output the message to a...

  • Stuck on this computer science assignment Write a program that demonstrates binary searching through an array...

    Stuck on this computer science assignment Write a program that demonstrates binary searching through an array of strings and finding specific values in an corresponding parallel double array. In all cases your output should exactly match the provided solution.o. Provided files: Assignment.cpp - starter assignment with function prototypes companies.txt - file for program to read. earnings.txt - file for program to read. Input1.txt Input2.txt - Test these inputs out manually, or use stream redirection Input3.txt - These inputs are based...

  • Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment...

    Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and total points. The final score must be rounded up to the nearest whole value using the ceil function in the <cmath> header file. You must also display the floating-point result up to 5 decimal places. The input to the program must come from a file containing a single line with the score and total separated by...

  • For this assignment, you are to write a program that does the following: (C++) • read exam scores...

    For this assignment, you are to write a program that does the following: (C++) • read exam scores from a file name data.txt into an array, and • after reading all the scores, output the following to the monitor: the average score and the total number of scores. In addition, the program must use the following functions: //precondition: fileName is name of the file to open, inFile is the input file 2 of 2 //postcondition: inFile is opened. If inFile...

  • c++, I am having trouble getting my program to compile, any help would be appreciated. #include...

    c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...

  • Hello! I'm posting this program that is partially completed if someone can help me out, I...

    Hello! I'm posting this program that is partially completed if someone can help me out, I will give you a good rating! Thanks, // You are given a partially completed program that creates a list of employees, like employees' record. // Each record has this information: employee's name, supervisors's name, department of the employee, room number. // The struct 'employeeRecord' holds information of one employee. Department is enum type. // An array of structs called 'list' is made to hold...

  • Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director,...

    Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director, Genre, Year Released, Running Time) into a vector of structures and perform the following operations: Search for a specific title Search for movies by a specific director Search for movies by a specific genre Search for movies released in a certain time period Search for movies within a range for running time Display the movies on the screen in a nice, easy to read...

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
ADVERTISEMENT