|
i want to write a a program that will accept student name and grades and output it.use an array data structure in the implementation this program and implement the following
write method that will traverses the array and allow the user to perform the following processes
a) search for a particular student and his or her marks
b)find the average of all the student in the class
c)find all student with a mark below 50 and output them.
i started off with this codes in Java .But the thing is if i can do it in java i can do it in C and C++
import java.util.Scanner;
//import java.lang.String;
public class Main {
public static int n;
//public static String names;
//private static String[] nameS;
//private static String[] nameS;
/**
* @param args the command line arguments
*/
public static void main(String[] args/*,String[] nameS*/) {
Scanner in=new Scanner(System.in);
int Da=0;
int num []=new int[n];
//int x=0;
System.out.printf("%s\n","Enter the Number of student taking This Couse");
n=in.nextInt();
String name[]=new String [n];
System.out.printf("%s %s \n", "index","value");
for (; Da < name.length; Da++ )/*Da 4 Display array*/ {
System.out.printf( "%5d%8d\n", Da, name[Da] );
}
System.out.println("Enter the names of the student");
String names;
names=in.nextLine();
name[n] = new String(names);
for (; Da < name.length; Da++ ){
System.out.printf( "%5d%8d\n", Da, name[Da] );
}
}
}
i can not input the names into the array( name) i created
pls help me
|
|
|
|
|
Please don't cross post this in multiple forums. Make up your mind whether you want an answer to C/C++ or Java.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
and please use PRE tags for code snippets, I'm not going to read that unformatted unindented stuff!
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Saturday, December 4, 2010 12:01 AM
|
|
|
|
|
Hi,
In this area there are some differences between C++ and Java.
To input nb values of type Val from some stream (console, file or string) to a C++ std::array<Val, nb> you can use:
#include <iostream>
#include <array>
using std::tr1::array;
template <class Val, size_t nb>
array<Val, nb> Input(std::istream& in)
{
array<Val, nb> vals = {0};
while (!in.eof())
{
std::copy_n(std::istream_iterator<Val>(in), vals.size(), vals.begin());
if (in.good())
break;
in.clear();
in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
};
return vals;
}
int main()
{
std::cout << "Input five integers" << std::endl;
array<int, 5> vals = Input<int, 5>(std::cin);
std::copy(vals.begin(), vals.end(), std::ostream_iterator<int>(std::cout, "\n"));
return 0;
}
Good luck
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
modified on Saturday, December 4, 2010 6:08 AM
|
|
|
|
|
/*
Program: Drink Machine
Programmer: Cachel Caldiero
Date: November 16, 2010
Purpose: Simulate a drink machine
*/
#include <iostream>
#include <string>
using namespace std;
// Function Prototypes
void banner();
void menu();
int getMoney();
bool enough(double);
void getDrink();
void dispenseChange(double);
// Main function
int main ()
{
double money = 0.0;
//display banner
banner();
menu();
//While not enough money
while (!enough(money))
{
//Add money based upon option selected
switch (getMoney())
{
case 1: cout << "You have entered $1.00" << endl;
break;
case 2: cout << "You have entered 25 cents" << endl;
break;
case 3: cout << "You have entered 10 cents" << endl;
break;
case 4: cout << "You have entered 5 cents" << endl;
break;
}
//Tell user how much money has been deposited already
cout << endl << "Current amount deposited is " << money << endl;
}
//determine drink selection
getDrink();
//dispense change
if (money > 1.00)
dispenseChange(money);
return 0;
}
// Function Definitions
void banner()
{
cout << "MMM DDD" << endl
<< "OOO EEE" << endl
<< "UUU WWW" << endl
<< "NNN " << endl
<< "TTT " << endl
<< "AAA " << endl
<< "III " << endl
<< "NNN " << endl;
}
void menu()
{
cout << "Pick your drink" << endl
<< "1. Pepsi" << endl
<< "2. Diet Pepsi" << endl
<< "3. Mountain Dew" << endl
<< "4. Diet Mountain Dew" << endl
<< "5. Bottled Water" << endl;
}
int getMoney()
{
int opt;
cout << "Please deposit $0.25." << endl;
cout << "1.Dollar" << endl
<< "2.Quarter" << endl
<< "3.Dime" << endl
<< "4.Nickel" << endl;
cin >> opt;
return opt;
}
bool enough(double m)
{
bool opt(double);
//is there enough money?
if (opt >= enough)
cout << "Enough money inserted" << endl;
else
cout << "Need more money" << endl;
}
void getDrink()
{
string drinkSelection = "";
int option;
//display selection menu
cout << "Pick your drink" << endl;
cout << "1.Pepsi" << endl
<< "2.Diet Pepsi" << endl
<< "3.Mountain Dew" << endl
<< "4.Diet Mountain Dew" << endl
<< "5.Bottled Water" << endl;
//read input selection for drink
cin >> option;
//determine what drink is selected
getDrink();
//output here is your drink.. message
cout << "Here is your drink" << endl;
}
void dispenseChange(double m)
{
int getMoney();
//determine the change in coins.. for example 2 dimes, 1 nickel.
if (getMoney == 1)
cout << "Your change is $0.75 or 3 quarters.";
if (getMoney == 2)
cout << "Your change is $0.50 or 2 quarters.";
else if (getMoney == 3)
cout << "Your change is $0.25 or 1 quarter.";
}
|
|
|
|
|
What exactly is happening that's not right? Also, please format your code with <pre> tags to make it reasonably readable.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
What are
tags?
My main problem is part of code that follows:
void dispenseChange(double m)
{
int getMoney();
if (getMoney = 1)
cout << "Your change is $0.75 or 3 quarters.";
if (getMoney = 2)
cout << "Your change is $0.50 or 2 quarters.";
else if (getMoney == 3)
cout << "Your change is $0.25 or 1 quarter.";
}
|
|
|
|
|
It's hard to read in this format, but I think there is more wrong than just this function.
Your dispenseChange functions accepts a double m, which contains the amount of money inserted. The function is called when the amount is more than 1.00. The price of a drink is 25ct, so why not call this function when the amount is more than 0.25?
Then when you're in the function dispenseChange, you call GetMoney. So after you have inserted too much money already and change is calculated, you ask for another coin to be inserted and then base the change on that coin.
The change should be based on the amount paid and the price: so m-0.25 is the amount that is paid too much. Then you'd have to split this to coins.
Other observations:
In your main loop, you check until you have inserted enough money. You do this by calling getMoney(), but you don't update your money variable. So the enough(money) check won't be right either.
Your getDrink function calls itself.
Maybe try something like this:
using namespace std;
void banner();
void menu();
int getMoney();
bool enough(double);
void getDrink();
void dispenseChange(double);
int main ()
{
double money = 0.0;
banner();
menu();
while (!enough(money))
{
switch (getMoney())
{
case 1: cout << "You have entered $1.00" << endl;
money += 1.00;
break;
case 2: cout << "You have entered 25 cents" << endl;
money += 0.25;
break;
case 3: cout << "You have entered 10 cents" << endl;
money += 0.10;
break;
case 4: cout << "You have entered 5 cents" << endl;
money += 0.05;
break;
}
cout << endl << "Current amount deposited is " << money << endl;
}
getDrink();
if (money > 0.25)
dispenseChange(money);
return 0;
}
void banner()
{
cout << "MMM DDD" << endl
<< "OOO EEE" << endl
<< "UUU WWW" << endl
<< "NNN " << endl
<< "TTT " << endl
<< "AAA " << endl
<< "III " << endl
<< "NNN " << endl;
}
void menu()
{
cout << "Pick your drink" << endl
<< "1. Pepsi" << endl
<< "2. Diet Pepsi" << endl
<< "3. Mountain Dew" << endl
<< "4. Diet Mountain Dew" << endl
<< "5. Bottled Water" << endl;
}
int getMoney()
{
int opt;
cout << "Please deposit $0.25." << endl;
cout << "1.Dollar" << endl
<< "2.Quarter" << endl
<< "3.Dime" << endl
<< "4.Nickel" << endl;
cin >> opt;
return opt;
}
bool enough(double m)
{
if (m >= 0.25){
cout << "Enough money inserted" << endl;
return 1;
}
else{
cout << "Need more money" << endl;
return 0;
}
}
void getDrink()
{
int option;
cout << "Pick your drink" << endl;
cout << "1.Pepsi" << endl
<< "2.Diet Pepsi" << endl
<< "3.Mountain Dew" << endl
<< "4.Diet Mountain Dew" << endl
<< "5.Bottled Water" << endl;
cin >> option;
cout << "Here is your drink" << endl;
}
void dispenseChange(double m)
{
if (m == 1.20)
cout << "Your change is $0.95 or 3 quarters and 2 dimes.";
else if (m == 1.15)
cout << "Your change is $0.90 or 3 quarters and a dime and a nickel.";
else if (m == 1.10)
cout << "Your change is $0.85 or 3 quarters and a dime.";
else if (m == 1.05)
cout << "Your change is $0.80 or 3 quarters and a nickel.";
else if (m == 1.00)
cout << "Your change is $0.75 or 3 quarters.";
else if (m == 0.45)
cout << "Your change is $0.20 or 2 dimes.";
else if (m == 0.40)
cout << "Your change is $0.15 or a dime and a nickel.";
else if (m == 0.35)
cout << "Your change is $0.10 or a dime.";
else if (m == 0.30)
cout << "Your change is $0.05 or a nickel.";
}
modified on Saturday, December 4, 2010 6:40 AM
modified 13-Sep-18 21:01pm.
|
|
|
|
|
you get mixed up betwen "=" and "==" ...
review your courses texts and documentations.
Watched code never compiles.
|
|
|
|
|
To open a drive/disk and read data from it there are many ways like CreateFile/ReadFile, _open/_read etc
do we have any code written in assembly language which open disk and read data from it from any location. And we can use that code in vc++. If yes please provide any link
|
|
|
|
|
You are not going to improve performance by writing assembly code to read/write files, because there's a bigger bottleneck at the disk i/o level (the data transfer from/to the disk happens at a MUCH slower pace than the speed at which the program itself executes).
It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.
|
|
|
|
|
ok. What about data reading. Using VC++ function sometime API hangs which read data. Will assembly code success in this. And to read data asynchronously is not reliable because it depends on disk to disk.
|
|
|
|
|
There's no reason why a C++ API should "hang" as such while reading a file. It may be due to disk latency, which cannot be cured if you change the programming language that was used to read data.
It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.
|
|
|
|
|
|
Don't bother trying to use assembly language for this type of thing. Under modern operating systems you're always going to have to use some OS service to access the disk whatever language you're programming in. Even if you write a device driver to do the access there's no point in using an assembly language as writing it in C will be easier and probably as fast and efficient. And even if you write a device driver you're still relying on the OS to call the driver for you so you're still at the mercy of the OS.
Cheers,
Ash
|
|
|
|
|
Thanks
I experienced that asynchronous disk io is not reliable. Am i correct?
If not then please give some idea about the way to use it
|
|
|
|
|
What do you mean with "reliable" ?!?
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
it is known to occasionally return bits that are neither one nor zero.
|
|
|
|
|
Hi there,
I need to use a memory checker "like" Intel Memory Inspector.
Of course I do'nt have 800 USD to buy such tool so I wonder if there are alternatives ?
Push Framework - now released !
http://www.pushframework.com
|
|
|
|
|
|
Hi all,
I'm stuck with this.
I want to find the memory usage of my application. So I can work on with GetProcessMemoryInfo, and I need to find the relevant process ID in-advance to workaround. It's possible too.
But if my application runs multiple instances I cannot do that. Because all the process has the same name I cannot pick what the ID is.
Any suggestions really appreciate.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
You could use the GetCurrentProcess[^] function and pass it to GetProcessMemoryInfo[^].
HANDLE hProc = GetCurrentProcess();
PROCESS_MEMORY_COUNTERS_EX info;
info.cb = sizeof(PROCESS_MEMORY_COUNTERS_EX);
GetProcessMemoryInfo(hProc, (PROCESS_MEMORY_COUNTERS*)&info, info.cb);
modified 13-Sep-18 21:01pm.
|
|
|
|
|
Thanks for the replay.
Actually I comes with an error, undeclared identifier on the following.
Thaddeus Jones wrote: PROCESS_MEMORY_COUNTERS_EX info;
I've included psapi.h header too.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
You can try PROCESS_MEMORY_COUNTERS instead, maybe PROCESS_MEMORY_COUNTERS_EX was introduced later than your compiler (it requires WinXP SP2 or above).
modified 13-Sep-18 21:01pm.
|
|
|
|
|
That's why I'm wired. I'm working on WinXP SP3.
Anyway I work on with PROCESS_MEMORY_COUNTERS, and works fine. But when I'm invoking GetProcessMemoryInfo(...) it gives an unusual error at build.
error LNK2019: unresolved external symbol _GetProcessMemoryInfo@12 referenced in function "public: void __thiscall CMyExceptionLogger::LogMemoryUsage(enum LOGLEVEL)" (?LogMemoryUsage@CMyExceptionLogger@@QAEXW4LOGLEVEL@@@Z)
You have any idea about this?
I appreciate your help all the time...
CodingLover
|
|
|
|